Skip to content

Commit

Permalink
Fixed issue with missing sample id in btl file dfo-mar-odis#173
Browse files Browse the repository at this point in the history
  • Loading branch information
upsonp committed Jul 10, 2024
1 parent 4436e63 commit 9ccb4c7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
12 changes: 11 additions & 1 deletion core/parsers/SampleParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,17 @@ def parse_data_frame(mission: core_models.Mission, sample_config: settings_model
value = row[value_field]

if sample_id not in bottle_keys:
message = f"Could not find bottle matching id {sample_id} in file {file_name}"
message = f"Could not find bottle matching id {sample_id} in file {file_name} \n"
event = mission.events.filter(sample_id__lte=sample_id, end_sample_id__gte=sample_id)
if event:
event = event.first()
message += (_("Possible Event") + f" #{event.event_id} " + _("Bottle IDs") +
f" {event.sample_id} - {event.end_sample_id}")
message += _("\nEvent Comments : ")
for action in event.actions.all():
if action.comment:
message += f"\n{action.get_type_display()} : {action.comment}"

error = core_models.FileError(mission=mission, file_name=file_name, line=sample_id, message=message,
type=core_models.ErrorType.sample)
errors.append(error)
Expand Down
35 changes: 29 additions & 6 deletions core/parsers/ctd.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,15 @@ def process_data(event: core_models.Event, data_frame: pandas.DataFrame, column_
update_discrete_samples: [core_models.DiscreteSampleValue] = []
# validate and remove bottles that don't exist
if data_frame_avg.shape[0] > (event.total_samples + 1):
message = _('Event contained more than the expected number of bottles. Additional bottles will be dropped. ')
message += _("Event") + f" #{event.event_id} "
message += _("Expected") + f"[{(event.total_samples+1)}] "
message += _("Found") + f"[{data_frame_avg.shape[0]}]"
message = _('Event contained more than the expected number of bottles. Additional bottles will be dropped. \n')
message += _("Event") + f" #{event.event_id} \n"
message += _("Expected") + f"[{(event.total_samples+1)}] \n"
message += _("Found") + f"[{data_frame_avg.shape[0]}]\n"
message += _("\nEvent Comments : ")
for action in event.actions.all():
if action.comment:
message += f"\n{action.get_type_display()} : {action.comment}"

logger.warning(message)

core_models.FileError(mission=mission, file_name=file_name, line=skipped_rows, message=message,
Expand Down Expand Up @@ -373,11 +378,29 @@ def process_data(event: core_models.Event, data_frame: pandas.DataFrame, column_

# if the Bottle S/N column is present then use that values as the bottle ID
if 'bottle_' in row[1]:
bottle_id = int(row[1]['bottle_'])
try:
bottle_id = int(row[1]['bottle_'])
except ValueError as ex:
logger.exception(ex)
message = _("There was an error parsing a bottle id - ")
message += _("\nEvent Comments : ")
for action in event.actions.all():
if action.comment:
message += f"\n{action.get_type_display()} : {action.comment}"

logger.error(message)

core_models.FileError(mission=mission, file_name=file_name, line=skipped_rows, message=message,
type=core_models.ErrorType.validation).save()
continue

if not bottles.filter(bottle_id=bottle_id).exists():
message = _("Bottle does not exist for event")
message = _("Bottle does not exist for event \n")
message += _("Event") + f" #{event.event_id} " + _("Bottle ID") + f" #{bottle_id}"
message += _("\nEvent Comments : ")
for action in event.actions.all():
if action.comment:
message += f"\n{action.get_type_display()} : {action.comment}"

logger.warning(message)
continue
Expand Down
1 change: 1 addition & 0 deletions core/tests/TestAndesParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_andeis_parser_events(self):
{
"event_number": 11.0,
"instrument": "Plankton net (202μm)",
"instrument_type": "NET",
"wire_out": "1000 m",
"wire_angle": "45 degrees",
"flow_meter_start": 2068,
Expand Down
5 changes: 4 additions & 1 deletion core/views_mission_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def get_file_error_card(request, database, mission_id):
li_id = f'error_{error.pk}'
li = soup.new_tag('li', attrs={'class': 'list-group-item', 'id': li_id})
div = soup.new_tag('div', attrs={'class': 'col'})
div.string = error.message
msgs = error.message.split("\n")
for msg in msgs:
div.append(msg_div:=soup.new_tag('div'))
msg_div.string = msg

url = reverse_lazy('core:mission_samples_delete_file_error', args=(database, error.pk))
btn_attrs = {
Expand Down
2 changes: 1 addition & 1 deletion start_dart.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if not exist ".\logs\" (
mkdir logs
)

set dart_version=3.3.0.2
set dart_version=3.3.1

REM if this is not a git repo, and the application was installed from zip file we just want to run update
REM if this is a cloned version of the git repo we want to pull from master, then run the update
Expand Down
2 changes: 1 addition & 1 deletion update.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if not exist ".\logs\" (
REM If this was run from a clone repo we can force an update of the python libraries, collectstatic or a
REM migration on the database by changing the update version

set update_version=3.3.0.2
set update_version=3.3.1

set first_run=0
set server_path=.\dart_env\Scripts\activate.bat
Expand Down

0 comments on commit 9ccb4c7

Please sign in to comment.