-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_stats.py
executable file
·41 lines (33 loc) · 1.1 KB
/
problem_stats.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
#!/usr/bin/env python
import json
from pathlib import Path
def minmax_coordinates(path):
minx = miny = 0x800000
maxx = maxy = -0x800000
for fn in path.glob('*.json'):
with open(fn) as fp:
obj = json.load(fp)
hole = obj.get('hole', [])
figure = obj.get('figure', {}).get('vertices', [])
for [x, y] in (hole + figure):
minx, maxx = min(minx, x), max(maxx, x)
miny, maxy = min(miny, y), max(maxy, y)
print(f'coordinate range: x={minx}:{maxx}, y={miny}:{maxy}')
def max_vertices(path):
maxhole = maxfig = -0x800000
for fn in path.glob('*.json'):
with open(fn) as fp:
obj = json.load(fp)
hole = obj.get('hole', [])
maxhole = max(maxhole, len(hole))
figure = obj.get('figure', {}).get('vertices', [])
maxfig = max(maxfig, len(figure))
print('max vertices count')
print(' hole', maxhole)
print(' fig', maxfig)
def main():
path = Path(__file__).with_name('spec') / 'problems'
minmax_coordinates(path)
max_vertices(path)
if __name__ == '__main__':
main()