|
12 | 12 | get_test_session, |
13 | 13 | upgrade_test_database) |
14 | 14 | from reia.schemas.calculation_schemas import RiskAssessment |
15 | | -from reia.schemas.enums import ECalculationType |
16 | 15 | from reia.services.calculation import (CalculationDataService, |
17 | 16 | CalculationExecutionService) |
18 | 17 | from reia.services.creation_info import populate_creation_info |
@@ -151,113 +150,6 @@ def loss_calculation(loss_config, db_session): |
151 | 150 | return calculation |
152 | 151 |
|
153 | 152 |
|
154 | | -@pytest.fixture(scope='module') |
155 | | -def loss_calculation_example(db_session): |
156 | | - """Load example loss and damage calculations, then create risk assessment.""" |
157 | | - # Import exposure (shared by both calculations) |
158 | | - exposure = ExposureService.import_from_files( |
159 | | - db_session, |
160 | | - CALCULATION / 'exposure_model_converted.xml', |
161 | | - 'exposure') |
162 | | - |
163 | | - # Import vulnerability models for loss calculation |
164 | | - contents = VulnerabilityService.import_from_files( |
165 | | - db_session, |
166 | | - CALCULATION / 'contents_vulnerability_model.xml', |
167 | | - 'contents') |
168 | | - downtime = VulnerabilityService.import_from_files( |
169 | | - db_session, |
170 | | - CALCULATION / 'downtime_vulnerability_model.xml', |
171 | | - 'downtime') |
172 | | - structural = VulnerabilityService.import_from_files( |
173 | | - db_session, |
174 | | - CALCULATION / 'structural_vulnerability_model.xml', |
175 | | - 'structural') |
176 | | - nonstructural = VulnerabilityService.import_from_files( |
177 | | - db_session, |
178 | | - CALCULATION / 'nonstructural_vulnerability_model.xml', |
179 | | - 'nonstructural') |
180 | | - occupants = VulnerabilityService.import_from_files( |
181 | | - db_session, |
182 | | - CALCULATION / 'occupants_vulnerability_model.xml', |
183 | | - 'occupants') |
184 | | - |
185 | | - # Import fragility model for damage calculation |
186 | | - fragility = FragilityService.import_from_files( |
187 | | - db_session, |
188 | | - CALCULATION / 'structural_fragility_model.xml', |
189 | | - 'fragility') |
190 | | - |
191 | | - # Import taxonomy mapping (shared by both calculations) |
192 | | - taxonomy = TaxonomyService.import_from_files( |
193 | | - db_session, |
194 | | - CALCULATION / 'taxonomy_mapping.csv', |
195 | | - 'taxonomy') |
196 | | - |
197 | | - # Configure loss calculation (scenario_risk) |
198 | | - risk_file = configparser.ConfigParser() |
199 | | - risk_file.read(str(CALCULATION / 'job.ini')) |
200 | | - |
201 | | - risk_file['exposure']['exposure_file'] = str(exposure.oid) |
202 | | - risk_file['vulnerability']['contents_vulnerability_file'] = str( |
203 | | - contents.oid) |
204 | | - risk_file['vulnerability']['business_interruption_vulnerability_file'] = str( |
205 | | - downtime.oid) |
206 | | - risk_file['vulnerability']['structural_vulnerability_file'] = str( |
207 | | - structural.oid) |
208 | | - risk_file['vulnerability']['nonstructural_vulnerability_file'] = str( |
209 | | - nonstructural.oid) |
210 | | - risk_file['vulnerability']['occupants_vulnerability_file'] = str( |
211 | | - occupants.oid) |
212 | | - risk_file['vulnerability']['taxonomy_mapping_csv'] = str(taxonomy.oid) |
213 | | - risk_file['hazard']['gmfs_csv'] = str(CALCULATION / 'gmfs.csv') |
214 | | - risk_file['hazard']['sites_csv'] = str(CALCULATION / 'sites.csv') |
215 | | - |
216 | | - risk_file['fragility']['structural_fragility_file'] = str(fragility.oid) |
217 | | - risk_file['fragility']['taxonomy_mapping_csv'] = str(taxonomy.oid) |
218 | | - |
219 | | - with tempfile.TemporaryDirectory() as tmpdirname: |
220 | | - # Write loss calculation config |
221 | | - loss_file_path = Path(tmpdirname) / 'loss_calculation.ini' |
222 | | - with open(loss_file_path, 'w') as f: |
223 | | - risk_file.write(f) |
224 | | - |
225 | | - # Import both calculation configs |
226 | | - calculation_data = CalculationDataService.import_from_files( |
227 | | - db_session, [loss_file_path], [1]) |
228 | | - |
229 | | - # Run both calculations |
230 | | - loss_calculation = None |
231 | | - damage_calculation = None |
232 | | - calc_service = CalculationExecutionService(db_session) |
233 | | - |
234 | | - for data in calculation_data: |
235 | | - calc, branch_settings = data |
236 | | - |
237 | | - if calc is None: |
238 | | - continue |
239 | | - |
240 | | - calculation = calc_service.run_calculation(calc, branch_settings) |
241 | | - |
242 | | - # Determine which calculation this is based on calculation_mode |
243 | | - if calculation.type == ECalculationType.LOSS: |
244 | | - loss_calculation = calculation |
245 | | - elif calculation.type == ECalculationType.DAMAGE: |
246 | | - damage_calculation = calculation |
247 | | - |
248 | | - # Create risk assessment from both calculations |
249 | | - riskassessment = RiskAssessment( |
250 | | - originid='smi:ch.ethz.sed/example', |
251 | | - losscalculation_oid=loss_calculation.oid, |
252 | | - damagecalculation_oid=damage_calculation.oid) |
253 | | - |
254 | | - populate_creation_info(riskassessment) |
255 | | - risk_assessment = RiskAssessmentRepository.create( |
256 | | - db_session, riskassessment) |
257 | | - |
258 | | - return risk_assessment |
259 | | - |
260 | | - |
261 | 153 | @pytest.fixture(scope='module') |
262 | 154 | def damage_config(exposure, fragility, taxonomy): |
263 | 155 | """Create damage calculation config.""" |
|
0 commit comments