@@ -66,44 +66,29 @@ def __init__(self):
66
66
"export_dist" ,
67
67
input_indx , X_cord , Y_cord )
68
68
69
- def _get_id (self ,
70
- idx : int ,
71
- i_result : DFVizResults
72
- ) -> str :
73
- """ Get the ID of the element """
74
- counter = 0
75
-
76
- if self .prefix == "beam" :
77
- return idx
78
- elif self .prefix == "joint" :
79
- for idx_b , beam in enumerate (i_result .assembly .beams ):
80
- for idx_j , joint in enumerate (beam .joints ):
81
- if counter == idx :
82
- return f"{ idx_b } --{ idx_j } --{ 0 } "
83
- counter += 1
84
- elif self .prefix == "joint_face" :
85
- for idx_b , beam in enumerate (i_result .assembly .beams ):
86
- for idx_j , joint in enumerate (beam .joints ):
87
- for idx_f , face in enumerate (joint .faces ):
88
- if counter == idx :
89
- return f"{ idx_b } --{ idx_j } --{ idx_f } "
90
- counter += 1
91
-
92
69
def _prepare_row (self ,
93
70
idx : int ,
94
71
i_result : DFVizResults
95
- ) -> typing .Dict :
72
+ ) -> typing .Dict [ str , typing . Any ] :
96
73
"""
97
74
Convert the results contained in the DFVizResults object to a dict to be written in the CSV file
98
75
99
76
:param idx: Index of the element
100
77
:param i_result: DFVizResults object containing all the values
101
78
102
- :return: Dict of values containng as keys the header and as items the values to be written in the CSV file
79
+ :return: Dict of values containing as keys the header and as items the values to be written in the CSV file
103
80
"""
104
81
if i_result .sanity_check [idx ].value != DFInvalidData .VALID .value :
105
82
invalid_type = i_result .sanity_check [idx ].name
106
- return [self ._get_id (idx , i_result ), invalid_type , invalid_type , invalid_type , invalid_type , invalid_type , invalid_type ]
83
+ return {
84
+ f"{ self .prefix } id" : i_result .find_id (idx ),
85
+ "invalid_type" : invalid_type ,
86
+ "min_deviation" : invalid_type ,
87
+ "max_deviation" : invalid_type ,
88
+ "std_deviation" : invalid_type ,
89
+ "rmse" : invalid_type ,
90
+ "mean" : invalid_type
91
+ }
107
92
108
93
distances = [round (value , 4 ) for value in i_result .distances [idx ]]
109
94
min_dev = round (i_result .distances_min_deviation [idx ], 4 )
@@ -112,27 +97,48 @@ def _prepare_row(self,
112
97
rmse = round (i_result .distances_rmse [idx ], 4 )
113
98
mean = round (i_result .distances_mean [idx ], 4 )
114
99
115
- row : typing .Dict = {
116
- f"{ self .prefix } id" : self . _get_id (idx , i_result ),
100
+ row : typing .Dict [ str , typing . Any ] = {
101
+ f"{ self .prefix } id" : i_result . find_id (idx ),
117
102
"distances" : distances ,
118
103
"min_deviation" : min_dev ,
119
104
"max_deviation" : max_dev ,
120
105
"std_deviation" : std_dev ,
121
106
"rmse" : rmse ,
122
107
"mean" : mean
123
108
}
109
+
110
+ # FIXME: find a good design system
111
+ # Add extra geometric info based on analysis type
112
+ if i_result .analysis_type == "beam" :
113
+ row .update ({
114
+ "beam_length" : i_result .assembly .beams [idx ].length
115
+ })
116
+ elif i_result .analysis_type == "joint" :
117
+ # NB:: for conviniency, if there is only one beam, we add the lenght of the beam i nthe joint csv analysis output
118
+ if i_result .assembly .has_only_one_beam :
119
+ row .update ({
120
+ "beam_length" : i_result .assembly .beams [0 ].length
121
+ })
122
+ row .update ({
123
+ "joint_distance_to_beam_midpoint" : i_result .assembly .compute_all_joint_distances_to_midpoint ()[idx ]
124
+ })
125
+ elif i_result .analysis_type == "joint_face" :
126
+ row .update ({
127
+ "jointface_angle" : i_result .assembly .compute_all_joint_angles ()[idx ]
128
+ })
129
+
124
130
return row
125
131
126
132
def _write_csv (self ,
127
133
csv_path : str ,
128
- rows : typing .List [typing .Dict ],
134
+ rows : typing .List [typing .Dict [ str , typing . Any ] ],
129
135
is_writing_only_distances : bool = False
130
136
) -> None :
131
137
"""
132
138
Write the CSV file
133
139
134
140
:param csv_path: Path of the CSV file
135
- :param rows: Dict of values to be written in the CSV file
141
+ :param rows: List of dictionaries containing values to be written in the CSV file
136
142
:param is_writing_only_distances: Flag to check if to write ONLY distances or the whole analysis
137
143
138
144
:return: None
@@ -157,20 +163,15 @@ def RunScript(self,
157
163
i_file_name : str ,
158
164
i_export_seperate_files : bool ,
159
165
i_export_distances : bool ,
160
- i_result ) :
166
+ i_result : DFVizResults ) -> None :
161
167
162
168
csv_analysis_path : str = None
163
169
csv_distances_path : str = None
164
170
165
171
if i_dump :
166
172
os .makedirs (i_export_dir , exist_ok = True )
167
173
168
- if len (i_result .assembly .beams ) == len (i_result .source ):
169
- self .prefix = "beam"
170
- elif len (i_result .assembly .all_joints ) == len (i_result .source ):
171
- self .prefix = "joint"
172
- elif len (i_result .assembly .all_joint_faces ) == len (i_result .source ):
173
- self .prefix = "joint_face"
174
+ self .prefix = i_result .analysis_type
174
175
175
176
if i_export_seperate_files :
176
177
for idx in range (len (i_result .source )):
0 commit comments