Hi! I’ve been using the “Calculator” function successfully for a while. Recently I saw weird results. Either I misunderstand something (totally likely!) or there’s a bug. I’ve run a simplified test which I’ll describe below.
I want to export to influx :
- Net = CoolRmExFanB + CoolRmExFanR + CoolRmExFanW * 3
but what I get wrong … it appears to be
- (CoolRmExFanB + CoolRmExFanR + CoolRmExFanW )* 3
The config.txt is below. I expect Test1 == Test2 == Test3:
This simple error is magnified for the other calculations. They give values like 700MW!
I can work around by forcing precedence or thrice adding, instead of x3.
The calculator works like a “dumb” calculator in that it does not have hierarchy of operators, it simply works from left to right. Parenthesis can be used to override as in your test3 above.
Unfortunately, the original implementation did not anticipate the extensive use the calculator would come to have, but now changing it to do operator hierarchy could change the results in many existing scripts. It’s a little bulky but using parenthesis isn’t that difficult once you are aware of the limitations. Hindsight is 20/20.
Okay, that explain it. Not a problem,. Who doesn’t love a parenthesis?
(It would be good to document this (maybe I missed it), as it intuitively looks likes a “real” calculator.)!
Edit: I’ve changed my formulae and wanted to check I’m using the min/max function correctly. I realise I’m pushing the calculator’s limit a bit!
- Consumption : sum of all those circuits with some x3 (this should now be fine)
- Export : When (ClubShedR+W+B) < 1, I want to return -(ClubShedR+W+B).
- As for consumption, but return Consumption iff Consumption > 0
I plan to add a cautionary note right on the calculator face.
After testing, and referring to the Consumption, Export and Import in the image about above
…the “min” and “max” function appear to just look at the immediate element before (not the whole () expression). This is consistent with a ‘dumb’ calculator. Hence the Export and Import don’t work as intended.
Is it perhaps best to avoid the min/max function on multiple elements? Or should the parenthesis work with the max/min function?
Without seeing the data, and results, I can’t say one way or the other, but the max function is simply a binary operator. The advantage of left to right evaluation is that it does not require compiling to polish or reverse polish to evaluate. So the entire expression within parenthesis is evaluated before the min or max function is even encountered. If it didn’t work properly for those, it wouldn’t work properly for any other binary function.
I created these output scripts:
and get results
These appear to work as expected.
Are you by any chance running these import and export scripts in Graph+ context over a period greater than a day?