cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Thingworx Property Running hours - how do I convert sensor reading that is in seconds to hours

stevenastewart
7-Bedrock

Thingworx Property Running hours - how do I convert sensor reading that is in seconds to hours

Novice here.  We have sensor data coming from a compressor and the value is in seconds.  Showing that does not make sense (large number, see attachment), but not sure how or where to convert it to hours.  Tried filter on the binding in Vuforia Studio, but nothing worked.  Looked at TW properties, but didn't see anything that help.

ACCEPTED SOLUTION

Accepted Solutions

Thanks Sharon.

Not sure which board I opened this on but with Vuforia Studio, I was able to get what I wanted with this code in the Filter section of a binding:

https://stackoverflow.com/questions/8211744/convert-time-interval-given-in-seconds-into-more-human-readable-form
WORKED!
seconds = Number(value);
var numyears = Math.floor(seconds / 31536000);
var numdays = Math.floor((seconds % 31536000) / 86400); 
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;
value = numyears + " years " +  numdays + " days " + numhours + " hours " + numminutes + " minutes " + numseconds + " seconds";
return value;

View solution in original post

2 REPLIES 2

Hi @stevenastewart.

 

If you're not interested in retaining the actual raw values in seconds, it would be more efficient to make the conversion on the device end before sending to ThingWorx, if possible.  If you do need to retain that raw data, the conversion can be done in ThingWorx via a service but could add a load on your server if you have many devices.

 

If you're unsure of how best to handle this, please provide more details around your use case and we will try to assist.

 

Regards.

 

--Sharon

Thanks Sharon.

Not sure which board I opened this on but with Vuforia Studio, I was able to get what I wanted with this code in the Filter section of a binding:

https://stackoverflow.com/questions/8211744/convert-time-interval-given-in-seconds-into-more-human-readable-form
WORKED!
seconds = Number(value);
var numyears = Math.floor(seconds / 31536000);
var numdays = Math.floor((seconds % 31536000) / 86400); 
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;
value = numyears + " years " +  numdays + " days " + numhours + " hours " + numminutes + " minutes " + numseconds + " seconds";
return value;
Announcements


Top Tags