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

Commit

Permalink
Use inclusive when querying for one data point
Browse files Browse the repository at this point in the history
If the latest and earliest timestamps are identical and the data we are
requesting is not going to be aggregated by a period, we should use the
new `inclusive` query parameter to ensure that we receive the data at
the given timestamp.
  • Loading branch information
tombooth committed Dec 16, 2014
1 parent e32ebed commit 3bca686
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 8 additions & 3 deletions backdrop/transformers/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ def get_query_parameters(transform, earliest, latest):
query_parameters = transform.get('query-parameters', {})
query_parameters['flatten'] = 'true'

if earliest == latest and 'period' in query_parameters:
query_parameters['duration'] = 1
query_parameters['start_at'] = latest.isoformat()
if earliest == latest:
if 'period' in query_parameters:
query_parameters['duration'] = 1
query_parameters['start_at'] = latest.isoformat()
else:
query_parameters['inclusive'] = 'true'
query_parameters['start_at'] = earliest.isoformat()
query_parameters['end_at'] = latest.isoformat()
else:
query_parameters['start_at'] = earliest.isoformat()
query_parameters['end_at'] = latest.isoformat()
Expand Down
18 changes: 17 additions & 1 deletion tests/transformers/test_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_run_transform_no_output_group(self, mock_logging_task, mock_data_set, m

class GetQueryParametersTestCase(unittest.TestCase):

def test_get_query_parameters_same_timestamps(self):
def test_same_timestamps_period(self):
earliest = datetime(2014, 12, 14, 12, 00, 00, tzinfo=pytz.utc)
latest = datetime(2014, 12, 14, 12, 00, 00, tzinfo=pytz.utc)
transform = {
Expand All @@ -154,3 +154,19 @@ def test_get_query_parameters_same_timestamps(self):
'duration': 1,
'start_at': '2014-12-14T12:00:00+00:00',
}))

def test_same_timestamps_non_period(self):
earliest = datetime(2014, 12, 14, 12, 00, 00, tzinfo=pytz.utc)
latest = datetime(2014, 12, 14, 12, 00, 00, tzinfo=pytz.utc)
transform = {
'query-parameters': {
}
}

query_parameters = get_query_parameters(transform, earliest, latest)

assert_that(query_parameters, has_entries({
'start_at': '2014-12-14T12:00:00+00:00',
'end_at': '2014-12-14T12:00:00+00:00',
'inclusive': 'true',
}))

0 comments on commit 3bca686

Please sign in to comment.