def timber_to_csv(start_time, end_time='Now', filename_prefix='SPSmeas_', outp_folder=None, t_query_interval=1800., t_query_interval_fine=60., filename_retrieved='bqm_retrieved.txt'): try: with open(filename_retrieved, 'r') as fid: list_retrieved = fid.read().split('\n') except IOError: list_retrieved = [] if type(start_time) is str: start_tstamp_unix = th.localtime2unixstamp(start_time) else: start_tstamp_unix = start_time if end_time == 'Now': end_tstamp_unix = time.mktime(time.localtime()) elif type(end_time) is str: end_tstamp_unix = th.localtime2unixstamp(end_time) else: end_tstamp_unix = end_time if outp_folder == None: outp_folder = 'BQM_CSVfromTimberDB' if not os.path.exists(outp_folder): os.makedirs(outp_folder) varlist = get_timber_varlist() print 'VARLIST', varlist t_queries = np.arange(start_tstamp_unix, end_tstamp_unix, t_query_interval) for t_query in t_queries: outp_compl_path = outp_folder + '/' + filename_prefix + '%d_%d.csv'%(t_query, t_query_interval) if outp_compl_path in list_retrieved: continue lldb.dbquery(varlist, t_query, t_query+t_query_interval, outp_compl_path) with open(filename_retrieved, 'a+') as fid: fid.write(outp_compl_path + '\n') # In case something goes wrong with the request -> use a shorter interval. if not os.path.exists(outp_compl_path): t_queries_fine = np.arange(t_query, t_query + t_query_interval, t_query_interval_fine) for t_query_fine in t_queries_fine: time_str = (th.unixstamp2localtime(t_query_fine)).replace(' ', '_') outp_compl_path = outp_folder + '/' + filename_prefix + '%d_%d.csv'%(t_query_fine, t_query_interval_fine) if outp_compl_path in list_retrieved: continue lldb.dbquery(varlist, t_query_fine, t_query_fine+t_query_interval_fine, outp_compl_path) with open(filename_retrieved, 'a+') as fid: fid.write(outp_compl_path + '\n') if not os.path.exists(outp_compl_path): print '!!! WARNING: Could not retrieve data in %s, %d s'%(time_str, t_query_interval_fine)
def plot_trim(self, figure_ax=None, use_cycletime=False): pl.ion() if not figure_ax: fig = pl.figure() figure_ax = pl.subplot2grid((1,1),(0,0)) if self.timestamp_unix: line_label=th.unixstamp2localtime(float(self.timestamp_unix)) if use_cycletime: figure_ax.plot(self.cycletime_vect, self.value_vect, label=line_label) figure_ax.set_xlabel('Cycle time [ms]') else: figure_ax.plot(self.time_vect, self.value_vect, label=line_label) figure_ax.set_xlabel('Time [ms]') figure_ax.set_ylabel('value') pl.draw() return figure_ax
def plot_trims(self, figure_ax=None, use_cycletime=False): pl.ion() if not figure_ax: fig = pl.figure() figure_ax = pl.subplot2grid((1,1),(0,0)) trim_times = self.trim_t_stamps[self.trim_t_stamps>0] for trim_time in trim_times: trim_obj = self.trim_obj_dict[trim_time] line_label = trim_obj.trim_variable+': '+th.unixstamp2localtime(float(trim_obj.timestamp_unix)) if use_cycletime: figure_ax.plot(trim_obj.cycletime_vect, trim_obj.value_vect, label=line_label) figure_ax.set_xlabel('Cycle time [ms]') else: figure_ax.plot(trim_obj.time_vect, trim_obj.value_vect, label=line_label) figure_ax.set_xlabel('Time [ms]') figure_ax.set_ylabel('value') pl.draw() return figure_ax
def plot_trim(self, figure_ax=None, use_cycletime=False): pl.ion() if not figure_ax: fig = pl.figure() figure_ax = pl.subplot2grid((1, 1), (0, 0)) if self.timestamp_unix: line_label = th.unixstamp2localtime(float(self.timestamp_unix)) if use_cycletime: figure_ax.plot(self.cycletime_vect, self.value_vect, label=line_label) figure_ax.set_xlabel('Cycle time [ms]') else: figure_ax.plot(self.time_vect, self.value_vect, label=line_label) figure_ax.set_xlabel('Time [ms]') figure_ax.set_ylabel('value') pl.draw() return figure_ax
def plot_trims(self, figure_ax=None, use_cycletime=False): pl.ion() if not figure_ax: fig = pl.figure() figure_ax = pl.subplot2grid((1, 1), (0, 0)) trim_times = self.trim_t_stamps[self.trim_t_stamps > 0] for trim_time in trim_times: trim_obj = self.trim_obj_dict[trim_time] line_label = trim_obj.trim_variable + ': ' + th.unixstamp2localtime( float(trim_obj.timestamp_unix)) if use_cycletime: figure_ax.plot(trim_obj.cycletime_vect, trim_obj.value_vect, label=line_label) figure_ax.set_xlabel('Cycle time [ms]') else: figure_ax.plot(trim_obj.time_vect, trim_obj.value_vect, label=line_label) figure_ax.set_xlabel('Time [ms]') figure_ax.set_ylabel('value') pl.draw() return figure_ax
def timber_to_csv(start_time, end_time='Now', filename_prefix='SPSmeas_', outp_folder=None, list_device_names=None, t_query_interval=1800., t_query_interval_fine=60., filename_retrieved='ws_retrieved.txt'): try: with open(filename_retrieved, 'r') as fid: list_retrieved = fid.read().split('\n') except IOError: list_retrieved = [] if type(start_time) is str: start_tstamp_unix = th.localtime2unixstamp(start_time) else: start_tstamp_unix = start_time if end_time == 'Now': end_tstamp_unix = time.mktime(time.localtime()) elif type(end_time) is str: end_tstamp_unix = th.localtime2unixstamp(end_time) else: end_tstamp_unix = end_time if outp_folder == None: outp_folder = 'WS_CSVfromTimberDB' if not os.path.exists(outp_folder): os.makedirs(outp_folder) if list_device_names == None: list_device_names = [ 'SPS.BWS.41677.H_ROT', 'SPS.BWS.41677.V_ROT', 'SPS.BWS.51995.H_ROT', 'SPS.BWS.51995.V_ROT' ] varlist = [] for device_name in list_device_names: varlist.extend(get_timber_varlist(device_name)) filename_prefix += device_name.split( '.')[-2] + '.' + device_name.split('.')[-1] + '_' print 'VARLIST', varlist t_queries = np.arange(start_tstamp_unix, end_tstamp_unix, t_query_interval) for t_query in t_queries: outp_compl_path = outp_folder + '/' + filename_prefix + '%d_%d.csv' % ( t_query, t_query_interval) if outp_compl_path in list_retrieved: continue lldb.dbquery(varlist, t_query, t_query + t_query_interval, outp_compl_path) now = th.time.mktime(th.time.localtime()) if now - t_query > 2 * 3600: with open(filename_retrieved, 'a+') as fid: fid.write(outp_compl_path + '\n') # In case something goes wrong with the request -> use a shorter interval. if not os.path.exists(outp_compl_path): t_queries_fine = np.arange(t_query, t_query + t_query_interval, t_query_interval_fine) for t_query_fine in t_queries_fine: time_str = (th.unixstamp2localtime(t_query_fine)).replace( ' ', '_') outp_compl_path = outp_folder + '/' + filename_prefix + '%d_%d.csv' % ( t_query_fine, t_query_interval_fine) if outp_compl_path in list_retrieved: continue lldb.dbquery(varlist, t_query_fine, t_query_fine + t_query_interval_fine, outp_compl_path) with open(filename_retrieved, 'a+') as fid: fid.write(outp_compl_path + '\n') if not os.path.exists(outp_compl_path): print '!!! WARNING: Could not retrieve data in %s, %d s' % ( time_str, t_query_interval_fine)
def print_trim_history(self): for trim_time in self.get_trim_times(): trim_obj = self.trim_obj_dict[trim_time] print(th.unixstamp2localtime(float(trim_obj.timestamp_unix))+': '+trim_obj.trim_variable)
def print_trim_history(self): for trim_time in self.get_trim_times(): trim_obj = self.trim_obj_dict[trim_time] print( th.unixstamp2localtime(float(trim_obj.timestamp_unix)) + ': ' + trim_obj.trim_variable)