first commit
[bl_monitoring.git] / tools / generic_utils / dataPortioning_byTime.py
blobabc0176aead43d116b6c618bacff1ca79071ee24
1 #!/usr/bin/env python
3 import os, sys, time
5 from tools.generic_utils.time_formats import *
10 ##################################################
11 def get_dataPortion(data, timeInterval_sec):
13 if timeInterval_sec[0] < data[0][0] or timeInterval_sec[1] > data[len(data)-1][0]:
14 print "Invalid parameters in data_portionnig.get_dataPortion"
15 sys.exit(0)
17 i =0
18 while(data[i][0] < timeInterval_sec[0]):
19 i +=1
20 start_inx = i
22 while(data[i][0] <= timeInterval_sec[1]):
23 i += 1
24 end_inx = i
26 return data[start_inx:end_inx]
29 #################################################
30 def split_paramData(param_data, periods_str):
32 data_piecewise = []
34 periods_sec = periodsStr2periodsSec(periods_str)
36 i =0
38 for period in periods_sec:
39 #print period # debug
41 ## if period[0] < param_data[0][0] or period[1] > param_data[len(param_data)-1][0]:
42 ## print "Invalid parameters in data_portionnig.split_paramData"
43 ## sys.exit(0)
45 if period[0] < param_data[0][0] or period[1] > param_data[len(param_data)-1][0]:
46 return [param_data]
48 while(param_data[i][0] < period[0]):
49 i +=1
50 start_inx = i
52 while(param_data[i][0] <= period[1]):
53 i += 1
54 end_inx = i
56 data_piecewise.append(param_data[start_inx:end_inx])
58 return data_piecewise