Expression of procedure for summing up


asaikk

Recommended Posts

I am doing a new exercise, trying to make an expression whose objective is :

"counting and summing up the time (seconds) when the pressure is positive"

I have made so far below;

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

\\ Summing up the sec when Pressure is positive

private Data02 = 0

if (Pressure[0]>0)

Data02 = Data02+1

else

Data02 = Data02

endif

DataBox02.addValue(Data02)

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

(Pressure is read every second.)

and the problem I have now is

"declaration and input of initial data (=0) for Data02 shoule be stated elsewhere than this expression."

Would you teach me how to do this?

The target I aim is to make this procedure hourly, that is , input "0" at the start of every hour.

Thanks in advance

Link to comment
Share on other sites

That's a start, except you are initializing data02 every time, so you only get 0 or 1. I'm assuming you are putting this in the event of pressure? Do this:

1) create a sequence marked auto start and put:

databox02.addValue(0)

2) in the event for your pressure sequence you want:

private data02 = dataBox02[0]
if (formatDateTime("%H", pressure.time[0]) != formatDateTime("%H", pressure.time[1])
   // new hour
   data02 = 0
endif
if (pressure[0] > 0)
   data02 += (pressure.time[0] - pressure.time[1])
endif
data02.time = pressure.time[0]
databox02.addValue(data02)

Link to comment
Share on other sites

  • 2 weeks later...

Hey Guru,

So what if Pressure is not a channel but a global type variable,

formatDateTime("%M", Pressre.time[0])

will always shows a constant no matter when you flash the pressure data?

or if I do need the Pressure value and its corresponding time, I should need but Pressure into a test channel?

More options?

Cheers~

Link to comment
Share on other sites

Okay I found a trick here,

if I put:

Pressure[1] = Pressure[0]
Pressure[0] = *** (some sort of expression)
then
? formatDateTime("%S", Pressure.time[0])

then Pressure time can updated in real time.

What is the differences for these two ways assuming here Pressure is a variable of global type.

cheers,

Solomem

Link to comment
Share on other sites

The command / alert window is a great place to check this stuff out yourself. First, I'm assuming the typo in your first post is just in the forum (you have "Pressre.time[0]).

Next, a global variable gets assigned time with every assignment. To see this in the command/alert, just type these commands:

global x

x = 3

? getTime(x)

you'll get the time stamp when you did x = 3. Now:

x = 4

? getTime(x)

you'll get a different time stamp, for when you did x = 4.

The trick to this is to remember that it only assigns the timestamp when the timestamp is not available. So, if you did:

global y = x

? getTime(y)

you'll see that it gives you the timestamp of when you did x=4, not when you did y=x. This is because it pulls the timestamp from x. If you want a different timestamp, you'd have to do something like:

y.time = systime()

? getTime(y)

Note that getTime(y) and y.time are the same thing, except that you can assign a value to y.time. This is all assuming scalar variables, not channels or arrays.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.