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

Commit

Permalink
Use _timestamp instead of _start_at to compare data points
Browse files Browse the repository at this point in the history
This is more robust and simpler than determining if a
period has been requested. Timestamp will always be
present in the response.
  • Loading branch information
mattrco committed Jan 23, 2015
1 parent 24cc694 commit 8720d2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 2 additions & 8 deletions backdrop/transformers/tasks/latest_dataset_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ def is_latest_data(data_set_config, transform, latest_datum):
existing_data = data_set.get(query_parameters=read_params)

if existing_data['data']:
if 'period' in transform_params:
if existing_data['data'][0]['_start_at'] > latest_datum['_timestamp']:
return False
else:
# If we got more than one data point back, assume latest_data
# isn't the newest in the dataset.
if len(existing_data['data']) > 1:
return False
if existing_data['data'][0]['_timestamp'] > latest_datum['_timestamp']:
return False

return True

Expand Down
10 changes: 5 additions & 5 deletions tests/transformers/tasks/test_latest_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def test_compute(self, mock_dashboard, mock_dataset):
'data': [
{
'_count': 1.0,
'_end_at': '2015-01-19T00:00:00+00:00',
'_start_at': '2015-01-12T00:00:00+00:00'
'_end_at': '2012-01-19T00:00:00+00:00',
'_timestamp': '2012`-01-12T00:00:00+00:00'
}
]
}
Expand Down Expand Up @@ -102,12 +102,12 @@ def test_compute_old_date_range(self, mock_dashboard, mock_dataset):
{
'_count': 1.0,
'_end_at': '2015-01-19T00:00:00+00:00',
'_start_at': '2015-01-12T00:00:00+00:00'
'_timestamp': '2015-01-12T00:00:00+00:00'
},
{
'_count': 1.0,
'_end_at': '2015-01-19T00:00:00+00:00',
'_start_at': '2015-01-12T00:00:00+00:00'
'_timestamp': '2015-01-12T00:00:00+00:00'
}
]
}
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_compute_old_date_period(self, mock_dashboard, mock_dataset):
'data': [
{
'_count': 1.0,
'_start_at': '2016-10-07T00:00:00+00:00'
'_timestamp': '2016-10-07T00:00:00+00:00'
}
]
}
Expand Down

0 comments on commit 8720d2f

Please sign in to comment.