File tree

6 files changed

+732
-664
lines changed

6 files changed

+732
-664
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.8.11
1+
3.10.12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
1+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10
22

33
WORKDIR /app
44

55
# Install Poetry
6-
RUN curl -sSL https://raw.usercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
6+
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
77
cd /usr/local/bin && \
88
ln -s /opt/poetry/bin/poetry && \
99
poetry config virtualenvs.create false
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ async def persist(keys: Keys, data: BitcoinSentiments):
111111
), data,
112112
)
113113

114+
async def get_latest_timestamp(ts_key: str):
115+
response = await redis.execute_command(
116+
'TS.GET', ts_key
117+
)
118+
119+
# Returns a list of the structure [timestamp, value]
120+
return response
114121

115122
async def get_hourly_average(ts_key: str, top_of_the_hour: int):
116123
response = await redis.execute_command(
@@ -167,7 +174,11 @@ def now():
167174
async def calculate_three_hours_of_data(keys: Keys) -> Dict[str, str]:
168175
sentiment_key = keys.timeseries_sentiment_key()
169176
price_key = keys.timeseries_price_key()
170-
three_hours_ago_ms = int((now() - timedelta(hours=3)).timestamp() * 1000)
177+
latest_data = await get_latest_timestamp(sentiment_key)
178+
#three_hours_ago_ms = int((now() - timedelta(hours=3)).timestamp() * 1000)
179+
three_hours_ago_ms = latest_data[0] - (1000 * 60 * 60 * 2)
180+
181+
print(three_hours_ago_ms)
171182

172183
sentiment = await get_hourly_average(sentiment_key, three_hours_ago_ms)
173184
price = await get_hourly_average(price_key, three_hours_ago_ms)
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
version: '3.8'
21
services:
32
redis:
4-
image: redislabs/redismod
3+
image: redis/redis-stack
54
ports:
65
- "16379:6379"
76
volumes:
87
- $PWD/data:/data
9-
command: --dir /data --loadmodule /usr/lib/redis/modules/redistimeseries.so
108

119
app:
1210
restart: always

0 commit comments

Comments
 (0)