@@ -153,35 +153,34 @@ def ecp_dict_to_objects(ecp_dict, custom_map=None, verbose=0):
153153 new_instance = obj_class ()
154154 except TypeError as e :
155155 if "required positional argument:" in str (e ):
156- parameter = str (e ).split ("argument: " )[- 1 ]
157- parameter = parameter [1 :- 1 ]
158- new_instance = obj_class (data_models [mtype ][m_id ][parameter ])
156+ parameters = [str (e ).split ("argument: " )[- 1 ]]
159157 elif "required positional arguments:" in str (e ):
160158 p_str = str (e ).split ("arguments: " )[- 1 ]
161159 if ", and " in p_str : # if more than 2
162160 partial = p_str .split (", and " )
163161 parameters = partial [0 ].split (", " ) + partial [- 1 :]
164162 else : # if one
165163 parameters = p_str .split (" and " )
166- params = []
167- for parameter in parameters :
168- parameter = parameter [1 :- 1 ]
169- try :
170- params .append (data_models [mtype ][m_id ][parameter ])
171- except KeyError as e2 : # To be removed and just raise exception
172- deprecation ("Your file is out of date, "
173- "run sfsimodels.migrate_ecp(<file-path>, <out-file-path>)." )
174- if mtype == "building" :
175- params = [len (data_models [mtype ][m_id ]["storey_masses" ])] # n_storeys
176- if "frame" in data_models [mtype ][m_id ]["type" ]:
177- params .append (len (data_models [mtype ][m_id ]["bay_lengths" ]))
178- else :
179- raise KeyError ("Can't find required positional argument: {0} for {1} id: {2}" .format (
180- parameter , mtype , m_id
181- ))
182- new_instance = obj_class (* params )
183164 else :
184165 raise TypeError (e )
166+ params = []
167+ for parameter in parameters :
168+ parameter = parameter [1 :- 1 ]
169+ try :
170+ params .append (data_models [mtype ][m_id ][parameter ])
171+ except KeyError as e2 : # To be removed and just raise exception
172+ deprecation ("Your file is out of date, "
173+ "run sfsimodels.migrate_ecp(<file-path>, <out-file-path>)." )
174+ if mtype == "building" :
175+ params = [len (data_models [mtype ][m_id ]["storey_masses" ])] # n_storeys
176+ if "frame" in data_models [mtype ][m_id ]["type" ]:
177+ params .append (len (data_models [mtype ][m_id ]["bay_lengths" ]))
178+ else :
179+ raise KeyError ("Can't find required positional argument: {0} for {1} id: {2}" .format (
180+ parameter , mtype , m_id
181+ ))
182+ new_instance = obj_class (* params )
183+
185184 add_to_obj (new_instance , data_models [mtype ][m_id ], objs = objs , verbose = verbose )
186185 # print(mtype, m_id)
187186 objs [base_type ][int (data_models [mtype ][m_id ]["id" ])] = new_instance
@@ -195,54 +194,6 @@ def ecp_dict_to_objects(ecp_dict, custom_map=None, verbose=0):
195194 if base_type not in objs :
196195 objs [base_type ] = OrderedDict ()
197196
198- # if base_type == "building":
199- # for m_id in data_models[mtype]:
200- # obj = data_models[mtype][m_id]
201- # if obj["type"] in deprecated_types:
202- # obj["type"] = deprecated_types[obj["type"]]
203- # if "type" not in obj:
204- # obj["type"] = base_type
205- # if obj["type"] in ["sdof"]:
206- # new_building = obj_map["%s-%s" % (base_type, obj["type"])]()
207- # elif "building_frame" in obj["type"] or "frame_building" in obj["type"]:
208- # n_storeys = len(obj['interstorey_heights'])
209- # n_bays = len(obj['bay_lengths'])
210- # new_building = obj_map["%s-%s" % (base_type, obj["type"])](n_storeys, n_bays)
211- # for ss in range(n_storeys):
212- # for bb in range(n_bays):
213- # sect_is = obj["beam_section_ids"][ss][bb]
214- # if hasattr(sect_is, "__len__"):
215- # n_sections = len(sect_is)
216- # new_building.beams[ss][bb].split_into_multiple([1] * n_sections) # TODO: should be lengths
217- # for sect_i in range(len(sect_is)):
218- # beam_sect_id = str(obj["beam_section_ids"][ss][bb][sect_i])
219- # sect_dictionary = obj["beam_sections"][beam_sect_id]
220- # add_to_obj(new_building.beams[ss][bb].sections[sect_i], sect_dictionary, verbose=verbose)
221- # else: # deprecated loading
222- # beam_sect_id = str(obj["beam_section_ids"][ss][bb])
223- # sect_dictionary = obj["beam_sections"][beam_sect_id]
224- # add_to_obj(new_building.beams[ss][bb].section[0], sect_dictionary, verbose=verbose)
225- # for cc in range(n_bays + 1):
226- # sect_is = obj["column_section_ids"][ss][cc]
227- # if hasattr(sect_is, "__len__"):
228- # n_sections = len(sect_is)
229- # # TODO: should be lengths
230- # new_building.columns[ss][cc].split_into_multiple([1] * n_sections)
231- # for sect_i in range(len(sect_is)):
232- # column_sect_id = str(obj["column_section_ids"][ss][cc][sect_i])
233- # sect_dictionary = obj["column_sections"][column_sect_id]
234- # add_to_obj(new_building.columns[ss][cc].sections[sect_i], sect_dictionary, verbose=verbose)
235- # else:
236- # column_sect_id = str(obj["column_section_ids"][ss][cc])
237- # sect_dictionary = obj["column_sections"][column_sect_id]
238- # add_to_obj(new_building.columns[ss][cc].sections[0], sect_dictionary, verbose=verbose)
239- #
240- # else:
241- # n_storeys = len(obj['interstorey_heights'])
242- # new_building = obj_map["%s-%s" % (base_type, obj["type"])](n_storeys)
243- # add_to_obj(new_building, data_models[mtype][m_id], verbose=verbose)
244- # objs[base_type][int(data_models[mtype][m_id]["id"])] = new_building
245-
246197 if base_type == "system" : # must be run after other objects are loaded
247198 for m_id in data_models [mtype ]:
248199 obj = data_models [mtype ][m_id ]
0 commit comments