Hours since last point update
-
Here's a quick meta point script that returns the number of hours (in decimal) since a point has last updated:
//returns the number of hours since the value (genset power) last changed //get the current epoch now = new Date().getTime(); //get the point's last timestamp epoch then = p1117.time; //get delta in milliseconds delta = now - then; //convert milliseconds to hours hours = delta / 3600000 return hours;
This is useful if you want to know, for example, how many hours something has gone without running. It assumes that no new values on the points means the 'thing' isn't running, in my case I am looking at the output power of a gen-set to determine when it last ran.
-
It seems like, datapoint value's timestamp change every datasoure poll even if it's value don't change,so the last point update's time = datasource last poll time.
-
Generally true Hussam, but not always.
If a datasource fails polling some points but not others, it will only update the times of those it successfully polled. Or, if the entire poll fails, no timestamps will be updated. The timestamp displayed for a point on the data point details page does reflect the cache's perspective, meaning what the value of a point is and when that value was reported last. Other ways of accessing data can get you timestamps that reflect those which will ultimately be logged in the database.
For example, compare two meta scripts being run on a point receiving 1 second updates, but not always changing (I used a virtual binary point on random): It is set to log on change.
return new Date(p1.time); //returns the date of the last update
return new Date(p1.lastValue(0).time); //returns the date of the last logging