Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@
// Test processing only new data - as we would do in production with a cron job
//"args": ["-v", "1", "--last_n_days", "14"]
// Test improving out of range log message for Planktivore deployment in April 2026 - Ahi 47 CFE
"args": ["-v", "1", "--log_file", "ahi/missionlogs/2026/20260406_20260412/20260410T080016/202604100800_202604111036.nc4", "--clobber"]
//"args": ["-v", "1", "--log_file", "ahi/missionlogs/2026/20260406_20260412/20260410T080016/202604100800_202604111036.nc4", "--clobber"]
// Test parsing for "MAXON" to get sipper data
"args": ["-v", "1", "--log_file", "daphne/missionlogs/2026/20261001_20261005/20261001T213640/202610012136_202610021748.nc4", "--clobber", "--no_cleanup"]
},
{
"name": "process_lrauv_sbd",
Expand Down
11 changes: 7 additions & 4 deletions src/data/sipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
each sample event:

Start message (INFO level):
"ELMO will go to position ..."
"ELMO will go to position ..." or "MAXON will go to position ..."

Sample-number/error message (IMPORTANT level):
"Sample <n>, err_code=<m>" or "Sample <n>, (err_code=<m>)"
Expand All @@ -34,8 +34,11 @@
# Module-level constants (derived from STOQS SampleLoaders.py conventions)
# ---------------------------------------------------------------------------

# Substring that marks the start of a sip
# Substrings that mark the start of a sip; the message names the motor
# controller driving the sampler: ELMO or MAXON
SIPPERING = "ELMO will go to position"
SIPPERING_MAXON = "MAXON will go to position"
SIPPERING_MARKERS = (SIPPERING, SIPPERING_MAXON)

# Pattern to extract the sample number from the confirmation message.
# Handles both "Sample 1, err_code=0" and "Sample 1, (err_code=0)"
Expand Down Expand Up @@ -95,7 +98,7 @@ def _read_syslog(self) -> list:
self.logger.info("Reading remote syslog %s", syslog_url)
with requests.get(syslog_url, stream=True, timeout=TIMEOUT) as resp:
if resp.status_code != HTTPStatus.OK:
msg = f"Cannot read {syslog_url}, " f"HTTP status={resp.status_code}"
msg = f"Cannot read {syslog_url}, HTTP status={resp.status_code}"
raise FileNotFoundError(msg)
return [line.decode(errors="ignore") for line in resp.iter_lines()]

Expand Down Expand Up @@ -124,7 +127,7 @@ def _parse_lines(self, lines: list) -> dict:
log_level = m.group("log_level").upper()
message = m.group("log_message")

if SIPPERING in message:
if any(marker in message for marker in SIPPERING_MARKERS):
if log_level == "INFO":
samplings_at_info.append((esec, message))
else:
Expand Down
33 changes: 29 additions & 4 deletions src/data/test_sipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

import pytest
from sipper import SIPPERING, Sipper
from sipper import SIPPERING, SIPPERING_MAXON, Sipper

# ---------------------------------------------------------------------------
# Synthetic syslog fragments
Expand Down Expand Up @@ -57,6 +57,24 @@ def _line(esec: float, component: str, level: str, message: str) -> str:
_line(1565985120.000, "CANONSampler", "IMPORTANT", "Sample 1, err_code=0"),
]

# Start messages naming the MAXON motor controller instead of ELMO
MAXON_SYSLOG = [
_line(1565985091.135, "CANONSampler", "INFO", f"{SIPPERING_MAXON} at 37.0N -121.9W"),
_line(1565985120.000, "CANONSampler", "IMPORTANT", "Sample 1, err_code=0"),
_line(1565987000.500, "CANONSampler", "INFO", f"{SIPPERING_MAXON} at 37.1N -121.8W"),
_line(1565987050.200, "CANONSampler", "IMPORTANT", "Sample 2, err_code=0"),
# Non-CANONSampler line with MAXON text — must be ignored
_line(1565987100.000, "OtherComponent", "INFO", f"{SIPPERING_MAXON} irrelevant"),
]

# ELMO and MAXON start messages in the same syslog are paired in arrival order
MIXED_ELMO_MAXON_SYSLOG = [
_line(1565985091.135, "CANONSampler", "INFO", f"{SIPPERING} at 37.0N"),
_line(1565985120.000, "CANONSampler", "IMPORTANT", "Sample 1, err_code=0"),
_line(1565987000.500, "CANONSampler", "INFO", f"{SIPPERING_MAXON} at 37.1N"),
_line(1565987050.200, "CANONSampler", "IMPORTANT", "Sample 2, err_code=0"),
]

# Lines without trailing newlines (as returned by requests.iter_lines)
STRIPPED_SYSLOG = [line.rstrip("\n") for line in NORMAL_SYSLOG]

Expand Down Expand Up @@ -144,10 +162,17 @@ def test_epoch_seconds_are_float_values(self):
for val in result.values():
assert isinstance(val, float) # noqa: S101

# ---------------------------------------------------------------------------
# _match_sippers tests
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# _match_sippers tests
# ---------------------------------------------------------------------------
def test_maxon_start_messages(self):
result = self._sipper()._parse_lines(MAXON_SYSLOG)
assert result == {1: pytest.approx(1565985091.135), 2: pytest.approx(1565987000.500)} # noqa: S101

def test_mixed_elmo_and_maxon_start_messages(self):
result = self._sipper()._parse_lines(MIXED_ELMO_MAXON_SYSLOG)
assert result == {1: pytest.approx(1565985091.135), 2: pytest.approx(1565987000.500)} # noqa: S101


class TestMatchSippers:
Expand Down
Loading