-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpast_records.py
62 lines (47 loc) · 1.75 KB
/
past_records.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
import json
from collections import defaultdict
with open('problem1_day-1.json', 'r') as f:
past_1 = json.load(f)
with open('problem1_day-2.json', 'r') as f:
past_2 = json.load(f)
with open('problem1_day-3.json', 'r') as f:
past_3 = json.load(f)
past_record = {}
for day in past_1:
if int(day) not in past_record:
past_record[int(day)] = defaultdict(int)
for element in past_1[day]:
past_record[int(day)][element[0]] += 1
for day in past_2:
if int(day) not in past_record:
past_record[int(day)] = defaultdict(int)
for element in past_2[day]:
past_record[int(day)][element[0]] += 1
for day in past_3:
if int(day) not in past_record:
past_record[int(day)] = defaultdict(int)
for element in past_3[day]:
past_record[int(day)][element[0]] += 1
past_record_half = {}
for minute in past_record:
half_min = (minute//30)*30
if half_min not in past_record_half:
past_record_half[half_min] = defaultdict(int)
for loc in past_record[minute]:
past_record_half[half_min][loc] += past_record[minute][loc]
for minute in past_record_half:
summation = sum(list(past_record_half[minute].values()))
for loc in past_record_half[minute]:
past_record_half[minute][loc] = past_record_half[minute][loc]/summation
size = 5
for minute in past_record_half:
print("minute", minute)
print_map = [[0]*size for _ in range(size)]
for row in range(size):
for col in range(size):
this_id = col*size+(size-1-row)
print_map[row][col] = str(past_record_half[minute][this_id])[:4]
for row in range(size):
print(print_map[row])
with open('past_record_half.json', 'w') as f:
json.dump(past_record_half, f)