extract temporal coverage from TimeSeriesReultValues table
@@ -1353,29 +1353,16 @@ def _extract_coverage_metadata(resource, cur, logical_file=None):
target_obj.metadata.create_element('coverage', type='box', value=bbox)
- cur.execute("SELECT * FROM Results")
- results = cur.fetchall()
- min_begin_date = None
- max_end_date = None
- for result in results:
- cur.execute("SELECT ActionID FROM FeatureActions WHERE FeatureActionID=?",
- (result["FeatureActionID"],))
- feature_action = cur.fetchone()
- cur.execute("SELECT BeginDateTime, EndDateTime FROM Actions WHERE ActionID=?",
- (feature_action["ActionID"],))
- action = cur.fetchone()
- if min_begin_date is None:
- min_begin_date = action["BeginDateTime"]
- elif min_begin_date > action["BeginDateTime"]:
- min_begin_date = action["BeginDateTime"]
+ # extract temporal coverage
+ cur.execute("SELECT MAX(ValueDateTime) AS 'EndDate', MIN(ValueDateTime) AS 'BeginDate' "
+ "FROM TimeSeriesResultValues")
- if max_end_date is None:
- max_end_date = action["EndDateTime"]
- elif max_end_date < action["EndDateTime"]:
- max_end_date = action["EndDateTime"]
+ dates = cur.fetchone()
+ begin_date = dates['BeginDate']
+ end_date = dates['EndDate']
# create coverage element
- value_dict = {"start": min_begin_date, "end": max_end_date}
+ value_dict = {"start": begin_date, "end": end_date}
target_obj.metadata.create_element('coverage', type='period', value=value_dict)
