Skip to content
Snippets Groups Projects

plot SOH channels in user's order

Merged Lan Dam requested to merge i110_channel_order into master
1 file
+ 14
16
Compare changes
  • Side-by-side
  • Inline
@@ -11,6 +11,8 @@ from sohstationviewer.view.plotting.plotting_widget.plotting_processor import (
from sohstationviewer.view.plotting.plotting_widget.plotting_widget import (
PlottingWidget)
from sohstationviewer.view.util.enums import LogType
from sohstationviewer.view.util.functions import (
replace_actual_question_chans, remove_not_found_chans)
from sohstationviewer.controller.util import display_tracking_info
from sohstationviewer.controller.plotting_data import get_title
@@ -28,7 +30,8 @@ class MultiThreadedPlottingWidget(PlottingWidget):
def __init__(self, *args, **kwargs):
PlottingWidget.__init__(self, *args, **kwargs)
self.data_processors: List[PlottingChannelProcessor] = []
# pref_order: order of channels to be plotted
self.pref_order: List[str] = []
# Only one data processor can run at a time, so it is not a big problem
#
self.thread_pool = QtCore.QThreadPool()
@@ -105,19 +108,33 @@ class MultiThreadedPlottingWidget(PlottingWidget):
return True
def create_plotting_channel_processors(
self, plotting_data: Dict, need_db_info: bool = False) -> None:
self, plotting_data: Dict,
need_db_info: bool = False) -> None:
"""
Create a data processor for each channel data.
Create a data processor for each channel data in the order of
pref_order. If pref_order isn't given, process in order of
plotting_data.
:param plotting_data: dict of data by chan_id
:param need_db_info: flag to get db info
"""
for chan_id in plotting_data:
chan_order = self.pref_order if self.pref_order \
else sorted(list(plotting_data.keys()))
chan_order = replace_actual_question_chans(
chan_order, list(plotting_data.keys()))
chan_order = remove_not_found_chans(
chan_order, list(plotting_data.keys()), self.processing_log)
not_plot_chans = []
for chan_id in chan_order:
if need_db_info:
chan_db_info = get_chan_plot_info(
chan_id, self.parent.data_type, self.c_mode)
if chan_db_info['height'] == 0:
chan_db_info = get_chan_plot_info(chan_id,
self.parent.data_type,
self.c_mode)
if (chan_db_info['height'] == 0 or
chan_db_info['plotType'] == ''):
# not draw
not_plot_chans.append(chan_id)
continue
if 'DEFAULT' in chan_db_info['channel']:
msg = (f"Channel {chan_id}'s "
@@ -127,14 +144,16 @@ class MultiThreadedPlottingWidget(PlottingWidget):
# instruction here
self.processing_log.append((msg, LogType.WARNING))
if chan_db_info['plotType'] == '':
continue
plotting_data[chan_id]['chan_db_info'] = chan_db_info
if not_plot_chans != []:
msg = (f"The database settings 'plotType' or 'height' show not to "
f"be plotted for the following channels: "
f"{', '.join( not_plot_chans)}")
self.processing_log.append((msg, LogType.WARNING))
self.move_soh_channels_with_link_to_the_end()
for chan_id in plotting_data:
for chan_id in chan_order:
if 'chan_db_info' not in plotting_data[chan_id]:
continue
channel_processor = PlottingChannelProcessor(
@@ -165,7 +184,8 @@ class MultiThreadedPlottingWidget(PlottingWidget):
for channel in channels_to_move:
self.plotting_data1[channel] = self.plotting_data1.pop(channel)
def plot_channels(self, d_obj, key, start_tm, end_tm, time_ticks_total):
def plot_channels(self, d_obj, key, start_tm, end_tm, time_ticks_total,
pref_order=[]):
"""
Prepare to plot waveform/SOH/mass-position data by creating a data
processor for each channel, then, run the processors.
@@ -175,12 +195,14 @@ class MultiThreadedPlottingWidget(PlottingWidget):
:param start_tm: requested start time to read
:param end_tm: requested end time to read
:param time_ticks_total: max number of tick to show on time bar
:param pref_order: order of channels to be plotted
"""
self.pref_order = pref_order
if not self.is_working:
self.reset_widget()
self.is_working = True
start_msg = f'Plotting {self.name} data...'
display_tracking_info(self.tracking_box, start_msg, 'info')
display_tracking_info(self.tracking_box, start_msg, LogType.INFO)
ret = self.init_plot(d_obj, key, start_tm, end_tm,
time_ticks_total)
if not ret:
@@ -188,8 +210,10 @@ class MultiThreadedPlottingWidget(PlottingWidget):
self.clean_up()
self.finished.emit()
return
self.create_plotting_channel_processors(self.plotting_data1, True)
self.create_plotting_channel_processors(self.plotting_data2, True)
self.process_channel()
@QtCore.Slot()
@@ -307,7 +331,7 @@ class MultiThreadedPlottingWidget(PlottingWidget):
all running background threads.
"""
display_tracking_info(self.tracking_box,
f'{self.name} plot stopped', 'info')
f'{self.name} plot stopped', LogType.INFO)
self.is_working = False
self.stopped.emit()
@@ -332,7 +356,7 @@ class MultiThreadedPlottingWidget(PlottingWidget):
if not self.is_working:
self.is_working = True
start_msg = 'Zooming in...'
display_tracking_info(self.tracking_box, start_msg, 'info')
display_tracking_info(self.tracking_box, start_msg, LogType.INFO)
self.create_plotting_channel_processors(self.plotting_data1)
self.create_plotting_channel_processors(self.plotting_data2)
self.process_channel()
Loading