forked from dhtech/ipplan2sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-dh-seatmap.py
57 lines (51 loc) · 1.33 KB
/
convert-dh-seatmap.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
import json
seatmap = json.load(open('seatmap.json', 'r'))
# Structure is:
# floors: {
# $floor_id: {
# name: "Hall D"
# We call them halls instead though
hall_id_map = {k: v['name'] for k,v in seatmap['floors'].items()}
# Structure is:
# rows: {
# $floor_id: {
# $row_id: {
# name: "B20"
# Row IDs are unique, so we ignore which floor they belong to
row_id_map = {k: v['name'] for x in seatmap['rows'].values() for k, v in x.items()}
# Structure is:
# seat_types: {
# $seat_type_id: {
# width: X
# height: Y
seat_type_map = seatmap['seat_types']
# Structure is:
# seats: {
# $floor_id: {
# $seat_id: {
# name: "20"
# row_id: $row_id
# floor_id: $floor_id
# seat_type_id: $seat_type_id
# Since floor_id is redundant we use the one inside the seat object.
seats = (v for x in seatmap['seats'].values() for v in x.values())
output = []
for seat in seats:
row = row_id_map[seat['row_id']]
hall = hall_id_map[seat['floor_id']]
seat_type = seat_type_map[seat['seat_type_id']]
seat_idx = seat['name']
x1 = seat['x']
y1 = seat['y']
x2 = seat['x'] + seat_type['width']
y2 = seat['y'] + seat_type['height']
output.append({
'x1': x1,
'y1': y1,
'x2': x2,
'y2': y2,
'seat': seat_idx,
'hall': hall,
'row': row,
})
print(json.dumps(output, indent=4))