Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
my target is
1. calculate the temp max and temp min in day.
I got the logic how to do it
2. Plotting it over chart
This has an issue. when am trying to plot on chart it is having mulitple temp_max , temp_min on the same day
which is wrong
3. to solve the above problem i came up with a logic again that temp_max , temp_min will only be update at 6PM daily so that i can avoid multiple recordings in a same day
for this i came up with a logic and tried to implement it. But am not sure how to acheive this in thingworx
here is the code snippet i wrote
var count = 0 // count for il do 6 times but i wont update the temp_max, temp_min
while (1)
{
me.temperature = Math.floor((Math.random() * 50) - 10); am getting the random temp value
count++;
if (count == 1) at count 1 both temp_max, temp_min will be equal to temperature
{
me.temp_min = me.temperature ;
me.temp_max = me.temperature;
}
if(me.temperature <= me.temp_min)
{
me.temp_min = me.temperature ;
}
if (me.temperature >= me.temp_max)
{
me.temp_max = me.temperature ;
}
if (count == 6)
{
var result = me.temp_min;
var result = me.temp_max;
count=0;
}
}
I tried to run this on shell and acheive what i want
if u see in the script at 6th count the values are being set for that particular day
and next the counter sets to zero and again it will be triggered later
please and kindly help me how to acheive this in thingworx
Sin,
if you do not want to record every change on Temp Max/Min your code could populate a DataTable instead of recording the logged properties. then you would plot the datatable records in the Graph.
For that:
Cheers
Ewerton
Right, this is the best way to do it, I think. In step 3, in that service, just have it go to the DataTable and say "is there an entry for today?" if not, add it with the current values of temperature and humidity or whatever properties. If there is already a DataTable entry for the day, then just compare the current values of whatever properties with those in the DataTable, and if they are higher/lower than what is there, then update the DataTable with the new min and max values.
Hope this helps!