-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_analysis.py
189 lines (153 loc) · 7.55 KB
/
db_analysis.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from utils.config_manager import ConfigManager
from persistence.db import MongoDBPersistenceManager
from model.odm import ODMModel
from model import Building
from utils.logger import Logger
from analysis import DXFAnalysis
from analysis import FloorMergeAnalysis
from analysis import BuildingIdAnalysis
persistence = MongoDBPersistenceManager(ConfigManager("config/general.json"))
ODMModel.set_pm( persistence )
def data_and_percent(value, total, num_padding = 3,):
if(total > 0):
return ("{:0>"+str(num_padding)+"} ({:>0.1f}%)").format(value, value/total*100.0)
else:
return ("{:0>"+str(num_padding)+"} ").format(value)
class GeneralReport:
merge_tuples = [
("edilizia", "dxf"),
("edilizia", "easyroom"),
("easyroom", "dxf"),
("easyroom", "edilizia")
]
@classmethod
def report_building(klass, building):
BuildingIdAnalysis.analyse_building_id(building)
with Logger.info("Analysing "+str(building)):
with Logger.info("DXF Data Analysis"):
klass._print_dxf_analysis(building)
no_data = set()
for source, target in klass.merge_tuples:
klass._print_merge_analysis(source, target, building)
if not building.get_path(source+".floors"):
no_data.add(source)
if not building.get_path(target+".floors"):
no_data.add(target)
if no_data:
Logger.info("Source doesn't exist or has no floor information:", ", ".join(no_data))
@classmethod
def _print_dxf_analysis(klass, building):
dxf_info = DXFAnalysis.analyse_dxf_info(building)
for f_id, count, which in dxf_info:
total_rooms = count["total_rooms"]
identified_rooms = data_and_percent(count["identified_rooms"], total_rooms)
categorized_rooms = data_and_percent(count["categorized_rooms"], total_rooms)
no_info_rooms = data_and_percent(count["no_info_rooms"], total_rooms)
message = "Floor {:5} | ".format(f_id)
message += "Rooms: {:<4} | ".format(total_rooms)
message += "With Id.: {:<12} | ".format(identified_rooms)
message += "With Cat: {:<12} | ".format(categorized_rooms)
message += "No info: {:<11} | ".format(no_info_rooms)
message += "Wall objs: {:<4} | ".format(count["walls"])
message += "Window objs: {:<4}".format(count["windows"])
Logger.info(message)
@classmethod
def _print_merge_analysis(klass, source, target, building):
method_name = "analyse_"+source+"_to_"+target
merge_info = getattr(FloorMergeAnalysis, method_name)(building)
if not building.get_path(source+".floors"):
return
if not building.get_path(target+".floors"):
return
with Logger.info("{} -> {} Merge Analysis".format(source.upper(), target.upper())):
for f_id, count, which in merge_info:
total_rooms = count["total_rooms"]
identified_rooms = data_and_percent(count["identified_rooms"], total_rooms)
non_identified_rooms = data_and_percent(count["non_identified_rooms"], total_rooms)
message = "Floor {:5} | ".format(f_id)
message += "Rooms: {:<4} | ".format(total_rooms)
message += "With Id.: {:<12} | ".format(identified_rooms)
message += "No Id: {:<12}".format(non_identified_rooms)
with Logger.info(message):
if count["non_identified_rooms"]:
Logger.warning(
source,
"knows about room(s)",
", ".join(which["non_identified_rooms"]),
"but", target, "does not"
)
@classmethod
def final_report(klass):
Logger.info("#####################################")
Logger.info("########### FINAL REPORTS ###########")
Logger.info("#####################################")
klass._final_building_id_report()
klass._final_dxf_report()
klass._final_merge_report()
@classmethod
def _final_building_id_report(klass):
count = BuildingIdAnalysis.general_count
Logger.info(
"Total Buildings: ", count["total_buildings"]
)
Logger.info(
"Buildings using legacy id: ", count["buildings_without_b_id"]
)
if count["buildings_without_b_id"]:
Logger.info(
"Legacy ids being used:", ", ".join(BuildingIdAnalysis.buildings_without_b_id)
)
@classmethod
def _final_dxf_report(klass):
with Logger.info("DXF Analysis"):
count = DXFAnalysis.general_count
total_floors = count["dxf.total_floors"]
matched_floors = data_and_percent(count["dxf.matched_floors"], total_floors)
total_rooms = count["dxf.total_rooms"]
identified_rooms = data_and_percent(count["dxf.identified_rooms"], total_rooms)
categorized_rooms = data_and_percent(count["dxf.categorized_rooms"], total_rooms)
no_info_rooms = data_and_percent(count["dxf.no_info_rooms"], total_rooms)
Logger.info("Total Floors : {}".format(total_floors))
Logger.info(
"Matched Floors : {:<14}".format(matched_floors),
"(Floors with at least one room associated to other sources)"
)
Logger.info("Total Rooms : {}".format(total_rooms))
Logger.info(
"Rooms Identified : {:<14}".format(identified_rooms),
"(there exists at least one data source with information about those rooms)"
)
Logger.info(
"Rooms with Category : {}".format(categorized_rooms),
"(unidentified rooms for which we can infer it's type)"
)
Logger.info("Rooms with no info : {}".format(no_info_rooms))
@classmethod
def _final_merge_report(klass):
with Logger.info("Merge Analysis"):
count = FloorMergeAnalysis.general_count
which = FloorMergeAnalysis.general_which
for source, target in klass.merge_tuples:
with Logger.info("Merged floor data from {} to {}".format(source, target)):
prefix = source+"_"+target
total_floors = count[prefix+".total_floors"]
identified_rooms = len(which[prefix+".identified_rooms"])
non_identified_rooms = len(which[prefix+".non_identified_rooms"])
total_rooms = identified_rooms + non_identified_rooms
identified_rooms = data_and_percent(identified_rooms, total_rooms)
non_identified_rooms = data_and_percent(non_identified_rooms, total_rooms)
Logger.info("Total floors analysed : {}".format(total_floors))
Logger.info("Total rooms found on {:<8} : {}".format(source, total_rooms))
Logger.info("Found in both sources : {}".format(identified_rooms))
with Logger.info("Not found on {:<9} : {}".format(target, non_identified_rooms)):
if which[prefix+".non_identified_rooms"]:
unident = sorted(which[prefix+".non_identified_rooms"])
while unident:
message = ""
for room_id in unident[:9]:
message += "{:<12}".format(room_id)
Logger.info(message)
unident = unident[9:]
for b in Building.where({}):
GeneralReport.report_building(b)
GeneralReport.final_report()