# Expression for Summing up the sec when Pressure is positive

## Recommended Posts

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)

private Data02 = 5

else

private Data02 = 0

endif

------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------

\\ 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) != formatDateTime("%M", DataBox02.time))

private endtime = DataBox02.time

private starttime = endtime - (endtime % 60)

private theSum = sum(DataBox02[starttime, endtime])

theSum.time = endtime

endif

------------------------------------------------------------------------------------------------------------------

##### Share on other sites

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.

##### Share on other sites

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()])

##### Share on other sites

• 1 year later...

>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?