Compare commits

...

4 Commits

5 changed files with 67 additions and 15 deletions

View File

@ -1,17 +1,17 @@
# Parameters file for Surveillance Bot # Parameters file for Surveillance Bot
datapath: "/data/SDS/" # SC3 Datapath datapath: "/data/SDS/" # SC3 Datapath
networks: ["1Y", "HA"] # select networks, list or str networks: ["1Y", "HA", "MK"] # select networks, list or str
stations: "*" # select stations, list or str stations: "*" # select stations, list or str
locations: "*" # select locations, list or str locations: "*" # select locations, list or str
stations_blacklist: ["TEST", "EREA"] # exclude these stations stations_blacklist: ["TEST", "EREA", "DOMV"] # exclude these stations
networks_blacklist: [] # exclude these networks networks_blacklist: [] # exclude these networks
interval: 60 # Perform checks every x seconds interval: 60 # Perform checks every x seconds
n_track: 300 # wait n_track * intervals before performing an action (i.e. send mail/end highlight status) n_track: 360 # wait n_track * intervals before performing an action (i.e. send mail/end highlight status)
timespan: 3 # Check data of the recent x days timespan: 3 # Check data of the recent x days
verbosity: 0 # verbosity flag verbosity: 0 # verbosity flag
track_changes: True # tracks all changes since GUI startup by text highlighting (GUI only) track_changes: True # tracks all changes since GUI startup by text highlighting (GUI only)
warn_count: False # show number of warnings and errors in table warn_count: False # show number of warnings and errors in table
min_sample: 3 # minimum samples for raising Warn/FAIL min_sample: 5 # minimum samples for raising Warn/FAIL
dt_thresh: [300, 1800] # threshold (s) for timing delay colourisation (yellow/red) dt_thresh: [300, 1800] # threshold (s) for timing delay colourisation (yellow/red)
html_figures: True # Create html figure directory and links html_figures: True # Create html figure directory and links
reread_parameters: True # reread parameters file (change parameters on runtime, not for itself/GUI refresh/datapath) reread_parameters: True # reread parameters file (change parameters on runtime, not for itself/GUI refresh/datapath)
@ -72,12 +72,12 @@ CHANNELS:
EX2: EX2:
unit: 1e-6 unit: 1e-6
name: "PowBox 230V/12V (V)" name: "PowBox 230V/12V (V)"
ticks: [1, 5, 1] ticks: [0, 5, 1]
warn: [2, 3, 4, 4.5, 5] warn: [2, 3, 4, 4.5, 5]
EX3: EX3:
unit: 1e-6 unit: 1e-6
name: "PowBox Router/Charger (V)" name: "PowBox Router/Charger (V)"
ticks: [1, 5, 1] ticks: [0, 5, 1]
warn: [2, 2.5, 3, 4, 5] warn: [2, 2.5, 3, 4, 5]
VEI: VEI:
unit: 1e-3 unit: 1e-3
@ -122,6 +122,15 @@ add_links:
slmon: {"URL": "../slmon/{nw}_{st}.html", "text": "show"} slmon: {"URL": "../slmon/{nw}_{st}.html", "text": "show"}
24h-plot: {"URL": "../scheli/{nw}/{st}.png", "text": "plot"} 24h-plot: {"URL": "../scheli/{nw}/{st}.png", "text": "plot"}
# add station-independent links below html table (list items separated with -)
add_global_links:
# for example: - {"text": "our homepage", "URL": "https://www.rub.de"}
- {"text": "show recent events on map",
"URL": "https://fdsnws.geophysik.ruhr-uni-bochum.de/map/?lat=39.5&lon=21&zoom=7&baselayer=mapnik"}
# html logo at page bottom
html_logo: "figures/Logo_RUB_BLAU_rgb.png"
# E-mail notifications # E-mail notifications
EMAIL: EMAIL:
mailserver: "localhost" mailserver: "localhost"

View File

