5 from tools
.generic_utils
.time_formats
import *
6 from tools
.generic_utils
.time_intervals
import *
7 #from tools.generic_utils.dataPortioning_byTime import *
10 #############################################
11 def get_okIntervals_indxs(param
, param_data
):
13 if len(param_data
) == 0:
14 return [] # it is not really correct but we are not supposed to get here
16 #timeInterval_sec = periodsStr2periodsSec([timeInterval_str])[0]
23 for i
in range(len(param_data
)):
25 ok
= param
.is_ok(param_data
[i
][1])
29 elif not ok
and was_ok
:
32 ok_intervals
.append((curr_startInx
, curr_endInx
))
34 #if curr_startInx != -1 and curr_endInx == -1:
35 if curr_startInx
> curr_endInx
:
36 ok_intervals
.append((curr_startInx
, len(param_data
)-1))
38 #print ok_intervals # debug
40 ## if len(ok_intervals) == 0:
46 #################################################################################
47 def get_extraPeriods(param
, param_data
, timeInterval_str
, minLength_sec
= 0):
50 okIntervals_indxs
= get_okIntervals_indxs(param
, param_data
)
52 if len(okIntervals_indxs
) == 0:
57 timeInterval_sec
= periodsStr2periodsSec([timeInterval_str
])[0]
59 if okIntervals_indxs
[0][0] == 0:
60 first_start
= timeInterval_sec
[0]
61 else: first_start
= param_data
[okIntervals_indxs
[0][0]][0]
63 #print sec2str(first_start) # debug
65 if okIntervals_indxs
[-1][1] == len(param_data
)-1:
66 last_end
= timeInterval_sec
[1]
67 else: last_end
= param_data
[okIntervals_indxs
[-1][1]][0]
69 #print sec2str(last_end) # debug
71 if len(okIntervals_indxs
) == 1:
72 subIntervals_sec
.append( (first_start
, last_end
) )
74 subIntervals_sec
.append((first_start
, param_data
[okIntervals_indxs
[0][1]][0]))
75 for i
in range(1, len(okIntervals_indxs
)-1):
76 subIntervals_sec
.append((param_data
[okIntervals_indxs
[i
][0]][0], param_data
[okIntervals_indxs
[i
][1]][0]))
77 subIntervals_sec
.append((param_data
[okIntervals_indxs
[-1][0]][0], last_end
))
81 return periodsSec2periodsStr( select_longIntervals(subIntervals_sec
, minLength_sec
) )
84 #################################################################################
85 def get_steadyPeriods(param
, param_data
, timeInterval_str
, minLength_sec
= 0):
87 #subIntervals_sec = periodsStr2periodsSec([timeInterval_str])
89 var_data
= param
.get_variation(param_data
, periodsStr2periodsSec([timeInterval_str
])[0])
91 okIntervals_indxs
= get_okIntervals_indxs(param
, var_data
)
95 for i
in okIntervals_indxs
:
96 subIntervals_sec
.append( (var_data
[i
[0]][0][0], var_data
[i
[1]][0][1]) )
97 param_vals
.append(param_data
[i
[0]][1])
99 #return periodsSec2periodsStr( select_longIntervals(subIntervals_sec, minLength_sec) ), param_vals
100 return periodsSec2periodsStr(subIntervals_sec
), param_vals
102 #################################################################################
103 def takeWholeOrEmpty_extendingTime(param
, timeInterval_str
, param_data
):
105 if ( str2sec(timeInterval_str
[1]) - str2sec(timeInterval_str
[0]) <=
106 float(param
.archiving_period
)/1000 ):
108 extended_timeInterval_sec
= ( max( str2sec(timeInterval_str
[1])- float(param
.archiving_period
)/1000,
110 str2sec(timeInterval_str
[1]) )
112 # take the corresponding portion of param_data
113 data_portion
= get_dataPortion(param_data
, extended_timeInterval_sec
)
115 if len(data_portion
) == 0:
116 print "No data for ", param
.attr_fullName
, " in the ", db
, \
117 " for the period ", periodsSec2periodsStr([extended_timeInterval_sec
])[0]
120 if param
.is_ok(data_portion
[-1][1]):
121 return [timeInterval_str
] # whole interval
123 return [] # empty list
125 print "No data for ", param
.attr_fullName
, " in the ", db
, \
126 " for the period ", timeInterval_str