From 68c6df72c92a30633be71a2154a1b850a9a39c8c Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 8 Nov 2022 12:06:00 +0100 Subject: [PATCH] [update] html output from GUI in background possible but maybe not optimal (needs display to work in bg) --- parameters.yaml | 1 - submit_bot.sh | 13 +++++++++---- survBot.py | 5 +++-- survBotGUI.py | 24 ++++++++++++++++++------ write_utils.py | 22 +++++++++++++--------- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/parameters.yaml b/parameters.yaml index ea7d8ad..a206927 100644 --- a/parameters.yaml +++ b/parameters.yaml @@ -1,6 +1,5 @@ # Parameters file for Surveillance Bot datapath: '/data/SDS/' # SC3 Datapath -outpath_html: '/home/marcel/tmp/survBot_out.html' # output of HTML table networks: ['1Y', 'HA'] stations: '*' locations: '*' diff --git a/submit_bot.sh b/submit_bot.sh index ec6fdcf..4f1a918 100644 --- a/submit_bot.sh +++ b/submit_bot.sh @@ -2,15 +2,20 @@ ulimit -s 8192 #$ -l low -#$ -l os=*stretch +#$ -l h_vmem=5G #$ -cwd #$ -pe smp 1 -##$ -q "*@minos15" +#$ -N survBot_bg -export PYTHONPATH="$PYTHONPATH:/home/marcel/git/" export PYTHONPATH="$PYTHONPATH:/home/marcel/git/code_base/" source /opt/anaconda3/etc/profile.d/conda.sh conda activate py37 -python survBot.py +# environment variables for numpy to prevent multi threading +export MKL_NUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 +export OMP_NUM_THREADS=1 + + +python survBotGUI.py -html '/home/marcel/public_html/survBot_out.html' --background diff --git a/survBot.py b/survBot.py index 7c0f75e..4cee2d5 100755 --- a/survBot.py +++ b/survBot.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#!/usr/bin/env python +# -*- coding: utf-8 -*- __version__ = '0.1' __author__ = 'Marcel Paffrath' @@ -510,7 +511,7 @@ class StationQC(object): self.warn(key=key, message=f'Trace {trace.get_id()}: ' f'Voltage below {pb_ok}V {len(under)} times. ' - f'Mean voltage: {np.mean(voltage)}' + f'Mean voltage: {np.mean(voltage):.2}' + self.get_last_occurrence_timestring(trace, under), status_message='WARN ({})'.format(n_occurrences)) diff --git a/survBotGUI.py b/survBotGUI.py index f34f354..9f645dd 100755 --- a/survBotGUI.py +++ b/survBotGUI.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#!/usr/bin/env python +# -*- coding: utf-8 -*- """ GUI overlay for the main survBot to show quality control of different stations specified in parameters.yaml file. """ @@ -77,7 +78,7 @@ class Thread(QtCore.QThread): class MainWindow(QtWidgets.QMainWindow): - def __init__(self, parameters='parameters.yaml', dt_thresh=(300, 1800)): + def __init__(self, parameters='parameters.yaml', outpath_html=None, dt_thresh=(300, 1800)): """ Main window of survBot GUI. :param parameters: Parameters dictionary file (yaml format) @@ -98,6 +99,7 @@ class MainWindow(QtWidgets.QMainWindow): self.last_mouse_loc = None self.status_message = '' self.starttime = UTCDateTime() + self.outpath_html = outpath_html # setup main layout of the GUI self.main_layout = QtWidgets.QVBoxLayout() @@ -184,12 +186,12 @@ class MainWindow(QtWidgets.QMainWindow): return super(QtWidgets.QMainWindow, self).eventFilter(object, event) def write_html_table(self): - fnout = self.parameters.get('outpath_html') + fnout = self.outpath_html if not fnout: return try: with open(fnout, 'w') as outfile: - write_html_header(outfile) + write_html_header(outfile, self.refresh_period) #write_html_table_title(outfile, self.parameters) init_html_table(outfile) nrows = self.table.rowCount() @@ -272,6 +274,10 @@ class MainWindow(QtWidgets.QMainWindow): def fill_table(self): """ Fills the table with most recent information. Executed after execute_qc thread is done or on refresh. """ + + # fill status bar first with new time + self.fill_status_bar() + for col_ind, check_key in enumerate(self.survBot.keys): for row_ind, st_id in enumerate(self.survBot.station_list): status_dict, detailed_dict = self.survBot.analysis_results.get(st_id) @@ -501,9 +507,15 @@ class SendSMSWidget(QtWidgets.QDialog): if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Call survBot GUI') + parser.add_argument('-html', dest='html_filename', default=None, help='filename for HTML output') + parser.add_argument('--background', dest='background', default=False, action='store_true', help='run in background') + args = parser.parse_args() + program_path = sys.path[0] parameters = os.path.join(program_path, 'parameters.yaml') app = QtWidgets.QApplication([]) - window = MainWindow(parameters=parameters) - window.showMaximized() + window = MainWindow(parameters=parameters, outpath_html=args.html_filename) + if not args.background: + window.showMaximized() sys.exit(app.exec_()) diff --git a/write_utils.py b/write_utils.py index 7de05d2..51af04e 100644 --- a/write_utils.py +++ b/write_utils.py @@ -7,15 +7,17 @@ def write_html_table_title(fobj, parameters): def write_html_text(fobj, text): fobj.write(f'

{text}

\n') -def write_html_header(fobj): +def write_html_header(fobj, refresh_rate=10): header = ['', '', - '', + f'', + '', ''] + # style = ['',] for item in header: fobj.write(item + '\n') @@ -32,14 +34,16 @@ def write_html_footer(fobj): fobj.write(item + '\n') def write_html_row(fobj, items, html_key='td'): - fobj.write('\n') + default_space = ' ' + fobj.write(default_space + '\n') for item in items: text = item.text() + tooltip = item.toolTip() color = item.backgroundColor().name() # fix for black background of headers color = '#e6e6e6' if color == '#000000' else color - fobj.write(f'<{html_key} bgcolor="{color}">' + text + f'\n') - fobj.write('\n') + fobj.write(2 * default_space + f'<{html_key} bgcolor="{color}" title="{tooltip}">' + text + f'\n') + fobj.write(default_space + '\n') def get_print_title_str(parameters): timespan = parameters.get('timespan') * 24 * 3600