-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.py
29 lines (24 loc) · 1.56 KB
/
clone.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
import json
with open('NVDA-Price-Stock-Prediction_clone.json', 'r') as fh: now = json.load(fh)
with open('NVDA-Price-Stock-Prediction_clone_before.json', 'r') as fh: before = json.load(fh)
latest = dict(before)
if 'count_past_to_last_2_weeks_ago' not in latest.keys(): latest['count_past_to_last_2_weeks_ago'] = 0
if 'uniques_past_to_last_2_weeks_ago' not in latest.keys(): latest['uniques_past_to_last_2_weeks_ago'] = 0
if 'count_total' not in latest.keys(): latest['count_total'] = 0
if 'uniques_total' not in latest.keys(): latest['uniques_total'] = 0
timestamps = {latest['clones'][i]['timestamp']: i for i in range(len(latest['clones']))}
for i in range(len(now['clones'])):
timestamp = now['clones'][i]['timestamp']
if timestamp in timestamps: latest['clones'][timestamps[timestamp]] = now['clones'][i]
else: latest['clones'].append(now['clones'][i])
if len(latest["clones"]) > 14:
temp_list = latest["clones"][:-14]
latest["clones"] = latest["clones"][-14:]
for i in temp_list:
latest['count_past_to_last_2_weeks_ago'] += i['count']
latest['uniques_past_to_last_2_weeks_ago'] += i['uniques']
latest['count'] = sum(map(lambda x: int(x['count']), latest['clones']))
latest['uniques'] = sum(map(lambda x: int(x['uniques']), latest['clones']))
latest['count_total'] = latest['count_past_to_last_2_weeks_ago'] + latest['count']
latest['uniques_total'] = latest['uniques_past_to_last_2_weeks_ago'] + latest['uniques']
with open('NVDA-Price-Stock-Prediction_clone.json', 'w', encoding='utf-8') as fh: json.dump(latest, fh, ensure_ascii=False, indent=4)