@@ -117,6 +117,8 @@ async def get_hourly_average(ts_key: str, top_of_the_hour: int):
|
117 | 117 | 'TS.RANGE', ts_key, top_of_the_hour, '+',
|
118 | 118 | 'AGGREGATION', 'avg', HOURLY_BUCKET,
|
119 | 119 | )
|
| 120 | +# Return the average without the timestamp. The response is a list |
| 121 | +# of the structure [timestamp, average]. |
120 | 122 | return response
|
121 | 123 |
|
122 | 124 |
|
@@ -166,32 +168,19 @@ def now():
|
166 | 168 | async def calculate_three_hours_of_data(keys: Keys) -> Dict[str, str]:
|
167 | 169 | sentiment_key = keys.timeseries_sentiment_key()
|
168 | 170 | 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) |
175 | 172 |
|
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) |
182 | 175 |
|
183 | 176 | last_three_hours = [{
|
184 | 177 | 'price': data[0][1], 'sentiment': data[1][1],
|
185 | 178 | 'time': datetime.fromtimestamp(data[0][0] / 1000, tz=timezone.utc),
|
186 | 179 | }
|
187 | 180 | for data in zip(price, sentiment)]
|
188 | 181 |
|
189 |
| -if len(last_three_hours) == 4: |
190 |
| -incomplete_hour = last_three_hours.pop(-1) |
191 |
| - |
192 | 182 | return {
|
193 | 183 | 'hourly_average_of_averages': last_three_hours,
|
194 |
| -'incomplete_hourly_average_of_averages': incomplete_hour, |
195 | 184 | 'sentiment_direction': get_direction(last_three_hours, 'sentiment'),
|
196 | 185 | 'price_direction': get_direction(last_three_hours, 'price'),
|
197 | 186 | }
|
|
0 commit comments