<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Metadata Script execution when?]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">in the mango help <a href="http://help.infiniteautomation.com/support/solutions/articles/14000022524-meta-data-source" rel="nofollow ugc">http://help.infiniteautomation.com/support/solutions/articles/14000022524-meta-data-source</a> there is written 'see “Script execution” below' when it comes about when a script is executed.</p>
<p dir="auto">Sadly there is nothing written below...</p>
<p dir="auto">Can anyone tell me when a metadatasource is updated?</p>
<p dir="auto">Alex</p>
]]></description><link>https://forum.mango-os.com/topic/2344/metadata-script-execution-when</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Jul 2026 20:38:18 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2344.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Jul 2016 07:51:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 21 Nov 2017 20:18:59 GMT]]></title><description><![CDATA[<p dir="auto">Sure, you would do the same thing to get pvd, then do</p>
<pre><code>var values = pvd.getLatestPointValues(dataPointId, 2);
</code></pre>
]]></description><link>https://forum.mango-os.com/post/16269</link><guid isPermaLink="true">https://forum.mango-os.com/post/16269</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 21 Nov 2017 20:18:59 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 21 Nov 2017 20:15:50 GMT]]></title><description><![CDATA[<p dir="auto">I was thinking another way would be if you could get result sets directly from the historical database only. Query the historical table, get some results and then extract the values of the two most recent entries. Is that a doable thing? Sorry if this is pretty basic somehow, I just don't have the background with this thing quite yet to know :)</p>
]]></description><link>https://forum.mango-os.com/post/16268</link><guid isPermaLink="true">https://forum.mango-os.com/post/16268</guid><dc:creator><![CDATA[psysak]]></dc:creator><pubDate>Tue, 21 Nov 2017 20:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 21 Nov 2017 19:25:02 GMT]]></title><description><![CDATA[<p dir="auto">Hi psysak,</p>
<p dir="auto">I think you're right that your cache's contents have made it in to the statistics object.</p>
<pre><code>var now = new Date();
var pv1 = p1.pointValueBefore(now.getTime() - 420000); //May need some slight adjusting of these offsets
var pv2 = p1.pointValueBefore(now.getTime() - 120000);
return pv2.value - pv1.value;
</code></pre>
<p dir="auto">Unfortunately pointValueBefore() will also use the cache if the timestamp in the cache is prior to the requested time. But, you can probably handle that by triggering it on a context update and then having an execution delay (but know if your update interval is less than your execution delay, a meta point will never run. A script is the opposite, where it'll only schedule a timeout if it hasn't already)</p>
<p dir="auto">Edit: The only way to truly guarantee they're logged is to get the values out via point value dao. So,</p>
<pre><code>var pvd = com.serotonin.m2m2.Common.databaseProxy.newPointValueDao();
var pv1 = pvd.getPointValueBefore( dataPointId, now.getTime() - 420000);
...
//Note that it is dataPointId, not xid. In the next version of Mango you will be able to do something like p1.getDataPointWrapper().getId() 
// but for now it would require something like com.serotonin.m2m2.db.dao.DataPointDao.instance.getDataPointIdByXid(p1.getDataPointWrapper().getXid());
// if you need to do this programatically
</code></pre>
]]></description><link>https://forum.mango-os.com/post/16267</link><guid isPermaLink="true">https://forum.mango-os.com/post/16267</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 21 Nov 2017 19:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 21 Nov 2017 19:06:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/phildunlap" aria-label="Profile: phildunlap">@<bdi>phildunlap</bdi></a> said in <a href="/post/15928">Metadata Script execution when?</a>:</p>
<blockquote>
<p dir="auto">pointValueBefore( CONTEXT.timestamp - 300000 );</p>
</blockquote>
<p dir="auto">Hey Phil, just a quick question on this again. Is there a way to pick specifically historical database entries when doing a calculation? For example, I log something every 5 mins and I'd like to take the delta between the last two historical database entries. I want it to ignore any cached values or anything else, I just want the last two entries in the history database.<br />
I ask this cause I think I realized that the system interpolates values between historical entries, is that correct? For example, I log something now and again in exactly 5 mins. If I then wait 2 mins and say give me the delta past(MINUTE, 5), what values will it use to calculate that delta?</p>
<p dir="auto">This is my dataset as downloaded from the mango<br />
EO00002GE_1KWH	11-21-17 13:24:27.249	37922363	37922363.00<br />
EO00002GE_1KWH	11-21-17 13:29:27.249	37922748	37922748.00<br />
EO00002GE_1KWH	11-21-17 13:34:27.249	37923143	37923143.00<br />
EO00002GE_1KWH	11-21-17 13:39:27.249	37923537	37923537.00<br />
EO00002GE_1KWH	11-21-17 13:44:27.249	37923922	37923922.00<br />
EO00002GE_1KWH	11-21-17 13:49:27.249	37924313	37924313.00<br />
EO00002GE_1KWH	11-21-17 13:54:27.249	37924709	37924709.00<br />
EO00002GE_1KWH	11-21-17 13:59:27.249	37925101	37925101.00<br />
EO00002GE_1KWH	11-21-17 14:04:27.249	37925478	37925478.00</p>
<p dir="auto">You can see it's doing a bang up job, every 5mins. I just want the delta between the last two entries and that's it :)</p>
]]></description><link>https://forum.mango-os.com/post/16265</link><guid isPermaLink="true">https://forum.mango-os.com/post/16265</guid><dc:creator><![CDATA[psysak]]></dc:creator><pubDate>Tue, 21 Nov 2017 19:06:58 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 24 Oct 2017 17:28:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/phildunlap" aria-label="Profile: phildunlap">@<bdi>phildunlap</bdi></a> said in <a href="/post/15928">Metadata Script execution when?</a>:</p>
<blockquote>
<p dir="auto">wa</p>
</blockquote>
<p dir="auto">Ya that's exactly what I was thinking too, I'd rather do it in the field and I will most likely do that there for the reasons exactly you mentioned. I would much rather just publish the computed values to a central mango system. Goofing around with this allows me to do something with "live data", pretty well like sitting at the mango on site. If I can figure this out on here then I can templatize it and deploy in the field. Plus ultimately what I'm working towards is some per site email notifications etc so I'd probably rather each site manage that on it's own.</p>
<p dir="auto">Only downside is managing changes to a fleet of devices, that may become an issue.</p>
]]></description><link>https://forum.mango-os.com/post/15929</link><guid isPermaLink="true">https://forum.mango-os.com/post/15929</guid><dc:creator><![CDATA[psysak]]></dc:creator><pubDate>Tue, 24 Oct 2017 17:28:06 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 24 Oct 2017 17:27:01 GMT]]></title><description><![CDATA[<p dir="auto">lastValue definitely is using the cache. I've actually written a few posts advising people to use lastValue for its cache expansion properties (a point starts with a cache of default cache size, but if something queries it for latest x values the cache will expand until the next cache reset event (likely the purge)).</p>
<p dir="auto">You could indeed use <code>var.past(MINUTE, 5).delta</code> on a five minute interval or logged event. If you want to guarantee you're getting the value from the database at least five minutes ago, you could try <code>var.pointValueBefore( CONTEXT.timestamp - 300000 );</code></p>
<p dir="auto">Ultimately, I will never completely like any solution because I believe your data analysis meta point shouldn't be on the other side of a publisher from what it is analyzing. You should be computing that on the same device and publishing the result. The inevitable disconnects coupled with the interval logging still occurring guarantees junk data if the meta points are in the cloud.</p>
]]></description><link>https://forum.mango-os.com/post/15928</link><guid isPermaLink="true">https://forum.mango-os.com/post/15928</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 24 Oct 2017 17:27:01 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 24 Oct 2017 16:39:28 GMT]]></title><description><![CDATA[<p dir="auto">That's great info Phil thank you, exactly what I'm looking for.</p>
<p dir="auto">Do you mind if I run an application implementation idea past you? This is just my experiment platform, I may end up pushing these applications down to the field mangos but I'll see how it goes, just experimenting with what I can do.</p>
<p dir="auto">I have some Mango ES devices in the field. They poll local MODBUS devices for pulse counts (electric meter, water meter, gas meter) every minute. Currently I am goofing around with a cloud based Mango platform running on EC2. From the mangos on site, I push data to my central one using HTTP POST. The point updates are just an accumulated pulse count, so the number gets bigger and bigger all the time, and they are pushed every minute.</p>
<p dir="auto">On the cloud Mango instance I have told the equivalent points to perform instant logs every 5 minutes. I then have a meta point which attempts to calculate the last five minute interval delta (it also applies a meter factor and does a couple other quick maths to the number). My initial implementation was to try and use<br />
<strong>var.value - var.lastValue(1).value</strong> triggered at a 5 min interval, initially using CRON</p>
<p dir="auto">This was causing some issues and what I just figured out is that lastValue(1) seems to return just any last value, so cached values are returned. I thought that lastValue(1) would return the last logged value.</p>
<p dir="auto">I have now moved on to trying to use the following<br />
<strong>var.past(MINUTE, 5)</strong> triggered update type logged</p>
<p dir="auto">Since I am logging the context point at an interval of 5 minutes I would expect that the script is triggered only every 5 minutes and the delta should give me the difference in counts between now and 5 minutes ago. Do I understand this correctly?</p>
]]></description><link>https://forum.mango-os.com/post/15926</link><guid isPermaLink="true">https://forum.mango-os.com/post/15926</guid><dc:creator><![CDATA[psysak]]></dc:creator><pubDate>Tue, 24 Oct 2017 16:39:28 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 24 Oct 2017 16:01:24 GMT]]></title><description><![CDATA[<p dir="auto">Hi psysak,</p>
<p dir="auto">Scripts and meta points provide the option for a point in its context to trigger execution with one of the three point events configurable in the context update event type drop down. "Context Update" is every single new value (so polls, sets) so long as they are new. "Context Logged" is for logged data, so this would fire when an interval logging point stores data as opposed to when it polls. And "Context Changed" is like "Context Update" but stipulates that the update must also be a different value.</p>
<p dir="auto">Cron expressions link to this page for a tutorial: <a href="http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger" rel="nofollow ugc">http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger</a></p>
<p dir="auto">I believe the only possible idiosyncrasies there is that year support is limited, and in the vast majority of cases you shouldn't have a year in your Mango cron expressions. Also I believe the ? behaves as a wildcard in the Day of Week field.</p>
<p dir="auto">Meta points have a few semantic options for 'Start of minute', 'Start of hour' etc.</p>
<p dir="auto">Cron expressions and those updates are basically the same as if a point update were to have occurred: script execution is triggered.</p>
<p dir="auto">I just looked into execution delays and it looks like they work slightly differently. On a meta point, if you have an execution delay of 5 seconds with a point updating every 3 seconds, your meta point will never run. Each update cancels the timer and schedules the update again, five seconds out.</p>
<p dir="auto">Scripts work the opposite way, though, where if you execution delay is 5 seconds and you have a point updating every 3 seconds, the first update at time 0 will schedule the execution. The second update at time 3 will log an aborted poll message for the script, at time 5 the script will execute, at time 6 the third update occurs and the script is scheduled to execute at time 11.</p>
]]></description><link>https://forum.mango-os.com/post/15925</link><guid isPermaLink="true">https://forum.mango-os.com/post/15925</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 24 Oct 2017 16:01:24 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Tue, 24 Oct 2017 15:26:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi I just ran into this myself and cannot find the "Script Execution" section either, Mango help included. I'd really like to get some clarity on this topic.</p>
]]></description><link>https://forum.mango-os.com/post/15921</link><guid isPermaLink="true">https://forum.mango-os.com/post/15921</guid><dc:creator><![CDATA[psysak]]></dc:creator><pubDate>Tue, 24 Oct 2017 15:26:54 GMT</pubDate></item><item><title><![CDATA[Reply to Metadata Script execution when? on Thu, 14 Jul 2016 13:53:34 GMT]]></title><description><![CDATA[<p dir="auto">I believe that article was copied right out of Mango help and pasted into support documentation.  We are working to improve our documentation so thanks for pointing this out.  You can see this help topic in its entirety in Mango.  Click on the little blue ? icon in Mango in the<br />
<img src="https://camo.nodebb.org/54107441bbe31ae04d6ec50d0081d3671c42c258?url=https%3A%2F%2Fi.imgur.com%2Fq3NYgwT.png" alt="0_1468503886116_upload-a357b4ff-70f0-404a-9af7-ded5bda60e4e" class=" img-fluid img-markdown" />  of your Metadata data source.</p>
<p dir="auto">Metadata scripts execute either on context update or on a cron pattern. This is set here <img src="https://camo.nodebb.org/262df75a3ab18acb61649d6397642039b19a3776?url=https%3A%2F%2Fi.imgur.com%2F0RdMbY3.png" alt="0_1468504147120_upload-0714d747-164a-4aec-950a-5af422fa6d3d" class=" img-fluid img-markdown" /><br />
If you use context update then you may select which data points trigger the script. <img src="https://camo.nodebb.org/b363637c801dd55a4b470fce81c9658afc829922?url=https%3A%2F%2Fi.imgur.com%2FVT3kRjo.png" alt="0_1468504392873_upload-c5e40203-28dc-468d-8ed1-16e18a8dedb3" class=" img-fluid img-markdown" /></p>
<p dir="auto">Note: It's usually best to not select all of them as this can cause the script to execute too often and cause a performance problem. With power come responsibility :-)</p>
]]></description><link>https://forum.mango-os.com/post/12057</link><guid isPermaLink="true">https://forum.mango-os.com/post/12057</guid><dc:creator><![CDATA[Woody Beverley]]></dc:creator><pubDate>Thu, 14 Jul 2016 13:53:34 GMT</pubDate></item></channel></rss>