Skip to content

Commit

Permalink
Factor out _get_lsr_volume() and add volume to logger messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MBARIMike committed Nov 22, 2024
1 parent 15b2799 commit af1ed69
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions stoqs/loaders/SampleLoaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,23 @@ def _validate_summaries(self, platform_name, filterings, stoppings, summaries, c

return filterings, stoppings, summaries

def _match_seq_to_cartridge(self, filterings, stoppings, summaries, before_seq_num_implemented=False, consolidated_msg=False):
def _get_lsr_volume(self, summary) -> float:
lsr_volume = re.search(lsr_volume_re, summary.text, re.MULTILINE)
if not lsr_volume:
self.logger.debug(f"Could not parse lsr_volume from '{summary.text}'")
self.logger.debug(f"Attempting with lsr_volume_re_paused regex: {lsr_volume_re_paused}")
lsr_volume = re.search(lsr_volume_re_paused, summary.text, re.MULTILINE)

# Convert volumes to ml and check for error in optional 3rd line of messages from ESP
volume = None
if lsr_volume:
if lsr_volume.groupdict().get('volume_units') == 'ml':
volume = float(lsr_volume.groupdict().get('volume_num'))
self.logger.debug(f"Parsed from log summary report volume = {volume} ml")

return volume

def _match_seq_to_cartridge(self, filterings, stoppings, summaries, before_seq_num_implemented=False, consolidated_msg=True):
'''Take lists from parsing TethysDash log and build Sample names list with start and end times
'''
# Loop through extractions from syslog to build dictionary
Expand All @@ -834,11 +850,7 @@ def _match_seq_to_cartridge(self, filterings, stoppings, summaries, before_seq_n
lsr_cartridge_number = re.search(CONSOLIDATED_MSG, summary.text)
else:
lsr_cartridge_number = re.search(lsr_cartridge_number_re, summary.text, re.MULTILINE)
lsr_volume = re.search(lsr_volume_re, summary.text, re.MULTILINE)
if not lsr_volume:
self.logger.debug(f"Could not parse lsr_volume from '{summary.text}'")
self.logger.debug(f"Attempting with lsr_volume_re_paused regex: {lsr_volume_re_paused}")
lsr_volume = re.search(lsr_volume_re_paused, summary.text, re.MULTILINE)
volume = self._get_lsr_volume(summary)
lsr_esp_error_msg = re.search(lsr_esp_error_msg_re, summary.text, re.MULTILINE)

# Ensure that sample # (seq) numbers match
Expand All @@ -859,7 +871,7 @@ def _match_seq_to_cartridge(self, filterings, stoppings, summaries, before_seq_n
try:
sample_name = f"Cartridge {lsr_cartridge_number.groupdict().get('cartridge_number')}"
if lsr_seq_num:
self.logger.info(f"sample # = {lsr_seq_num.groupdict().get('seq_num')}, sample_name = {sample_name}")
self.logger.info(f"sample # = {lsr_seq_num.groupdict().get('seq_num')}, sample_name = {sample_name}, volume = {volume} ml")
else:
self.logger.info(f"(No 'sample #' match) sample_name = {sample_name}")
except AttributeError:
Expand All @@ -873,11 +885,6 @@ def _match_seq_to_cartridge(self, filterings, stoppings, summaries, before_seq_n
self.logger.warn(f"Skipping this sample because of previous warning.")
continue

# Convert volumes to ml and check for error in optional 3rd line of messages from ESP
volume = None
if lsr_volume:
if lsr_volume.groupdict().get('volume_units') == 'ml':
volume = float(lsr_volume.groupdict().get('volume_num'))
if lsr_esp_error_msg:
if lsr_esp_error_msg.groupdict().get('esp_error_message'):
# Instance of 'Slide::Error in PROCESSING -- Archive Syringe positionErr at 54ul (actually 72ul)' in:
Expand All @@ -892,7 +899,6 @@ def _match_seq_to_cartridge(self, filterings, stoppings, summaries, before_seq_n
# http://dods.mbari.org/data/lrauv/makai/missionlogs/2019/20190822_20190827/20190822T194106/syslog
self.logger.info(f"Error encountered: {lsr_esp_error_msg.groupdict().get('esp_error_message')}")


sample_names[sample_name] = SampleInfo(filtering.esec, stopping.esec, volume, summary.text)

return sample_names
Expand Down Expand Up @@ -1016,7 +1022,7 @@ def _save_samples(self, db_alias, platform_name, activity_name, sampletype, samp
self.logger.warn(f"SampleType is {sampletype.name}, but no ESP device name found in syslog for {platform_name} {samp}")


def load_lrauv_samples(self, platform_name, activity_name, url, db_alias, use_consolidated_msg=False):
def load_lrauv_samples(self, platform_name, activity_name, url, db_alias, use_consolidated_msg=True):
'''
url looks like 'http://dods.mbari.org/opendap/data/lrauv/tethys/missionlogs/2018/20180906_20180917/20180908T084424/201809080844_201809112341_2S_scieng.nc'
'''
Expand Down

0 comments on commit af1ed69

Please sign in to comment.