def _add_unselected_channels(self, channels, source_ref): ProgressSpinner.increment_refcount() def get_results(results): # Auto-switch to time mode in charts only if the user # did not request it. if ( self.line_chart_mode == LineChartMode.DISTANCE and not self._results_has_distance(results) ): if self._user_refresh_requested == True: toast("Warning: one or more selected laps have missing distance data", length_long=True) self._user_refresh_requested = False else: self.line_chart_mode = LineChartMode.TIME self._refresh_chart_mode_toggle() # clone the incoming list of channels and pass it to the handler if self.line_chart_mode == LineChartMode.TIME: Clock.schedule_once(lambda dt: self._add_channels_results_time(channels[:], results)) elif self.line_chart_mode == LineChartMode.DISTANCE: Clock.schedule_once(lambda dt: self._add_channels_results_distance(channels[:], results)) else: Logger.error('LineChart: Unknown line chart mode ' + str(self.line_chart_mode)) try: self.datastore.get_channel_data(source_ref, ['Interval', 'Distance'] + channels, get_results) except Exception as e: Logger.warn('Non existant channel selected, not loading channels {}; {}'.format(channels, e)) finally: ProgressSpinner.decrement_refcount()
def _add_channels_results_time(self, channels, query_data): try: time_data_values = query_data['Interval'] for channel in channels: chart = self.ids.chart channel_data_values = query_data[channel] channel_data = channel_data_values.values # If we queried a channel that has no sample results, skip adding the plot if len(channel_data) == 0 or channel_data[0] is None: continue key = channel_data_values.channel + str( channel_data_values.source) plot = SmoothLinePlot(color=self.color_sequence.get_color(key)) channel_plot = ChannelPlot(plot, channel_data_values.channel, channel_data_values.min, channel_data_values.max, channel_data_values.source) chart.add_plot(plot) points = [] time_index = OrderedDict() sample_index = 0 time_data = time_data_values.values sample_count = len(time_data) interval = max(1, int(sample_count / self.MAX_SAMPLES_TO_DISPLAY)) Logger.info('LineChart: plot interval {}'.format(interval)) last_time = None time = 0 last_time = time_data[0] while sample_index < sample_count: current_time = time_data[sample_index] if last_time > current_time: Logger.warn( 'LineChart: interruption in interval channel, possible reset in data stream ({}->{})' .format(last_time, current_time)) last_time = current_time sample = channel_data[sample_index] time += current_time - last_time last_time = current_time points.append((time, sample)) time_index[time] = sample_index sample_index += interval channel_plot.chart_x_index = time_index plot.ymin = channel_data_values.min plot.ymax = channel_data_values.max plot.points = points self._channel_plots[str(channel_plot)] = channel_plot # sync max chart x dimension self._update_max_chart_x() self._update_x_marker_value() finally: ProgressSpinner.decrement_refcount()
def add_channels(self, channels, source_ref): ProgressSpinner.increment_refcount() def get_results(results): #clone the incoming list of channels and pass it to the handler Clock.schedule_once( lambda dt: self._add_channels_results(channels[:], results)) self.datastore.get_channel_data(source_ref, ['Distance'] + channels, get_results)
def _add_channels_results_time(self, channels, query_data): try: time_data_values = query_data['Interval'] for channel in channels: chart = self.ids.chart channel_data_values = query_data[channel] channel_data = channel_data_values.values # If we queried a channel that has no sample results, skip adding the plot if len(channel_data) == 0 or channel_data[0] is None: continue key = channel_data_values.channel + str(channel_data_values.source) plot = SmoothLinePlot(color=self.color_sequence.get_color(key)) channel_plot = ChannelPlot(plot, channel_data_values.channel, channel_data_values.min, channel_data_values.max, channel_data_values.source) chart.add_plot(plot) points = [] time_index = OrderedDict() sample_index = 0 time_data = time_data_values.values sample_count = len(time_data) interval = max(1, int(sample_count / self.MAX_SAMPLES_TO_DISPLAY)) Logger.info('LineChart: plot interval {}'.format(interval)) last_time = None time = 0 last_time = time_data[0] while sample_index < sample_count: current_time = time_data[sample_index] if last_time > current_time: Logger.warn('LineChart: interruption in interval channel, possible reset in data stream ({}->{})'.format(last_time, current_time)) last_time = current_time sample = channel_data[sample_index] time += current_time - last_time last_time = current_time points.append((time, sample)) time_index[time] = sample_index sample_index += interval channel_plot.chart_x_index = time_index plot.ymin = channel_data_values.min plot.ymax = channel_data_values.max plot.points = points self._channel_plots[str(channel_plot)] = channel_plot # sync max chart x dimension self._update_max_chart_x() self._update_x_marker_value() finally: ProgressSpinner.decrement_refcount()
def _add_channels_results_distance(self, channels, query_data): try: distance_data_values = query_data['Distance'] for channel in channels: chart = self.ids.chart channel_data_values = query_data[channel] key = channel_data_values.channel + str( channel_data_values.source) plot = SmoothLinePlot(color=self.color_sequence.get_color(key)) channel_plot = ChannelPlot(plot, channel_data_values.channel, channel_data_values.min, channel_data_values.max, channel_data_values.source) chart.add_plot(plot) points = [] distance_index = OrderedDict() sample_index = 0 distance_data = distance_data_values.values channel_data = channel_data_values.values sample_count = len(distance_data) interval = max(1, int(sample_count / self.MAX_SAMPLES_TO_DISPLAY)) Logger.info('LineChart: plot interval {}'.format(interval)) while sample_index < sample_count: sample = channel_data[sample_index] distance = distance_data[sample_index] points.append((distance, sample)) distance_index[distance] = sample_index sample_index += interval channel_plot.chart_x_index = distance_index plot.ymin = channel_data_values.min plot.ymax = channel_data_values.max plot.points = points self._channel_plots[str(channel_plot)] = channel_plot # sync max chart distances self._update_max_chart_x() self._update_x_marker_value() finally: ProgressSpinner.decrement_refcount()
def _add_channels_results_distance(self, channels, query_data): try: distance_data_values = query_data['Distance'] for channel in channels: chart = self.ids.chart channel_data_values = query_data[channel] key = channel_data_values.channel + str(channel_data_values.source) plot = SmoothLinePlot(color=self.color_sequence.get_color(key)) channel_plot = ChannelPlot(plot, channel_data_values.channel, channel_data_values.min, channel_data_values.max, channel_data_values.source) chart.add_plot(plot) points = [] distance_index = OrderedDict() sample_index = 0 distance_data = distance_data_values.values channel_data = channel_data_values.values sample_count = len(distance_data) interval = max(1, int(sample_count / self.MAX_SAMPLES_TO_DISPLAY)) Logger.info('LineChart: plot interval {}'.format(interval)) while sample_index < sample_count: sample = channel_data[sample_index] distance = distance_data[sample_index] points.append((distance, sample)) distance_index[distance] = sample_index sample_index += interval channel_plot.chart_x_index = distance_index plot.ymin = channel_data_values.min plot.ymax = channel_data_values.max plot.points = points self._channel_plots[str(channel_plot)] = channel_plot # sync max chart distances self._update_max_chart_x() self._update_x_marker_value() finally: ProgressSpinner.decrement_refcount()
def _add_unselected_channels(self, channels, source_ref): ProgressSpinner.increment_refcount() def get_results(results): # Auto-switch to time mode in charts only if the user # did not request it. if (self.line_chart_mode == LineChartMode.DISTANCE and not self._results_has_distance(results)): if self._user_refresh_requested == True: toast( "Warning: one or more selected laps have missing distance data", length_long=True) self._user_refresh_requested = False else: self.line_chart_mode = LineChartMode.TIME self._refresh_chart_mode_toggle() # clone the incoming list of channels and pass it to the handler if self.line_chart_mode == LineChartMode.TIME: Clock.schedule_once(lambda dt: self._add_channels_results_time( channels[:], results)) elif self.line_chart_mode == LineChartMode.DISTANCE: Clock.schedule_once( lambda dt: self._add_channels_results_distance( channels[:], results)) else: Logger.error('LineChart: Unknown line chart mode ' + str(self.line_chart_mode)) try: self.datastore.get_channel_data( source_ref, ['Interval', 'Distance'] + channels, get_results) except Exception as e: alertPopup( 'Could not load lap', "There was a problem loading the lap due to missing data:\r\n\r\n{}" .format(e)) raise # allow CrashHandler to record the issue finally: ProgressSpinner.decrement_refcount()
def _add_channels_results(self, channels, query_data): try: distance_data_values = query_data['Distance'] for channel in channels: chart = self.ids.chart channel_data_values = query_data[channel] key = channel_data_values.channel + str(channel_data_values.source) plot = SmoothLinePlot(color=self.color_sequence.get_color(key)) channel_plot = ChannelPlot(plot, channel_data_values.channel, channel_data_values.min, channel_data_values.max, channel_data_values.source) chart.add_plot(plot) points = [] distance_index = OrderedDict() sample_index = 0 distance_data = distance_data_values.values channel_data = channel_data_values.values for sample in channel_data: distance = distance_data[sample_index] points.append((distance, sample)) distance_index[distance] = sample_index sample_index += 1 channel_plot.distance_index = distance_index channel_plot.samples = sample_index plot.ymin = channel_data_values.min plot.ymax = channel_data_values.max plot.points = points self._channel_plots[str(channel_plot)] = channel_plot #sync max chart distances self._update_max_distance() finally: ProgressSpinner.decrement_refcount()
def _add_channels_results(self, channels, query_data): try: distance_data_values = query_data['Distance'] for channel in channels: chart = self.ids.chart channel_data_values = query_data[channel] key = channel_data_values.channel + str( channel_data_values.source) plot = SmoothLinePlot(color=self.color_sequence.get_color(key)) channel_plot = ChannelPlot(plot, channel_data_values.channel, channel_data_values.min, channel_data_values.max, channel_data_values.source) chart.add_plot(plot) points = [] distance_index = OrderedDict() sample_index = 0 distance_data = distance_data_values.values channel_data = channel_data_values.values for sample in channel_data: distance = distance_data[sample_index] points.append((distance, sample)) distance_index[distance] = sample_index sample_index += 1 channel_plot.distance_index = distance_index channel_plot.samples = sample_index plot.ymin = channel_data_values.min plot.ymax = channel_data_values.max plot.points = points self._channel_plots[str(channel_plot)] = channel_plot #sync max chart distances self._update_max_distance() finally: ProgressSpinner.decrement_refcount()
def add_channels(self, channels, source_ref): ProgressSpinner.increment_refcount() def get_results(results): #clone the incoming list of channels and pass it to the handler Clock.schedule_once(lambda dt: self._add_channels_results(channels[:], results)) self.datastore.get_channel_data(source_ref, ['Distance'] + channels, get_results)