From 3e5981bccfb4e5d16f80703ccf9b2d1243e19c09 Mon Sep 17 00:00:00 2001
From: Alex Wernle <awernle@usgs.gov>
Date: Mon, 17 Apr 2023 15:59:33 -0600
Subject: [PATCH 1/2] Changed get_summary_flags to return False values if no
 matching summary spreadsheet is found and defined reviewed metadata.

---
 .../residual/SpreadsheetAbsolutesFactory.py   | 29 ++++++++++++-------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/geomagio/residual/SpreadsheetAbsolutesFactory.py b/geomagio/residual/SpreadsheetAbsolutesFactory.py
index 3facd710..1443f34a 100644
--- a/geomagio/residual/SpreadsheetAbsolutesFactory.py
+++ b/geomagio/residual/SpreadsheetAbsolutesFactory.py
@@ -240,7 +240,7 @@ def get_summary_flags(
     endtime: UTCDateTime,
     absolute_time: UTCDateTime,
 ) -> List[Reading]:
-    """Get valid flags from SpreadsheetSummaryFactory.
+    """Get valid flags from SpreadsheetSummaryFactory and define "reviewed" metadata.
 
     Parameters
     ----------
@@ -257,18 +257,23 @@ def get_summary_flags(
 
     Returns
     -------
-    Array of valid flags for absolutes from summary sheets
+    Array of valid flags for absolutes from summary sheets and metadata
     """
     readings = factory.get_readings(
         observatory=observatory,
         starttime=UTCDateTime(starttime),
         endtime=UTCDateTime(endtime),
     )
-
-    for reading in readings:
-        if reading.time == absolute_time:
-            summary_flags = [v.valid for v in reading.absolutes]
-    return summary_flags
+    if readings:
+        for reading in readings:
+            if reading.time == absolute_time:
+                summary_flags = [v.valid for v in reading.absolutes]
+                reviewed = True
+        return summary_flags, reviewed
+    else:
+        print("No matching summary sheet found for time:", absolute_time)
+        reviewed = False
+        return [False, False, False], reviewed
 
 
 class SpreadsheetAbsolutesFactory(object):
@@ -329,9 +334,10 @@ class SpreadsheetAbsolutesFactory(object):
         metadata = self._parse_metadata(
             constants_sheet, measurement_sheet, calculation_sheet, summary_sheet
         )
-        absolutes = self._parse_absolutes(
+        absolutes, reviewed = self._parse_absolutes(
             summary_sheet, observatory, starttime, endtime, metadata["date"]
         )
+        metadata["reviewed:"] = reviewed
         measurements = (
             include_measurements
             and self._parse_measurements(
@@ -367,8 +373,9 @@ class SpreadsheetAbsolutesFactory(object):
         absolute_time = parse_relative_time(
             base_date, "{:04d}".format(sheet["B12"].value)
         )
-        # pull valid flags from summary spreadsheets and match with absolute_time
-        summary_flags = get_summary_flags(
+        # pull valid flags from summary spreadsheets and match with absolute_time...
+        #  and define metadata "reviewed" based on valid flags
+        summary_flags, reviewed = get_summary_flags(
             factory=SpreadsheetSummaryFactory(self.base_directory),
             observatory=observatory,
             starttime=UTCDateTime(starttime),
@@ -427,7 +434,7 @@ class SpreadsheetAbsolutesFactory(object):
                 valid=summary_flags[2],
             ),
         ]
-        return absolutes
+        return absolutes, reviewed
 
     def _parse_measurements(
         self, sheet: openpyxl.worksheet, base_date: str, precision: str
-- 
GitLab


From 45deff1ae90bc32c344c32cbb85218247a9970f1 Mon Sep 17 00:00:00 2001
From: Alex Wernle <awernle@usgs.gov>
Date: Tue, 18 Apr 2023 10:48:29 -0600
Subject: [PATCH 2/2] Slight change from If loop to Try loop in
 get_summary_flags function. It is more dynamic this way.

---
 geomagio/residual/SpreadsheetAbsolutesFactory.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/geomagio/residual/SpreadsheetAbsolutesFactory.py b/geomagio/residual/SpreadsheetAbsolutesFactory.py
index 1443f34a..27c5be9e 100644
--- a/geomagio/residual/SpreadsheetAbsolutesFactory.py
+++ b/geomagio/residual/SpreadsheetAbsolutesFactory.py
@@ -264,13 +264,13 @@ def get_summary_flags(
         starttime=UTCDateTime(starttime),
         endtime=UTCDateTime(endtime),
     )
-    if readings:
+    try:
         for reading in readings:
             if reading.time == absolute_time:
                 summary_flags = [v.valid for v in reading.absolutes]
                 reviewed = True
         return summary_flags, reviewed
-    else:
+    except:
         print("No matching summary sheet found for time:", absolute_time)
         reviewed = False
         return [False, False, False], reviewed
-- 
GitLab