From 5d212963747c6a5ae2bbde6d3b38dc0aea600698 Mon Sep 17 00:00:00 2001 From: Hal Simpson <hasimpson@usgs.gov> Date: Mon, 29 Jun 2015 13:09:53 -0600 Subject: [PATCH] Added routines to return the number of seconds in a given interval, and to detect if 'new' data exists between two data sets --- geomagio/TimeseriesUtilities.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/geomagio/TimeseriesUtilities.py b/geomagio/TimeseriesUtilities.py index a83071ab8..60efb0d06 100644 --- a/geomagio/TimeseriesUtilities.py +++ b/geomagio/TimeseriesUtilities.py @@ -39,9 +39,12 @@ def get_merged_gaps(gaps, channels): for channel in channels: gap_stream.extend(gaps[channel]) + if len(gap_stream) == 0: + return [] + sorted_gaps = sorted(gap_stream, key=lambda starttime: starttime[1]) merged_gaps = [] - new_gap = None + gap = sorted_gaps[0] for i in range(1,len(sorted_gaps)): nxtgap = sorted_gaps[i] @@ -54,3 +57,22 @@ def get_merged_gaps(gaps, channels): merged_gaps.append(gap) return merged_gaps + +def is_new_data(input_gaps, output_gaps): + for output_gap in output_gaps: + for input_gap in input_gaps: + if (output_gap[0] >= input_gap[0] and + output_gap[0] <= input_gap[1] and + output_gap[1] <= input_gap[1]): + return False + return True + +def get_seconds_of_interval(interval): + if interval == 'second': + return 1 + if interval == 'minute': + return 60 + if interval == 'hourly': + return 3600 + if interval == 'daily': + return 86400 -- GitLab