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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Problem with infinty loop need help

sred
1-Visitor

Problem with infinty loop need help

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

2 REPLIES 2
emoreira
14-Alexandrite
(To:sred)

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:

  1.      Create a DataTable in TWX
  2.      Create a datashape with Date (primary key)/TempMin/TempMax and associate it to the datatable
  3.      Create a code that changes that Adds a row for the current date and updates it in case the temperature values change (subscription to temperature value should work)
  4.      Add the QueryDatatableEntries to the mashup and link its AllDAta results to the chart.
  5.      Configure the chart

Cheers

Ewerton

ttielebein
14-Alexandrite
(To:emoreira)

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!

Announcements
Top Tags