From ee2a5db35b08c1c5d1134c3ee17f8749bcdfb17f Mon Sep 17 00:00:00 2001 From: Mike McCann Date: Wed, 10 Dec 2025 22:21:38 -0800 Subject: [PATCH] Enable the use of --last_n_days for process_lrauv.py. --- .vscode/launch.json | 4 +++- src/data/process.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5f529ba..1f8dcd2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -394,7 +394,9 @@ // No GPS data for a log_file that has an ESP Sample //"args": ["-v", "1", "--log_file", "brizo/missionlogs/2025/20250916_20250922/20250920T070029/202509200700_202509201900.nc4", "--no_cleanup"] // Has nighttime data for proxys to be computed - "args": ["-v", "1", "--log_file", "pontus/missionlogs/2024/20240725_20240729/20240729T023020/202407290230_202407291556.nc4", "--no_cleanup"] + //"args": ["-v", "1", "--log_file", "pontus/missionlogs/2024/20240725_20240729/20240729T023020/202407290230_202407291556.nc4", "--no_cleanup"] + // Testing for adding crontab entries for process_lrauv + "args": ["-v", "1", "--last_n_days", "30", "--no_cleanup"] }, ] diff --git a/src/data/process.py b/src/data/process.py index 15f4eca..b98a781 100755 --- a/src/data/process.py +++ b/src/data/process.py @@ -60,7 +60,7 @@ class data are: download_process and calibrate, while for LRAUV class data import subprocess import sys import time -from datetime import UTC, datetime +from datetime import UTC, datetime, timedelta from getpass import getuser from pathlib import Path from socket import gethostname @@ -1068,8 +1068,47 @@ def process_log_files(self) -> None: self.process_log_file(log_file) except (InvalidCalFile, InvalidCombinedFile) as e: self.logger.warning("%s", e) + elif self.config.get("last_n_days"): + # Process log files from the last N days + end_dt = datetime.now(tz=UTC) + start_dt = end_dt - timedelta(days=self.config["last_n_days"]) + + # Format datetimes as YYYYMMDDTHHMMSS + start_str = start_dt.strftime("%Y%m%dT%H%M%S") + end_str = end_dt.strftime("%Y%m%dT%H%M%S") + + self.logger.info( + "Processing log files from the last %d days (%s to %s)", + self.config["last_n_days"], + start_str, + end_str, + ) + + log_files = self.log_file_list(start_str, end_str, self.config.get("auv_name")) + if not log_files: + self.logger.warning( + "No log files found in the last %d days", + self.config["last_n_days"], + ) + return + + self.logger.info( + "Processing %d log files from the last %d days", + len(log_files), + self.config["last_n_days"], + ) + for log_file in log_files: + # Extract AUV name from path + self.auv_name = log_file.split("/")[0].lower() + self.logger.info("Processing log file: %s", log_file) + try: + self.process_log_file(log_file) + except (InvalidCalFile, InvalidCombinedFile) as e: + self.logger.warning("%s", e) else: - self.logger.error("Must provide either --log_file or both --start and --end arguments") + self.logger.error( + "Must provide either --log_file, both --start and --end, or --last_n_days arguments" + ) return def process_command_line(self):