-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_data_general.py
68 lines (43 loc) · 2.04 KB
/
final_data_general.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import json
import os
from datetime import datetime, timedelta
import pytz
import calculate_daily_payment_data
import calculate_market_data
import config
from manage_transactions import get_first_transaction_timestamp
from util import logging
STORE_FINAL_DATA_GENERAL = '/terra-data/v2/final/general'
log = logging.get_custom_logger(__name__, config.LOG_LEVEL)
def final_data_general():
os.makedirs(STORE_FINAL_DATA_GENERAL, exist_ok=True)
max_time = datetime.utcnow()
max_time = max_time.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.UTC)
stop_processing = False
date_to_process = get_first_transaction_timestamp()
# date_last_processed = _get_last_processed_date()
# date_to_process = max(date_to_process, date_last_processed + timedelta(days=1))
log.debug('generate final data: general')
if date_to_process >= max_time:
return
while not stop_processing:
final_data = {}
payment_data = calculate_daily_payment_data.get_data_for_date(date_to_process)
file_path = os.path.join(STORE_FINAL_DATA_GENERAL, date_to_process.strftime('%Y-%m-%d') + '.json')
if not os.path.isfile(file_path):
for symbol in payment_data.keys():
final_data[symbol] = {}
log.debug('creating final general data for ' + date_to_process.strftime('%Y-%m-%d'))
# Amount of Coins
# Velocity
market_data = calculate_market_data.get_data(symbol, date_to_process)
if not market_data:
return
final_data[symbol]['amount_of_coins'] = market_data['circulating_supply']
final_data[symbol]['velocity_m1'] = payment_data[symbol]['total_amount'] / market_data['circulating_supply']
if len(final_data.keys()) > 0:
with open(file_path, 'w') as file:
file.write(json.dumps(final_data))
date_to_process += timedelta(days=1)
if date_to_process >= max_time:
stop_processing = True