-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect_occurrences.py
More file actions
67 lines (52 loc) · 1.59 KB
/
collect_occurrences.py
File metadata and controls
67 lines (52 loc) · 1.59 KB
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
import json
import re
import operator
import ciso8601
with open('bookings.json') as f:
json_data = json.loads(f.read())
bookings = json_data["bookings"]
def extract_society_name(name):
pattern = ".*- UCLU (.*)"
match = re.match(pattern, name)
if match:
return match.groups()[0]
else:
return None
def number_of_bookings():
societies = {}
for booking in bookings:
society_name = extract_society_name(booking["contact"])
if society_name:
if society_name in societies.keys():
societies[society_name] += 1
else:
societies[society_name] = 1
else:
continue
sorted_societies = sorted(
societies.items(),
key=operator.itemgetter(1),
reverse=True
)
with open("total_bookings_by_society.json", "w") as f:
f.write(json.dumps({
"rows": [[society[0], society[1]] for society in sorted_societies]
}))
def bookings_over_time():
dates = {}
for booking in bookings:
start = ciso8601.parse_datetime(booking["start_time"])
formatted_date = "{year}-{month}-{day}".format(
year=start.year,
month=str(start.month).zfill(2),
day=str(start.day).zfill(2)
)
if formatted_date in dates.keys():
dates[formatted_date] += 1
else:
dates[formatted_date] = 1
with open("bookings_over_time.json", "w") as f:
f.write(json.dumps({
"rows": [[key, value] for key, value in dates.items()]
}))
number_of_bookings()