|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Time Weighted Average calculationDoes anyone have any ideas of the best way to calculate a time weighted average for values in a given time window?
e.g. Assuming calculation at time T, for a window of 1000s and the following values: T - 100 : 10 T - 300 : 20 T - 1500 : 30 The value would be: (100 * 10) + (200 * 20) + (700 * 30) / 1000 = 26 In this case we'd need all of the events in a given time window (in this case 1000) plus the last event in the previous window. Additionally, we'd need timestamps for all of these along with the current time. We've tried unsuccessfully to do this using epl statements and can get pretty close. Would it be simpler to write this into a custom view (c.f. stat:uni) which may incorporate a custom window (c.f. time window with last event from previous window) and the calculation itself? Using this approach we'd have a reusable view that could calculate a TWA for any values. Any thoughts/ideas much appreciated. Phil |
|
|
Re: Time Weighted Average calculationHi Phil, I think a custom view could make this more efficient. For an EPL based solution, I think I would use a named window and on-select or unidirectional join, since it seems that every data point needs to be recomputed based on time passing. For a large number of datapoints this could be slow. So something like: create window MyWin (timestamp long, value double) insert into MyWin select current_timestamp as timestamp, value from MyEvent select avg((current_timestamp - timestamp) * 1000 * value) from MyWin, MyEvent.std:lastevent() unidirectional Best regards, Tom From: Phil Mo <philiprmorris@...> To: user@... Sent: Thursday, September 3, 2009 2:34:45 PM Subject: [esper-user] Time Weighted Average calculation Does anyone have any ideas of the best way to calculate a time weighted average for values in a given time window? e.g. Assuming calculation at time T, for a window of 1000s and the following values: T - 100 : 10 T - 300 : 20 T - 1500 : 30 The value would be: (100 * 10) + (200 * 20) + (700 * 30) / 1000 = 26 In this case we'd need all of the events in a given time window (in this case 1000) plus the last event in the previous window. Additionally, we'd need timestamps for all of these along with the current time. We've tried unsuccessfully to do this using epl statements and can get pretty close. Would it be simpler to write this into a custom view (c.f. stat:uni) which may incorporate a custom window (c.f. time window with last event from previous window) and the calculation itself? Using this approach we'd have a reusable view that could calculate a TWA for any values. Any thoughts/ideas much appreciated. Phil -- View this message in context: http://www.nabble.com/Time-Weighted-Average-calculation-tp25281750p25281750.html Sent from the Esper User list mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |