Closed cweitkamp closed 2 years ago
Regarding the units: would it be possible to add a new method performUnitCalculation
with an implementation like
@Override
Unit performUnitCalculation(Unit unit1, Unit unit2) {
return unit1.multiply(unit2);
}
The AbstractMathTransformationService
could then check if at least one of the values has a unit (creating a Unit
from the string after the number part). If that is the case, the method could be called and the new unit added to the value. If only one value has a unit, it the other unit should be Unit.ONE
, that way even dividing 5
by 2 s
would result in 2.5 1/s
.
WDYT?
Good idea. But if we think about doing so we might want to cast the source and value strings for the transformation to a QuantityType
directly and use the existing arithmetic methods.
Do you think these "inside string" transformations are mandatory? Parsing the source string with text and invalid units won't work with both proposals.
No, I don't think that's mandatory. A clean solution that works with units is IMO better.
QuantityType
to allow proper unit calculationsSpecial use case: AVM FRITZ! outlets expose power and voltage. I have a rule to calculate the current based on the formula "E = U * I <=> I = E / U" read from two Items. This enhancement allows me to define a profile to do the math.
Currently a remaining issue is the target unit.
Signed-off-by: Christoph Weitkamp github@christophweitkamp.de