Correct meta script for rollup 1 hour delta on data point. Showing negative historical entry.
-
Thanks phildunlap,
I will give this a try.
Is there a meta script reference guide that you could point me to? I kind of new at Mango, and still trying to get up to speed.Thanks again.
-
No worries!
I'm not sure if you read it (but I would bet so if you're doing past() and delta), but the Mango JavaScript help text is quite useful. You can click the blue help icon on either the meta data source or the meta data point and you will see "Mango JavaScript" in the related items at the bottom. This text is also available here: http://help.infiniteautomation.com/support/solutions/articles/14000022520-about-mango-java-script
-
Hello Phil,
I went ahead and tried replacing the code with your recommended code. Purged all the historical data, and regenerated the History.
The strange thing now is that I have a extremely high, positive value for the 1am entry. At 2am, and after, the value is more of what I would expect.Now one thing I forgot to mention earlier, is that I am converting Totalized BTU's to totalized kBTU's with the following script:
return (p1.value * 0.001);
and then using the resulting Meta datapoint in the Script that you supplied earlier. I just noticed that I have the "Updates Context" checked on this calculated kBTU totalized point, and Update Event is set to "Context Update". Could that be part of my problem, where the delta point is Updating on the start of the Hour??
Thanks again for the help.
Ray
-
Hi Ray,
Extremely high? There is no division in that script, so either maximumValue is very large or firstValue is negative. Perhaps posting charts for the points and labeling their relationship to one another could be useful.
That all seems fine. You would want your scalar meta point to update on context, and you'd want your hourly point to only execute once an hour. You wouldn't want any points on the hourly point to be context update.
-
Here are some screenshots:
Screenshot1:
This is a kBTU per Hour Meta DataPoint. Notice the 1:00am entry is much higher than the 12am, or 2am entries.
Screenshot2:
This is the Totalized kBTU Meta dataPoint that I am using to calculate the above screenshot from, notice the 12:00:AM value:
EDIT: Pasted the Wrong pic, here is the correct one:
I have a Scheduled Event Handler resetting all of the actual bacnet I/P btu meter reset points for the totalized btu to zero at midnight every day. Thanks again for the help.
-
Hmm...
Maybe we would have been better off making the If( stats.delta < 0 ) condition as
return stats.lastValue;
-
Is there a way to syncronize the bacnet points with the Meta points, regarding timestamp? I notice that the bacnet source btu point , updates every minute and 55 seconds, and the Scheduled Event reset value doesn't log until 1 minute after midnight. My bacnet logs are on 1 minute intervals, but apparently they are not starting at the top of the hour/seconds 0:00. Very strange.
-
There is not a good way to synchronize that for BACnet currently, but you shouldn't really need to. In an upcoming version we'll be offering cron patterns as a means to define polling for all polling data sources. That 1 minute log interval will begin when the data source is enabled (whatever second that may be). For BACnet, values can arrive via COV subscription as well, which prevents quantizing the time. Some data sources do have a 'quantize' option to poll on only whole intervals of the period.
The bad way that comes to mind would be calling the RuntimeManager.disableDataSource( dsXid ) then RuntimeManager.enableDataSource( dsXid ) from within a script. That'd almost certainly sync it up to just after the execution of the script, but I wouldn't play with that as a real solution to anything.
One can set the TIMESTAMP variable to an epoch time within a meta point to specify what time the returned value is to be logged at, however.
-
Hello Phil,
just letting you know that your following recommended script:
var stats = p143.past(HOUR); if( stats.delta < 0 ) /* this is probably the right solution */ return stats.lastValue; return stats.delta;
Took care of my issue. Thanks again for all of your help.
-
Glad to be of service!
-
Hi Phil,
You had helped me a while ago with the following script in this thread:
var stats = p143.past(HOUR); if( stats.delta < 0 ) /* this is probably the right solution */ return stats.lastValue; return stats.delta;
Having the odd thing happen occasionally where the delta value goes to a negative value ( less than 0) at some point during the day, and not just after midnight of each day. As you may recall from this previous thread, this calculation was to combat a totalized reset at the start of each day, and to eliminate the extreme delta value that would occur at the beginning of each day. This script has been working great. It's just occasionally, I will record negative delta value, say at 11AM in the morning, and the script will return the "stats.lastValue;" which appears to be the totalized last value, and not the last delta value. This adds a very high spike to the chart of data as shown below at the 11AM position:
I was hoping you has some insight as how to possibly try to fix this occasional extreme value.Thanks
-
Hi Ray,
But we had a precondition! I wonder how negative it actually is, since I would assume it really shouldn't go negative from your description (except when reset).
I suspect we could account for whatever is happening by moving our perception of a restart from stats.delta < 0 to stats.delta < -50 or so. Then it'll go ahead and log the negative delta in that case (so long as it is greater than -50).
var stats = p143.past(HOUR); if( stats.delta < -50 ) /* permit small negative deltas */ return stats.lastValue; return stats.delta;
Alternatively, we could use the time of day in the script to figure out when to return the stats.lastValue, like
var stats = p143.past(HOUR); if( new Date().getHours() == 0 ) /* your hour may vary, you may need 1 instead of 0 */ return stats.lastValue; return stats.delta;
-
Hi Phil,
The lowest I've seen the delta go is -1.1 or so. I like the Idea of < -50, I think that will work. I will give this a shot.
Thanks Again.