@ -2,11 +2,13 @@ body {
background-color: #ffffff; background-color: #ffffff;
place-items: center; place-items: center;
text-align: center; text-align: center;
padding-bottom: 30px;
} }
td { td {
border-radius: 4px; border-radius: 4px;
padding: 0px; padding: 0px;
white-space: nowrap;
} }
th { th {
@ -37,3 +39,12 @@ a:hover {
50% { background-color: #ff3200;} 50% { background-color: #ff3200;}
100% { background-color: #ffcc00;} 100% { background-color: #ffcc00;}
} }
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}

View File

@ -2,11 +2,13 @@ body {
background-color: #ffffff; background-color: #ffffff;
place-items: center; place-items: center;
text-align: center; text-align: center;
padding-bottom: 30px;
} }
td { td {
border-radius: 4px; border-radius: 4px;
padding: 10px 2px; padding: 10px 2px;
white-space: nowrap;
} }
th { th {
@ -41,3 +43,12 @@ a:hover {
50% { background-color: #ff3200;} 50% { background-color: #ff3200;}
100% { background-color: #ffee00;} 100% { background-color: #ffee00;}
} }
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}

View File

@ -20,7 +20,7 @@ import matplotlib.pyplot as plt
from obspy import read, UTCDateTime, Stream from obspy import read, UTCDateTime, Stream
from obspy.clients.filesystem.sds import Client from obspy.clients.filesystem.sds import Client
from write_utils import get_html_text, get_html_row, html_footer, get_html_header, get_print_title_str, \ from write_utils import get_html_text, get_html_link, get_html_row, html_footer, get_html_header, get_print_title_str, \
init_html_table, finish_html_table, get_mail_html_header, add_html_image init_html_table, finish_html_table, get_mail_html_header, add_html_image
from utils import get_bg_color, modify_stream_for_plot, set_axis_yticks, set_axis_color, plot_axis_thresholds from utils import get_bg_color, modify_stream_for_plot, set_axis_yticks, set_axis_color, plot_axis_thresholds
@ -120,9 +120,16 @@ class SurveillanceBot(object):
self.networks_blacklist = self.parameters.get('networks_blacklist') self.networks_blacklist = self.parameters.get('networks_blacklist')
self.refresh_period = self.parameters.get('interval') self.refresh_period = self.parameters.get('interval')
self.transform_parameters() self.transform_parameters()
add_links = self.parameters.get('add_links') add_links = self.parameters.get('add_links')
self.add_links = add_links if add_links else {} self.add_links = add_links if add_links else {}
add_global_links = self.parameters.get('add_global_links')
# in case user forgets "-" in parameters file
if isinstance(add_global_links, dict):
add_global_links = [add_global_links]
self.add_global_links = add_global_links if add_global_links else []
def transform_parameters(self): def transform_parameters(self):
for key in ['networks', 'stations', 'locations', 'channels']: for key in ['networks', 'stations', 'locations', 'channels']:
parameter = self.parameters.get(key) parameter = self.parameters.get(key)
@ -496,8 +503,12 @@ class SurveillanceBot(object):
outfile.write(finish_html_table()) outfile.write(finish_html_table())
for dct in self.add_global_links:
link_str = get_html_link(dct.get('text'), dct.get('URL'))
outfile.write(get_html_text(link_str))
outfile.write(get_html_text(self.status_message)) outfile.write(get_html_text(self.status_message))
outfile.write(html_footer()) outfile.write(html_footer(footer_logo=self.parameters.get('html_logo')))
except Exception as e: except Exception as e:
print(f'Could not write HTML table to {fnout}:') print(f'Could not write HTML table to {fnout}:')

View File

@ -47,9 +47,15 @@ def finish_html_table():
return '</table>\n' return '</table>\n'
def html_footer(): def html_footer(footer_logo=None):
footer = ['</body>', footer = ['</body>']
'</html>'] if footer_logo:
logo_items = [f'<div class="footer">',
f' <img style="float: right; padding: 10px;" src="{footer_logo}" height=30px>',
f'</div>']
footer += logo_items
footer.append('</html>\n')
footer = _convert_to_textstring(footer) footer = _convert_to_textstring(footer)
return footer return footer
@ -58,6 +64,10 @@ def add_html_image(img_data, img_format='png'):
return f"""<br>\n<img width="100%" src="data:image/{img_format};base64, {b64encode(img_data).decode('ascii')}">""" return f"""<br>\n<img width="100%" src="data:image/{img_format};base64, {b64encode(img_data).decode('ascii')}">"""
def get_html_link(text, link):
return f'<a href="{link}"> {text} </a>'
def get_html_row(items, html_key='td'): def get_html_row(items, html_key='td'):
row_string = '' row_string = ''
default_space = ' ' default_space = ' '
@ -73,11 +83,11 @@ def get_html_row(items, html_key='td'):
# check for black background of headers (shouldnt happen anymore) # check for black background of headers (shouldnt happen anymore)
color = '#e6e6e6' if color == '#000000' else color color = '#e6e6e6' if color == '#000000' else color
hyperlink = item.get('hyperlink') hyperlink = item.get('hyperlink')
image_str = f'<a href="{hyperlink}">' if hyperlink else '' text_str = get_html_link(text, hyperlink) if hyperlink else text
html_class = item.get('html_class') html_class = item.get('html_class')
class_str = f' class="{html_class}"' if html_class else '' class_str = f' class="{html_class}"' if html_class else ''
row_string += 2 * default_space + f'<{html_key}{class_str} bgcolor="{color}" title="{tooltip}"> {image_str}'\ row_string += 2 * default_space + f'<{html_key}{class_str} bgcolor="{color}" title="{tooltip}"> {text_str}'\
+ text + f'</{html_key}>\n' + f'</{html_key}>\n'
row_string += default_space + '</tr>\n' row_string += default_space + '</tr>\n'
return row_string return row_string