Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #292 from alphagov/more-robust-subclassing
Browse files Browse the repository at this point in the history
Various bits of code cleanup
  • Loading branch information
robyoung committed May 14, 2014
2 parents 4b36cb6 + 736c921 commit b33f185
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backdrop/core/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ def _is_start_of_day(self, timestamp):

def end(self, timestamp):
if self._is_boundary(timestamp):
return timestamp
return timestamp
return self.start(timestamp + self._delta)

def start(self, timestamp):
raise NotImplementedError()

def range(self, start, end):
_start = self.start(start).replace(tzinfo=pytz.UTC)
_end = self.end(end).replace(tzinfo=pytz.UTC)
while (_start < _end):
while _start < _end:
yield (_start, _start + self._delta)
_start += self._delta

def valid_start_at(self, timestamp):
raise NotImplementedError()


class Hour(Period):
def __init__(self):
Expand Down Expand Up @@ -129,7 +135,7 @@ def entry(start, end):
return data_by_start_at[time_index]
else:
return _merge(default, _period_limits(start, end))
return [entry(start, end) for start, end in period.range(start, end)]
return [entry(s, e) for s, e in period.range(start, end)]


def _period_limits(start, end):
Expand Down

0 comments on commit b33f185

Please sign in to comment.