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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ dist
*.swp
*.log
*.egg-info
*.cpython-*.so
output/
replicas-wlce/
25 changes: 17 additions & 8 deletions simt_emlite/cli/profile_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

from emop_frame_protocol.emop_profile_log_1_record import EmopProfileLog1Record
from emop_frame_protocol.emop_profile_log_2_record import EmopProfileLog2Record
from rich.console import Console

# mypy: disable-error-code="import-untyped"
from simt_emlite.mediator.mediator_client_exception import MediatorClientException
from simt_emlite.profile_logs.download_cache import DownloadCache
from simt_emlite.profile_logs.downloader_config import DownloaderConfig
from simt_emlite.profile_logs.profile_downloader import ProfileDownloader
from simt_emlite.profile_logs.replicas.replica_missing_file_utils import (
Expand Down Expand Up @@ -170,11 +169,20 @@ def update_progress(msg: str):
)
return True, None

log_1_records: Dict[datetime.datetime, EmopProfileLog1Record] = (
downloader.download_profile_log_1_day(progress_callback=update_progress)
assert downloader.serial is not None
cache = DownloadCache(output_dir, downloader.serial, date)
if cache.has_cached_data:
log_progress(
f"Resuming from cached progress for [bold]{downloader.serial}[/bold] on [cyan]{date}[/cyan]",
meter=downloader.serial,
date=str(date),
)

log_1_records = downloader.download_profile_log_1_day(
progress_callback=update_progress, cache=cache
)
log_2_records: Dict[datetime.datetime, EmopProfileLog2Record] = (
downloader.download_profile_log_2_day(progress_callback=update_progress)
log_2_records = downloader.download_profile_log_2_day(
progress_callback=update_progress, cache=cache
)

# Create start and end datetime for the day (timezone-aware)
Expand All @@ -185,8 +193,6 @@ def update_progress(msg: str):
tzinfo=datetime.timezone.utc
)

assert downloader.serial is not None

# Create SMIP readings from the downloaded profile logs
readings_a, readings_b = create_smip_readings(
serial=downloader.serial,
Expand Down Expand Up @@ -228,6 +234,9 @@ def update_progress(msg: str):
meter=downloader.serial,
)

# Download succeeded - clean up cache
cache.delete()

identifier = (
downloader.name
if downloader and downloader.name is not None
Expand Down
Loading