1
1
import functools
2
2
import logging
3
3
from datetime import datetime
4
+ from typing import Any
4
5
from typing import Dict
5
6
from typing import Iterable
6
7
from typing import List
21
22
TIME_FORMAT_STRING = '%Y-%m-%d_%H'
22
23
TWO_MINUTES = 60 * 60
23
24
25
+ BitcoinSentiments = List [Dict [str , Union [str , float ]]]
26
+
24
27
25
28
def prefixed_key (f ):
26
29
"""
27
30
A method decorator that prefixes return values.
31
+
28
32
Prefixes any string that the decorated method `f` returns with the value of
29
33
the `prefix` attribute on the owner object `self`.
30
34
"""
31
35
32
- def prefixed_method (self , * args , ** kwargs ):
33
- key = f (self , * args , ** kwargs )
36
+ def prefixed_method (* args , ** kwargs ):
37
+ self = args [0 ]
38
+ key = f (* args , ** kwargs )
34
39
return f'{ self .prefix } :{ key } '
35
40
36
41
return prefixed_method
@@ -56,6 +61,7 @@ def summary_key(self) -> str:
56
61
57
62
58
63
class Config (BaseSettings ):
64
+ # The default URL expects the app to run using Docker and docker-compose.
59
65
redis_url : str = 'redis://redis:6379'
60
66
61
67
@@ -81,7 +87,7 @@ def make_summary(data):
81
87
82
88
async def add_many_to_timeseries (
83
89
key_pairs : Iterable [Tuple [str , str ]],
84
- data : List [ Dict [ str , Union [ str , float ]]]
90
+ data : BitcoinSentiments
85
91
):
86
92
"""
87
93
Add many samples to a single timeseries key.
@@ -103,7 +109,7 @@ def make_keys():
103
109
return Keys ()
104
110
105
111
106
- async def persist (keys , data , summary ):
112
+ async def persist (keys : Keys , data : BitcoinSentiments , summary : Dict [ str , Any ] ):
107
113
# TODO: Only add timeseries data that we don't already have -- how?
108
114
ts_price_key = keys .timeseries_price_key ()
109
115
ts_sentiment_key = keys .timeseries_sentiment_key ()
0 commit comments