asaikk Posted February 17, 2012 Share Posted February 17, 2012 Early today I asked on an expression for "Minutely summing up the sec when Pressure is positive" I managed to develop it for myself. Following are the expression. ------------------------------------------------------------------------------------------------------------------ \\ Summing up the sec when Pressure is positive \\ Setting Data02 to input into Channel "DataBox02" \\ Pressure is read every 5 sec if (Pressure[0]>0) private Data02 = 5 else private Data02 = 0 endif DataBox02.addValue(Data02) ------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------ \\ Summing up the sec when Pressure is positive \\ Expression on Channel DataBox02 \\ Minutely summing up DataBox02 and put into Channel "SumupMinutely" if (formatDateTime("%M", DataBox02.time[0]) != formatDateTime("%M", DataBox02.time[1])) private endtime = DataBox02.time[1] private starttime = endtime - (endtime % 60) private theSum = sum(DataBox02[starttime, endtime]) theSum.time = endtime SumupMinutely.addValue(theSum) endif ------------------------------------------------------------------------------------------------------------------ Link to comment Share on other sites More sharing options...
AzeoTech Posted February 17, 2012 Share Posted February 17, 2012 That is another way to do it, but if it doesn't allow you to change the interval for the pressure reading without remembering changing the code. Truthfully, you don't really need to do any of this if you want to assume the spacing is 5. For example, the number of minutes the pressure has been above 0 today is simply: sum(pressure[systime() - systime()%86400, systime()] > 0) * 5 This uses simple boolean math: pressure > 0 returns an array of 0's and 1's. The sum of that array is the number of intervals that pressure is greater than 0. Multiply that by 5 minutes per interval and you have the result. The stuff in the [] is just math to subset from the start of today until now. You can do the last hour by simply changing the 86400 to 3600. Link to comment Share on other sites More sharing options...
asaikk Posted February 17, 2012 Author Share Posted February 17, 2012 Thank you for your advice. Applying the code you mentioned, I have got a very useful expression which sums up data from the beginning of the minute, hour, etc(below). -------------------------------------------------------------------------------- \\ Beautiful code \\ Summing up DataBox03 and put it into Channel "DataBox04" from the beginning of the minute \\ Expression on Channel DataBox03 private Data04 = sum(DataBox03[systime() - systime()%60, systime()]) DataBox04.addValue(Data04) Link to comment Share on other sites More sharing options...
asaikk Posted August 6, 2013 Author Share Posted August 6, 2013 >sum(pressure[systime() - systime()%86400, systime()] >The stuff in the [] is just math to subset from the start of today until now. As for above, I have a simple question ; Concerning (a) MyData[systime() - systime()%86400, systime()] and ( MyData[systime(), systime() - systime()%86400], the subset ( seems to be the reversed that of (a), so, my understanding is, (a) and ( are the same when used for "sum()" or "mean()". Is it correct? Thanks in advance. Link to comment Share on other sites More sharing options...
AzeoTech Posted August 6, 2013 Share Posted August 6, 2013 It doesn't matter. DAQFactory doesn't care which time you put first. Same applies for index. So: x[1,2] yields the same as x[2,1] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.