DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Daily Max Calculations

Hi,

 

I'm trying to perform calculations on my timeseries data in per day chunks. Specifically, I want to calculate the max value of my data channel for each day and then dump the data and associated datetime values into two new channels. Does anyone know how I might be able to do this?

 

My files typically contain two years' worth of 1 Hz data, but I usually resample the data at a slower rate and generate a new time channel to cut down on the channel length.

0 Kudos
Message 1 of 3
(3,806 Views)

Hi;

 

Can you upload a sample file that shows the format? Not the whole file, but enough data to be able to test. That way it would be easier to give you more specific advice.

 

Pedro M.

0 Kudos
Message 2 of 3
(3,781 Views)

I actually ended up figuring it out myself. I found the a script to calculate daily sums and just had to make a few changes to have it calculate max values instead of sums. The only minor issue I found with this script is that my data can't start mid-day, it needs to start on hour 0 of the first day (i.e. if I have data that starts on 22:00 on 9/19/2012, it calculates the max between 22:00 9/19/2012 and 22:00 9/20/2012, and so on). Here it is:

 

OPTION EXPLICIT

Dim DayRows, SumChs, DayVals
Call GroupCreate("Daily Totals")
Call GroupDefaultSet(GroupCount)

SumChs = Array("DateTimeLocalPeaks", "MWgainPeaks")
Call GetDayRows(DayRows, SumChs, DayVals)
Call CalcSumChs(DayRows, SumChs, DayVals)


'-------------------------------------------------------------------------------------
'-- GetDayRows() -- -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub GetDayRows(DayRows, SumChs, DayVals)
Dim i, k, iMax, DayChNum, DayValStart, DayRowStart, DayCurrVal, DayRowStr
DayChNum = CNo(SumChs(0))
iMax = ChnLength(DayChNum)
ReDim DayRows(iMax)
ReDim DayVals(iMax)
DayRowStart = 1
DayValStart = ChDX(1, DayChNum)
FOR i = 2 TO iMax
DayCurrVal = ChDX(i, DayChNum)
IF RTP(Abs(DayCurrVal-DayValStart), "D") > 1 THEN
Call UpdateDayRows(DayRows, k, i, DayRowStart, DayValStart, DayCurrVal, DayVals)
END IF ' next day
NEXT ' i
Call UpdateDayRows(DayRows, k, i, DayRowStart, DayValStart, DayCurrVal, DayVals)
ReDim Preserve DayRows(k)
ReDim Preserve DayVals(k)
End Sub ' GetDayRows()


'-------------------------------------------------------------------------------------
'-- UpdateDayRows() -- -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub UpdateDayRows(DayRows, k, i, DayRowStart, DayValStart, DayCurrVal, DayVals)
k = k + 1
DayRows(k) = DayRowStart
DayVals(k) = DayValStart
IF i > DayRowStart+1 THEN DayRows(k) = DayRows(k) & "-" & CStr(i-1)
DayRowStart = i
DayValStart = DayCurrVal
End Sub ' UpdateDayRows()


'-------------------------------------------------------------------------------------
'-- CalcSumChs() -- -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub CalcSumChs(DayRows, SumChs, DayVals)
Dim i, j, iMax, SumChNum
iMax = UBound(DayRows)
FOR i = 1 TO 22
StatSel(i) = "No"
NEXT ' i
StatSel(5) = "Yes"
StatClipCopy = 0
StatClipValue = 0
StatResChn = 0
Call ChnAlloc(ChnName(SumChs(0)), iMax, 1, DataTypeFloat64, "Time")
SumChNum = CNoXGet(GroupCount, GroupChnCount(GroupCount))
ChnLength(SumChNum) = iMax
FOR i = 1 TO iMax
ChDX(i, SumChNum) = DayVals(i)
NEXT ' i
Call ChnCharacter(SumChNum)
FOR j = 1 TO UBound(SumChs)
Call ChnAlloc(ChnName(SumChs(j)), iMax)
SumChNum = CNoXGet(GroupCount, GroupChnCount(GroupCount))
ChnLength(SumChNum) = iMax
FOR i = 1 TO iMax
Call StatBlockCalc("Channel", DayRows(i), SumChs(j))
ChDX(i, SumChNum) = StatMax
NEXT ' i
Call ChnCharacter(SumChNum)
NEXT ' j
End Sub ' CalcSumChs()

 

0 Kudos
Message 3 of 3
(3,775 Views)