def test_rank_series_by_source(mock_requests_get): mock_return = ["data1", "data2", "data3"] mock_requests_get.return_value.json.return_value = mock_return mock_requests_get.return_value.status_code = 200 # Ordering of the dict should not matter a = { "region_id": 13474, "abc": 123, "def": 123, "ghe": 123, "fij": 123, "item_id": 3457, "metric_id": 2540047, "source_id": 26 } a.pop("abc") a.pop("def") a.pop("ghe") a.pop("fij") b = { "item_id": 3457, "region_id": 13474, "metric_id": 2540047, "source_id": 26 } c = list(lib.rank_series_by_source(MOCK_TOKEN, MOCK_HOST, [a, b])) assert (len(c) == 3) assert mock_return == [x["source_id"] for x in c]
def test_rank_series_by_source(mock_requests_get): # for each series selection, mock ranking of 3 source ids mock_return = [11, 22, 33] mock_requests_get.return_value.json.return_value = mock_return mock_requests_get.return_value.status_code = 200 a = { 'region_id': 13474, 'abc': 123, 'def': 123, 'ghe': 123, 'fij': 123, 'item_id': 3457, 'metric_id': 2540047, 'source_id': 123, 'source_name': 'dontcare' } a.pop('abc') a.pop('def') a.pop('ghe') a.pop('fij') b = {'item_id': 1457, 'region_id': 13474, 'metric_id': 2540047} c = list(lib.rank_series_by_source(MOCK_TOKEN, MOCK_HOST, [a, b])) assert (len(c) == 6) for x in c: assert 'source_name' not in x assert mock_return + mock_return == [x['source_id'] for x in c]
def rank_series_by_source(self, series_list): """Given a list of series selections, for each unique combination excluding source, expand to all available sources and return them in ranked order. The order corresponds to how well that source covers the selection (metrics, items, regions, and time range and frequency). Parameters ---------- series_list : list of dicts See the output of :meth:`~.get_data_series`. Yields ------ dict The input series_list, expanded out to each possible source, ordered by coverage. """ return lib.rank_series_by_source(self.access_token, self.api_host, series_list)
def rank_series_by_source(self, series_list): return lib.rank_series_by_source(self.access_token, self.api_host, series_list)