Would like to know the best practice to calculate machine downtime by running signal,
For example: running signal was collected and storage in Stream Table, data are timestamp and value 0 (stop) and 1(run)
timestamp0 : 1
timestamp1 : 0
timestamp2 : 1
timestamp3 : 0
timestamp4 : 1
Stop time should be: (timestamp2-timestamp1) + (timestamp4-timestamp3) + ....
What is best way to calculate/query in historian value in stream table?
Thank you so much!
In a service, you could retrieve(and filter) the property values(Up or down) and its timestamps using QueryNumberPropertyHistory/QueryBooleanPropertyHistory into an infotable and then loop through it to calculate the up time. More details on such functions can be found here.
If you are using InfluxDB for your stream, another option would be to use the ELAPSED() function of InfluxDB in TWX service by using InfluxDB API /query HTTP endpoint.
Although this would be a select query, please note that in this case you are dealing directly with the database and sufficient precaution should be exercised to prevent any data corruption when directly interacting with DB.
I suppose in your case there will not be many data points. So, first approach should suffice.
Just to add to @rjanardan reply, depending on your access pattern you may consider precalculating those values, either at the time of inserting them, or in batch mode on the regular intervals.
There's no single "best practice", it really depends on multiple factors, such as:
Thank for the reply, my case is calculation OEE of machine (IIoT app), availability, performance are relate to downtime by running signal (we cannot implement the logic and handshaking in the controller, just read via Kepware). In additional, it will be implemented for productive application, not only a concept. Thus I want to know the best way.
The downtime can be minor or major, but the number of data I think it's not too much in one day/shift
Yes, can loop through the data if there is no better way.
I would like to calculate every hour and store OEE data in another InfoTable and purge old data after period of time, so that i can reduce the load when clients query the OEE data.
Appreciate to hear your idea.