[update] append warnings to existing ones
This commit is contained in:
parent
68c6df72c9
commit
abc201c673
42
survBot.py
42
survBot.py
@ -271,12 +271,20 @@ class StationQC(object):
|
|||||||
if message:
|
if message:
|
||||||
self.detailed_status_dict[key] = message
|
self.detailed_status_dict[key] = message
|
||||||
|
|
||||||
def warn(self, key, message, status_message='WARN'):
|
def warn(self, key, detailed_message, status_message='WARN'):
|
||||||
self.detailed_status_dict[key] = message
|
# update detailed status if already existing
|
||||||
self.status_dict[key] = status_message
|
current_message = self.detailed_status_dict.get(key)
|
||||||
|
current_message = '' if current_message in [None, '-'] else current_message + ' | '
|
||||||
|
self.detailed_status_dict[key] = current_message + detailed_message
|
||||||
|
|
||||||
|
# this is becoming a little bit too complicated (adding warnings to existing)
|
||||||
|
current_status_message = self.status_dict.get(key)
|
||||||
|
current_status_message = '' if current_status_message in [None, 'OK', '-'] else current_status_message + ' | '
|
||||||
|
self.status_dict[key] = current_status_message + status_message
|
||||||
|
|
||||||
# change this to something more useful, SMS/EMAIL/PUSH
|
# change this to something more useful, SMS/EMAIL/PUSH
|
||||||
if self.verbosity:
|
if self.verbosity:
|
||||||
self.print(f'{UTCDateTime()}: {message}', flush=False)
|
self.print(f'{UTCDateTime()}: {detailed_message}', flush=False)
|
||||||
# warnings.warn(message)
|
# warnings.warn(message)
|
||||||
|
|
||||||
def error(self, key, message):
|
def error(self, key, message):
|
||||||
@ -369,7 +377,7 @@ class StationQC(object):
|
|||||||
if len(undervolt) > 0:
|
if len(undervolt) > 0:
|
||||||
warn_message += f' {n_undervolt}x Voltage under {low_volt}V ' \
|
warn_message += f' {n_undervolt}x Voltage under {low_volt}V ' \
|
||||||
+ self.get_last_occurrence_timestring(trace, undervolt)
|
+ self.get_last_occurrence_timestring(trace, undervolt)
|
||||||
self.warn(key, message=warn_message, status_message='WARN ({})'.format(n_overvolt + n_undervolt))
|
self.warn(key, detailed_message=warn_message, status_message='WARN ({})'.format(n_overvolt + n_undervolt))
|
||||||
|
|
||||||
def pb_temp_analysis(self, channel='EX1'):
|
def pb_temp_analysis(self, channel='EX1'):
|
||||||
""" Analyse PowBox temperature output. """
|
""" Analyse PowBox temperature output. """
|
||||||
@ -399,9 +407,9 @@ class StationQC(object):
|
|||||||
if len(t_check) > 0:
|
if len(t_check) > 0:
|
||||||
self.warn(key=key,
|
self.warn(key=key,
|
||||||
status_message=cur_temp,
|
status_message=cur_temp,
|
||||||
message=f'Trace {trace.get_id()}: '
|
detailed_message=f'Trace {trace.get_id()}: '
|
||||||
f'Temperature over {max_temp}\N{DEGREE SIGN} at {trace.get_id()}!'
|
f'Temperature over {max_temp}\N{DEGREE SIGN} at {trace.get_id()}!'
|
||||||
+ self.get_last_occurrence_timestring(trace, t_check))
|
+ self.get_last_occurrence_timestring(trace, t_check))
|
||||||
else:
|
else:
|
||||||
self.status_ok(key,
|
self.status_ok(key,
|
||||||
status_message=cur_temp,
|
status_message=cur_temp,
|
||||||
@ -417,7 +425,8 @@ class StationQC(object):
|
|||||||
if self.verbosity > 1:
|
if self.verbosity > 1:
|
||||||
self.print(40 * '-')
|
self.print(40 * '-')
|
||||||
self.print('Performing PowBox 12V/230V check (EX2)', flush=False)
|
self.print('Performing PowBox 12V/230V check (EX2)', flush=False)
|
||||||
voltage_check, voltage_dict, last_val = self.pb_voltage_ok(trace, voltage, pb_dict_key, warn_keys=keys)
|
voltage_check, voltage_dict, last_val = self.pb_voltage_ok(trace, voltage, pb_dict_key, channel=channel,
|
||||||
|
warn_keys=keys)
|
||||||
if voltage_check:
|
if voltage_check:
|
||||||
for key in keys:
|
for key in keys:
|
||||||
self.status_ok(key)
|
self.status_ok(key)
|
||||||
@ -438,7 +447,8 @@ class StationQC(object):
|
|||||||
if self.verbosity > 1:
|
if self.verbosity > 1:
|
||||||
self.print(40 * '-')
|
self.print(40 * '-')
|
||||||
self.print('Performing PowBox Router/Charger check (EX3)', flush=False)
|
self.print('Performing PowBox Router/Charger check (EX3)', flush=False)
|
||||||
voltage_check, voltage_dict, last_val = self.pb_voltage_ok(trace, voltage, pb_dict_key, warn_keys=keys)
|
voltage_check, voltage_dict, last_val = self.pb_voltage_ok(trace, voltage, pb_dict_key, channel=channel,
|
||||||
|
warn_keys=keys)
|
||||||
if voltage_check:
|
if voltage_check:
|
||||||
for key in keys:
|
for key in keys:
|
||||||
self.status_ok(key)
|
self.status_ok(key)
|
||||||
@ -460,9 +470,9 @@ class StationQC(object):
|
|||||||
# try calculate number of voltage peaks from gaps between indices
|
# try calculate number of voltage peaks from gaps between indices
|
||||||
n_occurrences = len(np.where(np.diff(ind_array) > 1)[0]) + 1
|
n_occurrences = len(np.where(np.diff(ind_array) > 1)[0]) + 1
|
||||||
self.warn(key=key,
|
self.warn(key=key,
|
||||||
message=f'Trace {trace.get_id()}: '
|
detailed_message=f'Trace {trace.get_id()}: '
|
||||||
f'Found {n_occurrences} occurrence(s) of {volt_lvl}V: {key}: {message}'
|
f'Found {n_occurrences} occurrence(s) of {volt_lvl}V: {key}: {message}'
|
||||||
+ self.get_last_occurrence_timestring(trace, ind_array),
|
+ self.get_last_occurrence_timestring(trace, ind_array),
|
||||||
status_message='WARN ({})'.format(n_occurrences))
|
status_message='WARN ({})'.format(n_occurrences))
|
||||||
if last_val != 1:
|
if last_val != 1:
|
||||||
self.error(key, message=f'Last PowBox voltage state {last_val}V: {message}')
|
self.error(key, message=f'Last PowBox voltage state {last_val}V: {message}')
|
||||||
@ -483,7 +493,7 @@ class StationQC(object):
|
|||||||
return
|
return
|
||||||
return trace
|
return trace
|
||||||
|
|
||||||
def pb_voltage_ok(self, trace, voltage, pb_dict_key, warn_keys):
|
def pb_voltage_ok(self, trace, voltage, pb_dict_key, warn_keys, channel=None):
|
||||||
"""
|
"""
|
||||||
Checks if voltage level is ok everywhere and returns True. If it is not okay it returns a dictionary
|
Checks if voltage level is ok everywhere and returns True. If it is not okay it returns a dictionary
|
||||||
with each voltage value associated to the different steps specified in POWBOX > pb_steps. Also raises
|
with each voltage value associated to the different steps specified in POWBOX > pb_steps. Also raises
|
||||||
@ -509,10 +519,10 @@ class StationQC(object):
|
|||||||
n_occurrences = len(np.where(np.diff(under) > 1)[0]) + 1
|
n_occurrences = len(np.where(np.diff(under) > 1)[0]) + 1
|
||||||
for key in warn_keys:
|
for key in warn_keys:
|
||||||
self.warn(key=key,
|
self.warn(key=key,
|
||||||
message=f'Trace {trace.get_id()}: '
|
detailed_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):.2}'
|
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))
|
||||||
|
|
||||||
# Get voltage levels for classification
|
# Get voltage levels for classification
|
||||||
@ -540,10 +550,10 @@ class StationQC(object):
|
|||||||
n_unclassified = len(unclassified_indices)
|
n_unclassified = len(unclassified_indices)
|
||||||
max_uncl = self.parameters.get('THRESHOLDS').get('unclassified')
|
max_uncl = self.parameters.get('THRESHOLDS').get('unclassified')
|
||||||
if max_uncl and n_unclassified > max_uncl:
|
if max_uncl and n_unclassified > max_uncl:
|
||||||
self.warn(key='other', message=f'Trace {trace.get_id()}: '
|
self.warn(key='other', detailed_message=f'Trace {trace.get_id()}: '
|
||||||
f'{n_unclassified}/{len(all_indices)} '
|
f'{n_unclassified}/{len(all_indices)} '
|
||||||
f'unclassified voltage values in channel {trace.get_id()}',
|
f'unclassified voltage values in channel {trace.get_id()}',
|
||||||
status_message=f'{n_unclassified} UNCLASSIFIED')
|
status_message=f'{channel}: {n_unclassified} u')
|
||||||
|
|
||||||
return False, voltage_dict, last_val
|
return False, voltage_dict, last_val
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user