point.lastValue.value subtraction NaN
Apparently I cannot subtract two points without getting NaN instead of 1.0:
var lastGallon = gallons.lastValue(1); var dt = gallons.time - lastGallon.time; // time between last gallons (ms) return dt; // Success. result=176000.0 var dg = gallons.value - lastGallon.value; // number of gallons return dg; // Success. result=NaN return gallons.value; // Success. result=422536.0 return lastGallon.value; // Success. result=422535.0 return 422530.0 - lastGallon.value; // Success. result=NaN return gallons.value - 422535.0; // Success. result=1.0 return gallons.lastValue(1).value; // Success. result=422535.0
This seems to have broken during an upgrade or a restart back in November. What is wrong?
Also, I can't find the documentation on using the logging function in metadata scripts. Where is it?
phildunlap last edited by
I'm not sure what you're trying to do ever worked the way you're trying to do it. Every data type shares the PointValueTime return type for the lastValue, but all types of value are accessible. .value is going to return something with an 'object' type because it is a DataValue. The doubleValue is also an accessible property though! So, you can do either...
given that p is a numeric point.
This definitely worked as desired for years:
return (gallons.value - gallons.lastValue(1).value) / (gallons.time - gallons.lastValue(1).time) * (1000 * 60); // gallons per minute
and it suddenly stopped working in November. Anyways, your suggestion worked; thanks:
return (gallons.value - gallons.lastValue(1).doubleValue) / (gallons.time - gallons.lastValue(1).time) * (1000 * 60); // gallons per minute
The help states that I must use doubleValue for statistics functions, but lastValue is not a statistics function. Why is point.value treated differently than point.lastValue(1).value?
There should be more examples in the help to clarify this.
Ah! And there's the rub, you have supplied more information to the interpreter than "object - object" in those examples, those are "number - object" and a cast is implied.
I tried it on Mango 2.5.2 and it returns type of object. I also looked at the code involved since Mango's inception, which also would have been returning an object since Mango's inception.
Wait, sorry, I reread your sample that you sent us. I didn't realize it was always gallons.value - lastGallon.value as that's probably still number - object (and by the looks of things that doesn't matter, there isn't an implied cast to subtract an object from a number...)
We haven't changed anything about these for a long while though. We did some work on statistics objects and their return types, but we did not modify this in, say, the last year. (my impression from the code is "ever")
we did not modify this in, say, the last year.
In November I was still running Mango 2.5.2. Something definitely changed, because I had about a dozen metadata points using this script. I must have applied an upgrade in November. I don't recall what it was, but I upgraded straight from 2.5.2 to 2.7.2 in December, skipping 2.6 entirely. Now I'm on 2.7.3.
I expected gallons.value to work the same as lastGallon.value; and it did, provided I did not subtract one from the other. I urge you to add a git issue to create those wrappers you proposed, to make script writing more predictable, as the fix was counter-intuitive and I'm not sure the help does not lists all the functions available for each object. Of course, the other option is to change lastValue back to what it used to be: to return the same object type as the current point (p.time and p.value).
The other problem I'm having here is I cannot replicate. I have run up Mango 2.5.2 against Javas 7_79 and 8_65 and Mango 2.7.2 against Java 7 and 8 as compiled against 7 and 8 and when my script does....
print( typeof( p.lastValue(1).value ));
print( typeof( p.value ));
print( p.value - p.lastValue(1).value);
print( p.lastValue(0).value - p.lastValue(1).value)
I get results like...
So I guess I've surprised myself a little here. The only differences I've observed between 7 and 8 is that println became print and 7's print disappeared. That you say 2.7.3 concerns me a little, as I am unaware of such a version as of yet.