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

Commit

Permalink
This ensures that we post the latest non null data
Browse files Browse the repository at this point in the history
Not just the latest data.

We should handle no data better than having to find that {} has no key
for our data point.
  • Loading branch information
jcbashdown committed Jan 29, 2015
1 parent 31503d5 commit 0612b3f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
20 changes: 11 additions & 9 deletions backdrop/transformers/tasks/latest_transaction_explorer_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
config.STAGECRAFT_OAUTH_TOKEN)


def _get_latest_data_points(data):
def _get_latest_data_points(data, data_point_name):
data.sort(key=lambda item: item['_timestamp'], reverse=True)
return data[0]
for data_point in data:
if data_point_name in data_point and data_point[data_point_name]:
return data_point
return {}


def _get_stripped_down_data_for_data_point_name_only(
Expand Down Expand Up @@ -62,23 +65,22 @@ def _get_stripped_down_data_for_data_point_name_only(
return new_data


def _service_ids_with_latest_data(data):
def _service_ids_with_latest_data(data, data_point_name):
for service_data_group in group_by('service_id', data).items():
yield service_data_group[0], _get_latest_data_points(
service_data_group[1])
service_data_group[1], data_point_name)


def _dashboard_configs_with_latest_data(data):
for service_id, latest_data in _service_ids_with_latest_data(data):
def _dashboard_configs_with_latest_data(data, data_point_name):
for service_id, latest_data in _service_ids_with_latest_data(data, data_point_name): # noqa
dashboard_configs = admin_api.get_dashboard_by_tx_id(service_id)
if dashboard_configs:
yield dashboard_configs[0], latest_data


def _get_data_points_for_each_tx_metric(data, transform, data_set_config):
for dashboard_config, latest_data in _dashboard_configs_with_latest_data(
data):
for data_point_name in REQUIRED_DATA_POINTS:
for data_point_name in REQUIRED_DATA_POINTS:
for dashboard_config, latest_data in _dashboard_configs_with_latest_data(data, data_point_name): # noqa
latest_datum = _get_stripped_down_data_for_data_point_name_only(
dashboard_config, latest_data, data_point_name)
# we need to look at, for example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,27 @@
"_id": "MjAxMi0wMS0wMSAwMDowMDowMDIwMTMtMDEtMDEgMDA6MDA6MDBiaXMtYW5udWFsLXJldHVybnM=",
"_month_start_at": "2012-01-01T00:00:00+00:00",
"_quarter_start_at": "2012-01-01T00:00:00+00:00",
"_timestamp": "2012-01-01T00:00:00+00:00",
"_timestamp": "2013-01-01T00:00:00+00:00",
"_updated_at": "2014-03-19T10:44:32.287000+00:00",
"_week_start_at": "2013-12-26T00:00:00+00:00",
"cost_per_transaction": 2.63,
"digital_cost_per_transaction": 2.36,
"digital_takeup": 0.9756123825537215,
"end_at": "2013-01-01T00:00:00+00:00",
"number_of_digital_transactions": null,
"number_of_transactions": 2358738,
"period": "year",
"service_id": "bis-annual-returns",
"total_cost": 6203480.9399999995,
"type": "seasonally-adjusted"
},
{
"_day_start_at": "2012-01-01T00:00:00+00:00",
"_hour_start_at": "2012-01-01T00:00:00+00:00",
"_id": "MjAxMi0wMS0wMSAwMDowMDowMDIwMTMtMDEtMDEgMDA6MDA6MDBiaXMtYW5udWFsLXJldHVybnM=",
"_month_start_at": "2012-01-01T00:00:00+00:00",
"_quarter_start_at": "2012-01-01T00:00:00+00:00",
"_timestamp": "2012-12-12T00:00:00+00:00",
"_updated_at": "2014-03-19T10:44:32.287000+00:00",
"_week_start_at": "2013-12-26T00:00:00+00:00",
"cost_per_transaction": 2.63,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@
"dashboard_slug": "bis-returns",
"type": "seasonally-adjusted"
},
{
"_id": encode_id('bis-returns', 'number_of_digital_transactions'),
"_timestamp": "2012-12-12T00:00:00+00:00",
"end_at": "2013-01-01T00:00:00+00:00",
"number_of_digital_transactions": 2301214,
"period": "year",
"service_id": "bis-annual-returns",
"dashboard_slug": "bis-returns",
"type": "seasonally-adjusted"
},
{
"_id": encode_id('bis-returns', 'number_of_transactions'),
"_timestamp": "2013-04-01T00:00:00+00:00",
Expand Down Expand Up @@ -172,7 +182,7 @@ def test_compute(self, mock_dashboard_finder, mock_dataset):
'data-group': 'transactions-explorer',
'data-type': 'spreadsheet'}})

assert_that(len(transformed_data), is_(11))
assert_that(len(transformed_data), is_(12))
assert_that(transformed_data, contains_inanyorder(*data_to_post))

@patch("performanceplatform.client.DataSet.from_group_and_type")
Expand Down

0 comments on commit 0612b3f

Please sign in to comment.