Skip to content
Snippets Groups Projects
Commit d9f3687f authored by Lan Dam's avatar Lan Dam
Browse files

fix bug that checking key tps_data that prevent creating processor when replotting tps

parent 1acb14d6
No related branches found
No related tags found
1 merge request!231fix bug checking key tps_data that prevents creating processor when replotting tps
Pipeline #3407 passed with stage
in 5 minutes and 27 seconds
......@@ -14,7 +14,19 @@ class TimePowerSquaredProcessorSignal(QtCore.QObject):
class TimePowerSquaredProcessor(QtCore.QRunnable):
def __init__(self, channel_id: str, channel_data: dict, start_time: float,
end_time: float, start_5mins_of_diff_days: np.ndarray):
end_time: float, start_5mins_of_diff_days: np.ndarray,
tps_data: Optional[Dict]):
"""
:param channel_id: name of channel
:param channel_data: data of channel
:param start_time: start epoch time of data
:param end_time: end epoch time of data
:param start_5mins_of_diff_days: [[288 of floats], ] - the list of
start of all five minutes of days specified by start_tm and end_tm in
which each day has 288 of 5 minutes.
:param tps_data: calculated tps_data from the first plot or None for
the first plot
"""
super().__init__()
self.channel_id = channel_id
self.channel_data = channel_data
......@@ -22,6 +34,7 @@ class TimePowerSquaredProcessor(QtCore.QRunnable):
self.end_time = end_time
self.start_5mins_of_diff_days = start_5mins_of_diff_days
self.signals = TimePowerSquaredProcessorSignal()
self.tps_data = tps_data
# Flag to indicate whether the processor should stop running and clean
# up.
self.stop = False
......@@ -77,8 +90,11 @@ class TimePowerSquaredProcessor(QtCore.QRunnable):
saved in channel_data['tps-data']: np.mean(np.square(5m data))
"""
self.channel_data['tps_data'] = get_tps_for_discontinuous_data(
self.channel_data, self.start_5mins_of_diff_days)
if self.tps_data is None:
self.channel_data['tps_data'] = get_tps_for_discontinuous_data(
self.channel_data, self.start_5mins_of_diff_days)
else:
self.channel_data['tps_data'] = self.tps_data
self.signals.finished.emit(self.channel_id)
......
......@@ -131,15 +131,17 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
for chan_id in self.plotting_data1:
c_data = self.plotting_data1[chan_id]
if 'tps_data' not in c_data:
self.channels.append(chan_id)
channel_processor = TimePowerSquaredProcessor(
chan_id, c_data, self.min_x, self.max_x,
self.start_5mins_of_diff_days
)
channel_processor.signals.finished.connect(self.channel_done)
channel_processor.signals.stopped.connect(self.channel_done)
self.tps_processors.append(channel_processor)
tps_data = None
if 'tps_data' in c_data:
tps_data = c_data['tps_data']
self.channels.append(chan_id)
channel_processor = TimePowerSquaredProcessor(
chan_id, c_data, self.min_x, self.max_x,
self.start_5mins_of_diff_days, tps_data
)
channel_processor.signals.finished.connect(self.channel_done)
channel_processor.signals.stopped.connect(self.channel_done)
self.tps_processors.append(channel_processor)
# Because the widget determine if processing is done by comparing the
# lists of scheduled and finished channels, if a channel runs fast
......@@ -183,7 +185,6 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
Add finishing touches to the plot
Emit the stopped signal of the widget
"""
if chan_id == '':
msg = f'{self.get_plot_name()} stopped.'
else:
......@@ -192,6 +193,7 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.done()
display_tracking_info(self.tracking_box, msg)
self.is_working = False
self.stopped.emit()
def done(self):
......@@ -202,7 +204,6 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.main_widget.setFixedHeight(self.plotting_bot_pixel)
self.set_lim_markers()
self.draw()
self.is_working = False
def plot_channel(self, c_data: str, chan_id: str) -> Axes:
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment