python - SQL get aggregate value within a time-window in a time-series table -


i trying write sql method in python using sqlite/sqlalchemy build new table containing analyzed data mean, median, max, var on period of time, based on table contains raw time-series data.

let's raw data , timestamp not evenly distributed. want table: raw data table, aggregate value on 60-second sliding time window, e.g.:

raw: time      value 11:11:12   12 11:11:22   24 11:11:34   16 11:12:21   18 11:12:45   22 11:13:03   15 

and want get:

id  window_time      mean            median         max       var 1      11:11    mean(12,24,16)   med(12,24,16) ... 2      11:12    mean(18,22)      ... 3      11:13    ... ... 

how group data according timestamp?

if time column of time type (https://dev.mysql.com/doc/refman/5.7/en/time.html) in group by.

group time_format(`time`, '%h:%i') 

if, on other hand, column string type, things little trickier. suppose, if can guarantee every value in format hh:ii:ss, use substring.

group substring(`time` 1 5) 

if go either of these options, however, hope, sake, have paucity of records in database because i'm pretty sure each of these options going terrible in terms of performance. haven't done extensive tests, don't think mysql going able use indexes on either example.

honestly, you're better off creating table contains time hh:ii each record, , using table aggregate queries, trying in 1 query.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -