From ae0c2ef4e9de5464767def02a40b3151cc616d60 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 22 Nov 2022 18:06:25 +0100 Subject: [PATCH] [minor] track activity status, modify html output for stylesheet --- parameters.yaml | 2 +- survBot.py | 22 ++++++++++++++-------- write_utils.py | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/parameters.yaml b/parameters.yaml index af1f767..79234ca 100644 --- a/parameters.yaml +++ b/parameters.yaml @@ -8,7 +8,7 @@ channel_names: ["Temperature (°)", "Voltage (V)", "Voltage (V)", "Voltage (V)"] stations_blacklist: ["TEST", "EREA"] networks_blacklist: [] interval: 60 # Perform checks every x seconds -n_track: 120 # wait number of intervals after FAIL before performing an action (i.e. send mail) +n_track: 120 # wait n FAIL intervals before performing an action (i.e. send mail + end highlight status) timespan: 3 # Check data of the recent x days verbosity: 0 track_changes: True # tracks all changes since GUI startup by text highlighting (GUI only) diff --git a/survBot.py b/survBot.py index 96835d6..a55ec36 100755 --- a/survBot.py +++ b/survBot.py @@ -352,7 +352,7 @@ class SurveillanceBot(object): fig.savefig(fnout, dpi=150., bbox_inches='tight') plt.close(fig) - def write_html_table(self, default_color='#e6e6e6'): + def write_html_table(self, default_color='#e6e6e6', default_header_color='#999'): self.check_html_dir() fnout = pjoin(self.outpath_html, 'survBot_out.html') if not fnout: @@ -368,16 +368,17 @@ class SurveillanceBot(object): # add columns for additional links for key in self.add_links: header.insert(-1, key) - header_items = [dict(text='Station', color=default_color)] + header_items = [dict(text='Station', color=default_header_color)] for check_key in header: - item = dict(text=check_key, color=default_color) + item = dict(text=check_key, color=default_header_color) header_items.append(item) write_html_row(outfile, header_items, html_key='th') # Write all cells for nwst_id in self.station_list: fig_name = self.get_fig_path_rel(nwst_id) - col_items = [dict(text=nwst_id.rstrip('.'), color=default_color, hyperlink=fig_name)] + col_items = [dict(text=nwst_id.rstrip('.'), color=default_color, hyperlink=fig_name, + bold=True)] for check_key in header: if check_key in self.keys: status_dict = self.analysis_results.get(nwst_id) @@ -395,7 +396,8 @@ class SurveillanceBot(object): if not type(message) in [str]: message = str(message) + deg_str - item = dict(text=str(message), tooltip=str(detailed_message), color=bg_color) + item = dict(text=str(message), tooltip=str(detailed_message), color=bg_color, + blink=status.is_active) elif check_key in self.add_links: value = self.add_links.get(check_key).get('URL') link_text = self.add_links.get(check_key).get('text') @@ -517,18 +519,21 @@ class StationQC(object): current_status.count += count else: current_status = new_error - # refresh plot (using parent class) if error is new and not on program-startup + # if error is new and not on program-startup set active and refresh plot (using parent class) if self.search_previous_errors(key, n_errors=1): + current_status.is_active = True self.parent.write_html_figure(self.nwst_id) - self._update_status(key, current_status, detailed_message, last_occurrence) - if self.verbosity: self.print(f'{UTCDateTime()}: {detailed_message}', flush=False) # do not send error mail if this is the first run (e.g. program startup) or state was already error (unchanged) if self.search_previous_errors(key): self.send_mail(key, detailed_message) + # set status to "inactive" after sending info mail + current_status.is_active = False + + self._update_status(key, current_status, detailed_message, last_occurrence) def search_previous_errors(self, key, n_errors=None): """ @@ -908,6 +913,7 @@ class Status(object): self.is_warn = None self.is_error = None self.is_other = False + self.is_active = False def set_warn(self): self.is_warn = True diff --git a/write_utils.py b/write_utils.py index 14a8b1c..9126835 100644 --- a/write_utils.py +++ b/write_utils.py @@ -1,12 +1,15 @@ from datetime import timedelta + def write_html_table_title(fobj, parameters): title = get_print_title_str(parameters) fobj.write(f'

{title}

\n') + def write_html_text(fobj, text): fobj.write(f'

{text}

\n') + def write_html_header(fobj, refresh_rate=10): header = ['', '', @@ -24,35 +27,44 @@ def write_html_header(fobj, refresh_rate=10): for item in header: fobj.write(item + '\n') + def init_html_table(fobj): fobj.write('\n') + def finish_html_table(fobj): fobj.write('
\n') + def write_html_footer(fobj): footer = ['', ''] for item in footer: fobj.write(item + '\n') + def write_html_row(fobj, items, html_key='td'): default_space = ' ' fobj.write(default_space + '\n') for item in items: text = item.get('text') + if item.get('bold'): + text = '' + text + '' + if item.get('italic'): + text = '' + text + '' tooltip = item.get('tooltip') color = item.get('color') # check for black background of headers (shouldnt happen anymore) color = '#e6e6e6' if color == '#000000' else color hyperlink = item.get('hyperlink') image_str = f'' if hyperlink else '' - fobj.write(2 * default_space + f'<{html_key} bgcolor="{color}" title="{tooltip}"> {image_str}' + blink_str = f' class="blink-bg"' if item.get('blink') else '' + fobj.write(2 * default_space + f'<{html_key}{blink_str} bgcolor="{color}" title="{tooltip}"> {image_str}' + text + f'\n') fobj.write(default_space + '\n') + def get_print_title_str(parameters): timespan = parameters.get('timespan') * 24 * 3600 tdelta_str = str(timedelta(seconds=int(timespan))).replace(', 0:00:00', '') return f'Analysis table of router quality within the last {tdelta_str}' -