From b2b0ecb19b57ce359940909cd642e8a4799bace7 Mon Sep 17 00:00:00 2001 From: Alex Wernle <awernle@usgs.gov> Date: Mon, 15 May 2023 17:08:03 -0600 Subject: [PATCH] Added factory to created_by flag in order to track the source in the future. Changed status flag back to previous definition. --- geomagio/processing/copy_absolutes.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/geomagio/processing/copy_absolutes.py b/geomagio/processing/copy_absolutes.py index 8737f393..be0c5b41 100644 --- a/geomagio/processing/copy_absolutes.py +++ b/geomagio/processing/copy_absolutes.py @@ -66,8 +66,10 @@ def copy_absolutes( """Copy absolutes from the web absolutes service OR residual spreadsheets into the metadata service.""" if factory.value == ResidualFactory.WEB_ABSOLUTES: factory = WebAbsolutesFactory(url=web_absolutes_url) + source_factory = "webabsolutes" else: factory = SpreadsheetAbsolutesFactory(base_directory=directory) + source_factory = "spreadsheet" readings = get_readings( factory=factory, @@ -89,10 +91,12 @@ def copy_absolutes( iterable=readings, label="Uploading to metadata service" ) as progressbar: for reading in progressbar: - upload_reading(factory=metadata_factory, reading=reading) + upload_reading( + factory=metadata_factory, reading=reading, source_factory=source_factory + ) -def create_reading_metadata(reading: Reading) -> Metadata: +def create_reading_metadata(reading: Reading, source_factory) -> Metadata: """Create reading metadata object. Parameters @@ -107,13 +111,13 @@ def create_reading_metadata(reading: Reading) -> Metadata: measurement_times = [m.time for m in reading.measurements if m.time] metadata = Metadata( category=MetadataCategory.READING, - created_by=reading.metadata.get("observer", "copy_absolutes"), + created_by=(source_factory), endtime=max(measurement_times), metadata=json.loads(reading.json()), network="NT", starttime=min(measurement_times), station=reading.metadata["station"], - status="reviewed" if reading.metadata.get("reviewed") else "legacy", + status="reviewed" if reading.metadata.get("reviewed") else "new", updated_by=reading.metadata.get("reviewer"), ) return metadata @@ -157,7 +161,9 @@ def main() -> None: typer.run(copy_absolutes) -def upload_reading(factory: MetadataFactory, reading: Reading) -> Metadata: +def upload_reading( + factory: MetadataFactory, reading: Reading, source_factory +) -> Metadata: """Upload reading to metadata service Parameters @@ -171,7 +177,7 @@ def upload_reading(factory: MetadataFactory, reading: Reading) -> Metadata: ------- created metadata object """ - metadata = create_reading_metadata(reading=reading) + metadata = create_reading_metadata(reading=reading, source_factory=source_factory) # TODO: should this check if metadata was already uploaded? # TODO: should that check occur before calling this method? return factory.create_metadata(metadata=metadata) -- GitLab