File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ async def get_hourly_average(ts_key: str, top_of_the_hour: int):
117117
'TS.RANGE', ts_key, top_of_the_hour, '+',
118118
'AGGREGATION', 'avg', HOURLY_BUCKET,
119119
)
120+
# Return the average without the timestamp. The response is a list
121+
# of the structure [timestamp, average].
120122
return response
121123

122124

@@ -166,32 +168,19 @@ def now():
166168
async def calculate_three_hours_of_data(keys: Keys) -> Dict[str, str]:
167169
sentiment_key = keys.timeseries_sentiment_key()
168170
price_key = keys.timeseries_price_key()
169-
top_of_hour_three_hours_ago_ms = int(
170-
(now() - timedelta(hours=3)).replace(
171-
minute=0, second=0, microsecond=0,
172-
).timestamp() * 1000,
173-
)
174-
incomplete_hour = None
171+
three_hours_ago_ms = int((now() - timedelta(hours=3)).timestamp() * 1000)
175172

176-
sentiment = await get_hourly_average(
177-
sentiment_key, top_of_hour_three_hours_ago_ms,
178-
)
179-
price = await get_hourly_average(
180-
price_key, top_of_hour_three_hours_ago_ms,
181-
)
173+
sentiment = await get_hourly_average(sentiment_key, three_hours_ago_ms)
174+
price = await get_hourly_average(price_key, three_hours_ago_ms)
182175

183176
last_three_hours = [{
184177
'price': data[0][1], 'sentiment': data[1][1],
185178
'time': datetime.fromtimestamp(data[0][0] / 1000, tz=timezone.utc),
186179
}
187180
for data in zip(price, sentiment)]
188181

189-
if len(last_three_hours) == 4:
190-
incomplete_hour = last_three_hours.pop(-1)
191-
192182
return {
193183
'hourly_average_of_averages': last_three_hours,
194-
'incomplete_hourly_average_of_averages': incomplete_hour,
195184
'sentiment_direction': get_direction(last_three_hours, 'sentiment'),
196185
'price_direction': get_direction(last_three_hours, 'price'),
197186
}

0 commit comments

Comments
 (0)