DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate mean value with conditions

Solved!
Go to solution

Hello everyone,

 

With a customer requesting last Wednesday to review about 800 hundreds TDMS files for last Friday morning (yes, I'm already late), I decided to take a chance with VBS in DIAdem, although I knew nothing.

 

I manage to create a script that goes through a selected folder, reads each TDMS file, writes the file name in a txt file, calculate the mean value of a channel, writes this value in the txt file and moves the tdms file after reading.

 

But, and that's where I'm struggling, I have to calculate the mean value ONLY for the line where an other channel is set at "1".

To be more explicit, the files are created by a braking testbench. I have, to be short, 3 important channels : time, braking_pressure and active_braking.

I need to calculate the mean braking pressure value only when braking is active.

 

I have the intuition that is could be something like :

 

"for each line of the file

  if active_braking = 1 then

store the braking_pressure in an array

end if

calculate the mean value of the array"

 

I could use some help with this topic.

 

You can find attached the script as it is by now.

 

Thank you !!

 

JC

0 Kudos
Message 1 of 4
(999 Views)
Solution
Accepted by JCERRO_CETIM

Hi JCERRO_CETIM,

 

For such calculation you can use the channel event functions in DIAdem:

P1.png

You define a window where the active_braking channel is 1 or higher

P2.png

and calculate the mean at this areas for the braking-preasure channel

P3.png

With CTRL+SHIFT+C you can copy the script commands to the clipboard. Also the DIAdem help provides more small examples using a command as keyword.

The example is attached.

 

Greetings

Walter

 

0 Kudos
Message 2 of 4
(989 Views)

Hi Walter_Rick,

 

Thank you for your answer !

I did not know (I said I was new at DIAdem and VBS) that you could use built-in tools to create piece of code !

 

I however managed to find a solution on my own 😉

 

I used an array to store the data line by line if the condition is fullfilled :

 

nbr_point = 0
overall_pressure = 0

set voie_pression = data.GetChannel("[1]/FREINAGE_CP1")
set voie_active_freinage = data.GetChannel("[1]/ACTIVE_FREINAGE")

channel_size = voie_pression.Size

do while i <= channel_size
if voie_active_freinage.Values(i) = 1 then
'redim preserve freinage_active(ubound(freinage_active)+1)
'freinage_active(ubound(freinage_active))=voie_pression.Values(i)
overall_pressure = overall_pressure + voie_pression.Values(i)
nbr_point = nbr_point+1
end if
i=i+1
loop

average = overall_pressure/nbr_point

 

Thank you 🙂

I did not coded since the end of enginering school, it was fun !

0 Kudos
Message 3 of 4
(981 Views)

Hi JCERRO_CETIM,

 

Of course you can define or develop this by your own. That is always possible. However our experience is that a) own developed script code is typically slower (this is because it is running in VBS) and b) you must maintain this script code yourself.

 

In anyway, it is important to have a solution.

 

Greetings

Walter

0 Kudos
Message 4 of 4
(969 Views)