Package coprs :: Package logic :: Module helpers
[hide private]
[frames] | no frames]

Source Code for Module coprs.logic.helpers

 1  # coding: utf-8 
 2  import time 
 3   
4 -def slice_query(query, limit=100, offset=0):
5 """ 6 :param Query query: 7 :param int limit: 8 :param int offset: 9 :rtype: Query 10 """ 11 return query.limit(limit).offset(offset)
12
13 -def get_graph_parameters(type):
14 if type == "10min": 15 # 24 hours with 10 minute intervals 16 step = 600 17 steps = 144 18 elif type == "30min": 19 # 24 hours with 30 minute intervals 20 step = 1800 21 steps = 48 22 elif type == "24h": 23 # 90 days with 24 hour intervals 24 step = 86400 25 steps = 90 26 27 end = int(time.time()) 28 end = end - (end % step) # align graph interval to a multiple of step 29 start = end - (steps * step) 30 31 return { 32 "type": type, 33 "step": step, 34 "steps": steps, 35 "start": start, 36 "end": end, 37 }
38