[update] html output from GUI in background possible but maybe not optimal (needs display to work in bg)

This commit is contained in:
Marcel Paffrath 2022-11-08 12:06:00 +01:00
parent 37b73d4393
commit 68c6df72c9
5 changed files with 43 additions and 22 deletions

View File

@ -1,6 +1,5 @@
# Parameters file for Surveillance Bot # Parameters file for Surveillance Bot
datapath: '/data/SDS/' # SC3 Datapath datapath: '/data/SDS/' # SC3 Datapath
outpath_html: '/home/marcel/tmp/survBot_out.html' # output of HTML table
networks: ['1Y', 'HA'] networks: ['1Y', 'HA']
stations: '*' stations: '*'
locations: '*' locations: '*'

View File

@ -2,15 +2,20 @@
ulimit -s 8192 ulimit -s 8192
#$ -l low #$ -l low
#$ -l os=*stretch #$ -l h_vmem=5G
#$ -cwd #$ -cwd
#$ -pe smp 1 #$ -pe smp 1
##$ -q "*@minos15" #$ -N survBot_bg
export PYTHONPATH="$PYTHONPATH:/home/marcel/git/"
export PYTHONPATH="$PYTHONPATH:/home/marcel/git/code_base/" export PYTHONPATH="$PYTHONPATH:/home/marcel/git/code_base/"
source /opt/anaconda3/etc/profile.d/conda.sh source /opt/anaconda3/etc/profile.d/conda.sh
conda activate py37 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

View File

@ -1,4 +1,5 @@
#! /usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*-
__version__ = '0.1' __version__ = '0.1'
__author__ = 'Marcel Paffrath' __author__ = 'Marcel Paffrath'
@ -510,7 +511,7 @@ class StationQC(object):
self.warn(key=key, self.warn(key=key,
message=f'Trace {trace.get_id()}: ' message=f'Trace {trace.get_id()}: '
f'Voltage below {pb_ok}V {len(under)} times. ' 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), + self.get_last_occurrence_timestring(trace, under),
status_message='WARN ({})'.format(n_occurrences)) status_message='WARN ({})'.format(n_occurrences))

View File

@ -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. 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): 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. Main window of survBot GUI.
:param parameters: Parameters dictionary file (yaml format) :param parameters: Parameters dictionary file (yaml format)
@ -98,6 +99,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.last_mouse_loc = None self.last_mouse_loc = None
self.status_message = '' self.status_message = ''
self.starttime = UTCDateTime() self.starttime = UTCDateTime()
self.outpath_html = outpath_html
# setup main layout of the GUI # setup main layout of the GUI
self.main_layout = QtWidgets.QVBoxLayout() self.main_layout = QtWidgets.QVBoxLayout()
@ -184,12 +186,12 @@ class MainWindow(QtWidgets.QMainWindow):
return super(QtWidgets.QMainWindow, self).eventFilter(object, event) return super(QtWidgets.QMainWindow, self).eventFilter(object, event)
def write_html_table(self): def write_html_table(self):
fnout = self.parameters.get('outpath_html') fnout = self.outpath_html
if not fnout: if not fnout:
return return
try: try:
with open(fnout, 'w') as outfile: with open(fnout, 'w') as outfile:
write_html_header(outfile) write_html_header(outfile, self.refresh_period)
#write_html_table_title(outfile, self.parameters) #write_html_table_title(outfile, self.parameters)
init_html_table(outfile) init_html_table(outfile)
nrows = self.table.rowCount() nrows = self.table.rowCount()
@ -272,6 +274,10 @@ class MainWindow(QtWidgets.QMainWindow):
def fill_table(self): def fill_table(self):
""" Fills the table with most recent information. Executed after execute_qc thread is done or on refresh. """ """ 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 col_ind, check_key in enumerate(self.survBot.keys):
for row_ind, st_id in enumerate(self.survBot.station_list): for row_ind, st_id in enumerate(self.survBot.station_list):
status_dict, detailed_dict = self.survBot.analysis_results.get(st_id) status_dict, detailed_dict = self.survBot.analysis_results.get(st_id)
@ -501,9 +507,15 @@ class SendSMSWidget(QtWidgets.QDialog):
if __name__ == '__main__': 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] program_path = sys.path[0]
parameters = os.path.join(program_path, 'parameters.yaml') parameters = os.path.join(program_path, 'parameters.yaml')
app = QtWidgets.QApplication([]) app = QtWidgets.QApplication([])
window = MainWindow(parameters=parameters) window = MainWindow(parameters=parameters, outpath_html=args.html_filename)
window.showMaximized() if not args.background:
window.showMaximized()
sys.exit(app.exec_()) sys.exit(app.exec_())

View File

@ -7,15 +7,17 @@ def write_html_table_title(fobj, parameters):
def write_html_text(fobj, text): def write_html_text(fobj, text):
fobj.write(f'<p>{text}</p>\n') fobj.write(f'<p>{text}</p>\n')
def write_html_header(fobj): def write_html_header(fobj, refresh_rate=10):
header = ['<!DOCTYPE html>', header = ['<!DOCTYPE html>',
'<html>', '<html>',
'<style>', f'<meta http-equiv="refresh" content="{refresh_rate}" >',
'table, th, td {', '<meta charset="utf-8">',
'border:1px solid black;',
'}',
'</style>',
'<body>'] '<body>']
# style = ['<style>',
# 'table, th, td {',
# 'border:1px solid black;',
# '}',
# '</style>',]
for item in header: for item in header:
fobj.write(item + '\n') fobj.write(item + '\n')
@ -32,14 +34,16 @@ def write_html_footer(fobj):
fobj.write(item + '\n') fobj.write(item + '\n')
def write_html_row(fobj, items, html_key='td'): def write_html_row(fobj, items, html_key='td'):
fobj.write('<tr>\n') default_space = ' '
fobj.write(default_space + '<tr>\n')
for item in items: for item in items:
text = item.text() text = item.text()
tooltip = item.toolTip()
color = item.backgroundColor().name() color = item.backgroundColor().name()
# fix for black background of headers # fix for black background of headers
color = '#e6e6e6' if color == '#000000' else color color = '#e6e6e6' if color == '#000000' else color
fobj.write(f'<{html_key} bgcolor="{color}">' + text + f'</{html_key}>\n') fobj.write(2 * default_space + f'<{html_key} bgcolor="{color}" title="{tooltip}">' + text + f'</{html_key}>\n')
fobj.write('</tr>\n') fobj.write(default_space + '</tr>\n')
def get_print_title_str(parameters): def get_print_title_str(parameters):
timespan = parameters.get('timespan') * 24 * 3600 timespan = parameters.get('timespan') * 24 * 3600