-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprune.py
36 lines (24 loc) · 776 Bytes
/
prune.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
import os, sys, json
LITERALS = {'only', 'max'}
def minimize(full, year):
new = {}, {}
for rule, data in full['rules'].items():
for part in data:
if part[1] not in LITERALS and int(part[1]) < year:
continue
if part[1] == 'only' and int(part[0]) < year:
continue
new[1].setdefault(rule, []).append(part)
for zone, data in full['zones'].items():
for part in data:
if part['u'] and int(part['u'][0]) < year:
continue
new[0].setdefault(zone, []).append(part)
if part['r'] is not None and part['r'] not in new[1]:
part['r'] = None
return {'zones': new[0], 'rules': new[1]}
if __name__ == '__main__':
with open(sys.argv[1]) as f:
full = json.load(f)
pruned = minimize(full, 2013)
print(json.dumps(pruned))