Skip to content
Snippets Groups Projects
Verified Commit db4bc397 authored by Owen Graham's avatar Owen Graham
Browse files

Remove unused `smooth_batch()` function

parent b1d50757
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
from collections import namedtuple
from datetime import datetime, timedelta, timezone
from datetime import datetime, timezone
import json
import os
from urllib.parse import quote
......@@ -59,36 +59,6 @@ def query_hourly_data(station_name, year, smooth=False):
yield translate_api_line(api_line, api_cols)
def smooth_batch(datapoints):
"""Group 10-minute data into ten-to, o-clock, and ten-after trios."""
# Seconds and microseconds are presumed to be zero.
minute_marks = tuple(timedelta(minutes=x) for x in (-10, 0, 10))
required_mark_i = 1 # Index of o-clock in `minute_marks`
# Find the absolute hour and the minute mark `dt` belongs to.
def hour_of(dt):
for i, minute_mark in enumerate(minute_marks):
shifted = dt - minute_mark
if shifted.minute == 0:
return shifted, i
return None, None
batch = [None] * len(minute_marks)
batch_hour = None
for point in datapoints:
point_hour, mark_i = hour_of(point.dt)
if point_hour is None:
continue
if point_hour != batch_hour:
if batch[required_mark_i] is not None:
yield batch
batch = [None] * len(minute_marks)
batch_hour = point_hour
batch[mark_i] = point
if batch[required_mark_i] is not None:
yield batch
def translate_api_line(api_line, api_cols):
(date_str, time_str, *variables) = (api_line[col] for col in api_cols)
dt_naive = datetime.strptime(f'{date_str} {time_str}', '%Y-%m-%d %H:%M')
......
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