Skip to content
Snippets Groups Projects
Commit dd8c749f authored by Cain, Payton David's avatar Cain, Payton David
Browse files

implement get_valid_interval

parent 65ba5bc3
Branches
Tags
2 merge requests!146Release CMO metadata to production,!17Implement hourly/daily filtering products
...@@ -49,6 +49,20 @@ def get_step_time_shift(step): ...@@ -49,6 +49,20 @@ def get_step_time_shift(step):
return input_sample_period * ((numtaps - 1) / 2) return input_sample_period * ((numtaps - 1) / 2)
def get_valid_interval(step, start, end):
# get first interval
interval_start = start - (start.timestamp % step["output_sample_period"])
start = interval_start
interval_end = start + step["output_sample_period"] - step["input_sample_period"]
while end > interval_end:
interval_start = interval_end + step["input_sample_period"]
interval_end = (
interval_start + step["output_sample_period"] - step["input_sample_period"]
)
end = interval_end - step["output_sample_period"]
return start, end
class FilterAlgorithm(Algorithm): class FilterAlgorithm(Algorithm):
""" """
Filter Algorithm that filters and downsamples data Filter Algorithm that filters and downsamples data
...@@ -328,17 +342,16 @@ class FilterAlgorithm(Algorithm): ...@@ -328,17 +342,16 @@ class FilterAlgorithm(Algorithm):
end of input required to generate requested output. end of input required to generate requested output.
""" """
steps = self.get_filter_steps() steps = self.get_filter_steps()
steps = np.flip(steps)
# calculate start/end from step array # calculate start/end from step array
for step in steps: for step in steps:
if step["type"] == "average": if step["type"] == "average":
intervals = end.timestamp - start.timestamp start, end = get_valid_interval(step, start, end)
end = (start + intervals) - step["input_sample_period"] else:
return (start, end) shift = get_step_time_shift(step)
shift_step = shift * step["input_sample_period"]
shift = get_step_time_shift(step) start = start - shift_step
shift_step = shift * step["input_sample_period"] end = end + shift_step
start = start - shift_step
end = end + shift_step
return (start, end) return (start, end)
@classmethod @classmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment