Update arithmetic.js

This commit is contained in:
Tyler Cooper 2025-08-19 11:53:48 -05:00 committed by GitHub
parent 55e3b09415
commit b619b89bd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,42 +5,36 @@ export default {
name: "Arithmetic",
colour: 120,
inputsInline: true,
description: "Perform the specified arithmetic operation on two specified operands.",
description: "Perform mathematical calculations using sensor data, feed values, or any numbers in your Actions. Perfect for creating custom formulas like calculating averages, converting units (Celsius to Fahrenheit), computing percentages, or building complex calculations from multiple data sources.",
connections: {
mode: "value",
output: "expression",
},
template: `%A %OP %B`,
inputs: {
A: {
description: "The left side of the operation. Will be coerced to a number",
description: "The first number in your calculation (left side). Examples: temperature reading (72.5), feed value, sensor data, or results from other calculations. Non-numeric values will be automatically converted to numbers where possible.",
check: "expression",
shadow: 'io_math_number'
},
B: {
description: "The right side of the operation. Will be coerced to a number",
description: "The second number in your calculation (right side). Examples: conversion factors (1.8 for temp conversion), target values (75 for comparison), other sensor readings, or mathematical constants. Also automatically converted to numbers.",
check: "expression",
shadow: 'io_math_number'
},
},
fields: {
OP: {
description: "The mathematical operation to perform.",
description: "Choose the mathematical operation to perform:",
options: [
['+', 'ADD', "add two numbers"],
['-', 'MINUS', "subtract number B from number A"],
['x', 'MULTIPLY', "multiply two numbers"],
['/', 'DIVIDE', "divide number A by number B"],
['^', 'POWER', "raise number A to the power of number B"],
['+', 'ADD', "Addition: Combine two numbers (e.g., 25 + 5 = 30). For totaling values, adding offsets, or combining multiple sensor readings into sums."],
['-', 'MINUS', "Subtraction: Remove B from A (e.g., 30 - 5 = 25). For calculating differences, finding deltas between readings, or subtracting baseline values."],
['x', 'MULTIPLY', "Multiplication: A times B (e.g., 6 x 4 = 24). For unit conversions, scaling values, calculating areas/volumes, or applying multiplication factors."],
['/', 'DIVIDE', "Division: A divided by B (e.g., 20 ÷ 4 = 5). For calculating averages, ratios, percentages, or converting between different unit scales."],
['^', 'POWER', "Exponentiation: A raised to the power of B (e.g., 2^3 = 8). For advanced calculations, exponential growth models, or complex mathematical formulas."],
]
}
},
generators: {
json: (block, generator) => {
const
@ -54,7 +48,6 @@ export default {
operator = block.getFieldValue('OP'),
leftExp = generator.valueToCode(block, 'A', 0) || 'null',
rightExp = generator.valueToCode(block, 'B', 0) || 'null',
blockPayload = JSON.stringify({
arithmetic: {
left: JSON.parse(leftExp),
@ -64,11 +57,9 @@ export default {
right: JSON.parse(rightExp)
}
})
return [ blockPayload, 0 ]
}
},
regenerators: {
json: (blockObject, helpers) => {
const
@ -87,7 +78,6 @@ export default {
A: helpers.expressionToBlock(payload.left, { shadow: 'io_math_number' }),
B: helpers.expressionToBlock(payload.right, { shadow: 'io_math_number' }),
}
return { type: 'io_math_arithmetic', fields, inputs }
}
}