Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ar-api

* 'master' of https://github.com/datosgobar/series-tiempo-ar-api:
  Fix pylint
  Reescribo el armado de respuesta
  No devuelvo los nulls iniciales de una serie
  • Loading branch information
abenassi committed Jun 26, 2018
2 parents 4575705 + 56be45e commit a9b4358
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def format_response(self):
timestamp_dict = self.data_dict.setdefault(hit['key_as_string'], {})
timestamp_dict[self._data_dict_series_key(self.series[i])] = data
else:
response = filter(lambda hit, mode=rep_mode: mode in hit, response)
for hit in response:
data = hit[rep_mode] if rep_mode in hit else None
timestamp_dict = self.data_dict.setdefault(hit.timestamp, {})
timestamp_dict[self._data_dict_series_key(self.series[i])] = data
series = self._data_dict_series_key(self.series[i])
timestamp_dict[series] = hit[rep_mode]

if not self.data_dict: # No hay datos
return []
Expand Down
16 changes: 14 additions & 2 deletions series_tiempo_ar_api/apps/api/tests/es_query_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def test_end_of_period_with_rep_mode(self):
orig_eop.sort('asc')
end_of_period = orig_eop.run()

for i, row in enumerate(data[1:], 1): # El primero es nulo en pct change
value = end_of_period[i][1] / end_of_period[i - 1][1] - 1
for i, row in enumerate(data): # El primero es nulo en pct change
value = end_of_period[i + 1][1] / end_of_period[i][1] - 1

self.assertAlmostEqual(value, row[1])

Expand Down Expand Up @@ -462,3 +462,15 @@ def test_min_max_collapse_agg_with_rep_mode(self):
min_val = max([row[1] for row in data])

self.assertAlmostEqual(min_val, other_data[0][1], places=5)

def test_rep_mode_has_no_leading_nulls(self):
self.query.add_series(self.single_series, 'percent_change', self.series_periodicity)
data = self.query.run()

self.assertIsNotNone(data[0][1])

def test_year_rep_mode_has_no_leading_nulls(self):
self.query.add_series(self.single_series, 'percent_change_a_year_ago', self.series_periodicity)
data = self.query.run()

self.assertIsNotNone(data[0][1])
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_global_rep_mode(self):
other_query.sort('asc')
other_data = other_query.run()['data']

for index, row in enumerate(other_data[1:], start=1):
change = data[index][1] - data[index - 1][1]
for index, row in enumerate(other_data):
change = data[index + 1][1] - data[index][1]
# La resta anterior trae pérdida de precisión si los números de 'data' son grandes
self.assertAlmostEqual(row[1], change, places=5)

Expand Down

0 comments on commit a9b4358

Please sign in to comment.