Skip to content
Snippets Groups Projects
Commit 84a6f967 authored by Erin (Josh) Rigler's avatar Erin (Josh) Rigler
Browse files

Merge branch 'fix-FilterAlgorithm-get_nearest_time' into 'master'

Function get_nearest_time() behaves as expected now

See merge request !338
parents a88ca95f 426ad8d4
No related branches found
No related tags found
1 merge request!338Function get_nearest_time() behaves as expected now
Pipeline #489198 passed
......@@ -64,24 +64,29 @@ STEPS = [
def get_nearest_time(step, output_time, left=True):
# nearest allowed timestamp "left" of output_time
interval_start = output_time - (
output_time.timestamp % step["output_sample_period"]
)
# shift interval right if needed
if interval_start != output_time and not left:
interval_start += step["output_sample_period"]
# position center of filter, data around interval
half_width = get_step_time_shift(step)
if step["type"] == "average":
filter_center = interval_start + half_width
data_start = interval_start
data_end = (interval_start + step["output_sample_period"]) - step[
"input_sample_period"
]
interval_start += half_width
# shift interval if needed
if left:
if interval_start > output_time:
interval_start -= step["output_sample_period"]
else:
filter_center = interval_start
data_start = filter_center - half_width
data_end = filter_center + half_width
if interval_start < output_time:
interval_start += step["output_sample_period"]
filter_center = interval_start
data_start = filter_center - half_width
data_end = filter_center + half_width
return {
"time": filter_center,
"data_start": data_start,
......
......@@ -313,7 +313,7 @@ def test_get_nearest__oneday_average():
f = FilterAlgorithm(input_sample_period=60.0, output_sample_period=86400.0)
step = f.get_filter_steps()[0]
time = UTCDateTime("2020-08-20T01:00:00")
aligned = get_nearest_time(step=step, output_time=time)
aligned = get_nearest_time(step=step, output_time=time, left=False)
# filter is average for day, should be first/last minute samples of 2020-08-20
assert_equal(aligned["data_start"], UTCDateTime("2020-08-20T00:00:00"))
assert_equal(aligned["time"], UTCDateTime("2020-08-20T11:59:30"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment