Sampled calculation examples
Add 2 variables
return _A.Value + _B.Value
Select variable based on condition
if _A.Value > 100.0 {
return _B.Value
} else if _A.Value < 100.0 {
return _C.Value
}
return _A.Value
Raw calculation examples
Map value to string
if _A.Value == 1.0 {
return "STEP_A"
} else if _A.Value == 2.0 {
return "STEP_B"
}
return "INVALID"
result := text.re_find("\\\\d+\\\\.?\\\\d*",_A.Value) // eg _A = "SOME_2344324.34_VALUE"
if result != undefined && len(result) > 0 {
found := result[0][0].text
return float(found)
}
Return elapsed time between previous and current value
previous := local.get("previous")
local.set("previous", _A)
if previous {
return times.sub(_A.Timestamp, previous.Timestamp)
}
return 0
Incremental counter
threshold := 100
previous := float(local.get("previous"),0.0)
result := previous + _A.Value
if result >= threshold {
local.set("previous", 0.0)
return 0.0
}
local.set("previous",result)
return result
Generate random float between 0 and 1
return rand.float()
Examples using calculation context
Incremental counter
if Context.PreviousResult != undefined {
return Context.PreviousResult.Value + 1
}
return 0
Example using if97 steam functions
Calculate enthalpy
// Get input values for temperature and pressure from input references
temperatureCelsius := _A.Value // Assuming _A is an alias for temperature input in Celsius
pressureBar := _B.Value // Assuming _B is an alias for pressure input in Bar
// Convert temperature from Celsius to Kelvin
temperature := units.convert(temperatureCelsius, "C", "K")
// Convert pressure from Bar to Pascal
pressure := units.convert(pressureBar, "bar", "Pa")
// Calculate the specific enthalpy of steam using the if97.specificEnthalpy function
enthalpy := if97.specificEnthalpy(temperature, pressure)
// Return the calculated specific enthalpy
return enthalpy