-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
113 lines (104 loc) · 4.29 KB
/
main.py
File metadata and controls
113 lines (104 loc) · 4.29 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import csv
from obstacles import *
def load_obstacles(building):
obstacles = []
with open("data/obstacles/" + building) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
obstacles.append(Obstacle(float(row["x"]), float(row["y"])))
return obstacles
def load_shapes():
shapes = {
"Rectangular": {},
"Circular": {},
"L-shape": {},
"T-shape": {},
"Villa": {},
}
for shape in os.listdir("data/buildings"):
if shape.endswith(".csv"):
with open("data/buildings/" + shape) as csvfile:
reader = csv.reader(csvfile)
if shape.startswith("Rect"):
for row in reader:
shapes[shape[:-4]][row[0]] = Rectangle(
[float(row[1]), float(row[3])],
[float(row[2]), float(row[4])],
)
elif shape.startswith("L-s") or shape.startswith("T-s"):
for row in reader:
rect1 = Rectangle(
[float(row[1]), float(row[3])],
[float(row[2]), float(row[4])],
)
rect2 = Rectangle(
[float(row[5]), float(row[7])],
[float(row[6]), float(row[8])],
)
shapes[shape[:-4]][row[0]] = L_shape(rect1, rect2)
elif shape.startswith("Circular"):
for row in reader:
shapes[shape[:-4]][row[0]] = Circle(
float(row[1]), float(row[1]), float(row[1])
)
elif shape.startswith("Villa"):
for row in reader:
rect1 = Rectangle(
[float(row[1]), float(row[3])],
[float(row[2]), float(row[4])],
)
rect2 = Rectangle(
[float(row[5]), float(row[7])],
[float(row[6]), float(row[8])],
)
rect3 = Rectangle(
[float(row[9]), float(row[11])],
[float(row[10]), float(row[12])],
)
rect4 = Rectangle(
[float(row[13]), float(row[15])],
[float(row[14]), float(row[16])],
)
tri = Triangle(
[float(row[17]), float(row[18])],
[float(row[19]), float(row[20])],
[float(row[21]), float(row[22])],
)
shapes[shape[:-4]][row[0]] = Villa(
rect1, rect2, rect3, rect4, tri
)
return shapes
def main():
buildings = os.listdir("data/obstacles")
shapes = load_shapes()
out = shapes.copy()
for building in buildings:
if building.endswith(".csv"):
obstacles = load_obstacles(building)
model, size = building[:-4].split()
shape = shapes[model][size]
out[model][size] = {}
for cls in [Traditional, Props, Frames, Fast, East]:
props, canti, frames, name = cls(obstacles, shape).run(building[:-4])
out[model][size][name] = (props, canti, frames)
with open("out.csv", "w") as csvfile:
writer = csv.DictWriter(
csvfile,
fieldnames=["Model", "Size", "Class", "Props", "Cantilevers", "Frames"],
)
writer.writeheader()
for model in out:
for size in out[model]:
for cls in out[model][size]:
writer.writerow(
{
"Model": model,
"Size": size,
"Class": cls,
"Props": out[model][size][cls][0],
"Cantilevers": out[model][size][cls][1],
"Frames": out[model][size][cls][2],
}
)
if __name__ == "__main__":
main()