def getTimes(self): t0 = str2localtime(self.ui.comboBox_begin.currentText()) t1s = self.ui.comboBox_end.currentText() # if not absolute time if self._ts_re.match(t1s) is None: t1s = t1s.replace('now', '{}'.format(time.time() - str2time(t0))) t1s = str2time(t0) + str2time(t1s) t1 = str2localtime(t1s) return t0, t1
def split_interval_in_months(start,stop,cut=True): """ returns a list of start,stop tuples for each month in the interval if cut is True, then first and last interval are adjusted to start,stop """ months = get_months_in_interval(start,stop) months.append(get_next_month(months[-1])) months = zip(months,months[1:]) months = list(list((str2time(b),str2time(e)-1)) for b,e in months) if cut: months[0][0],months[-1][-1] = start,stop return months
def get_days_in_interval(*args): """ args may be a list of timestamps or just start,stop dates """ if len(args)==2: if fun.isString(args[0]): start,stop = str2time(args[0]),str2time(args[1]) else: start,stop = args[0],args[1] times = range(int(start),int(stop+86400),86400) else: times = args[0] days = sorted(set(list(d.split()[0] for d in map(time2str,times)))) return days
def get_days_in_interval(*args): """ args may be a list of timestamps or just start,stop dates """ if len(args)==2: if fun.isString(args[0]): start,stop = str2time(args[0]),str2time(args[1]) else: start,stop = args[0],args[1] times = range(int(start),int(stop),86400) else: times = args[0] days = sorted(set(list(d.split()[0] for d in map(time2str,times)))) return days
def str2localtime(str_time): try: v = float(str_time) except ValueError: v = str2time(str_time) if v < 0: v = time.time() + v v = time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(v)) return v
def dates2times(argin): """ Parsing dates like 'Y-M-D h:m' or '+/-X(shmdw)' """ return [fn.time2str(fn.str2time(a)) for a in argin]
def decimation(history, method, window='0', logger_obj=None, N=1080): """ Nones and NaNs are always removed if this method is called history: array of data method: method or callable window: string for time logger_obj: ArchivedTrendLogger or similar N: max array size to return """ t0 = time.time() l0 = len(history) if not l0: return history trace = getattr(logger_obj, 'warning', fandango.printf) try: window = str2time(window or '0') except: window = 0 start_date, stop_date = float(history[0][0]), float(history[-1][0]) ## Decimation by data_has_changed is ALWAYS done if len(history): #method is not None nv = [] #sq = isSequence(history[0][1]) for i, v in enumerate(history): if (v[1] not in (None, NaN ) # is not None and (sq or not isNaN(v[1])) #and (i in (0,l0-1,l0-2) or #data_has_changed(history[i-1],v,history[i+1])) ): nv.append(v) t1 = time.time() trace('Removed %d (None,NaN, Rep) values in %fs' % (l0 - len(nv), t1 - t0)) t0, i, c, lh = t1, 0, 0, len(history) while i < len(history): if history[c] in (None, NaN): history.pop(c) else: c += 1 i += 1 t1 = time.time() trace('Removed %d (None,NaN, Rep) values in %fs' % (l0 - len(history), t1 - t0)) history = nv if (method and isCallable(method) and method != data_has_changed and len(history) and type(history[0][-1]) in (int, float, bool)): #type(None)): # Data is filtered applying an averaging at every "window" interval. # As range() only accept integers the minimum window is 1 second. # It means that filtering 3 hours will implicitly prune millis data. #DATA FROM EVAL IS ALREADY FILTERED; SHOULD NOT PASS THROUGH HERE wmin = max(1., (stop_date - start_date) / (10 * 1080.)) wauto = max(1., (stop_date - start_date) / (10 * N)) trace('WMIN,WUSER,WAUTO = %s,%s,%s' % (wmin, window, wauto)) window = wauto if not window else max((wmin, window)) if len(history) > (stop_date - start_date) / window: history = fandango.arrays.filter_array(data=history, window=window, method=method) t2 = time.time() trace('Decimated %d values to %d in %f seconds ' '(%s,%s)' % (l0, len(history), t2 - t1, method, window)) else: trace('Decimation is not callable') return history
def decimation(history,method,window='0',logger_obj=None, N=1080): """ Nones and NaNs are always removed if this method is called history: array of data method: method or callable window: string for time logger_obj: ArchivedTrendLogger or similar N: max array size to return """ t0 = time.time() l0 = len(history) if not l0: return history trace = getattr(logger_obj,'warning',fandango.printf) try: window = str2time(window or '0') except: window = 0 start_date,stop_date = float(history[0][0]),float(history[-1][0]) ## Decimation by data_has_changed is ALWAYS done if len(history): #method is not None nv = [] #sq = isSequence(history[0][1]) for i,v in enumerate(history): if (v[1] not in (None,NaN)# is not None and (sq or not isNaN(v[1])) #and (i in (0,l0-1,l0-2) or #data_has_changed(history[i-1],v,history[i+1])) ): nv.append(v) t1 = time.time() trace('Removed %d (None,NaN, Rep) values in %fs' %(l0-len(nv),t1-t0)) t0,i,c,lh = t1,0,0,len(history) while i<len(history): if history[c] in (None,NaN): history.pop(c) else: c+=1 i+=1 t1 = time.time() trace('Removed %d (None,NaN, Rep) values in %fs' %(l0-len(history),t1-t0)) history = nv if (method and isCallable(method) and method!=data_has_changed and len(history) and type(history[0][-1]) in (int,float,bool)): #type(None)): # Data is filtered applying an averaging at every "window" interval. # As range() only accept integers the minimum window is 1 second. # It means that filtering 3 hours will implicitly prune millis data. #DATA FROM EVAL IS ALREADY FILTERED; SHOULD NOT PASS THROUGH HERE wmin = max(1.,(stop_date-start_date)/(10*1080.)) wauto = max(1.,(stop_date-start_date)/(10*N)) trace('WMIN,WUSER,WAUTO = %s,%s,%s'%(wmin,window,wauto)) window = wauto if not window else max((wmin,window)) if len(history) > (stop_date-start_date)/window: history = fandango.arrays.filter_array( data=history,window=window,method=method) t2 = time.time() trace('Decimated %d values to %d in %f seconds ' '(%s,%s)' %(l0,len(history),t2-t1,method,window)) else: trace('Decimation is not callable') return history