Exemplo n.º 1
0
    def test_with_input_type(self):
        job, files = helpers.get_fake_risk_job(
            get_data_path('classical_psha_based_risk/job.ini'),
            get_data_path('simple_fault_demo_hazard/job.ini'))
        rc = job.risk_calculation

        inputs = models.inputs4rcalc(rc.id, input_type='exposure')
        self.assertEqual(1, inputs.count())
Exemplo n.º 2
0
    def test_a_few_inputs(self):
        job, files = helpers.get_risk_job("classical_psha_based_risk/job.ini", "simple_fault_demo_hazard/job.ini")
        rc = job.risk_calculation

        expected_ids = sorted([x.id for x in files.values()])

        inputs = models.inputs4rcalc(rc.id)

        actual_ids = sorted([x.id for x in inputs])

        self.assertEqual(expected_ids, actual_ids)
Exemplo n.º 3
0
    def test_with_input_type(self):
        job, files = helpers.get_risk_job("classical_psha_based_risk/job.ini", "simple_fault_demo_hazard/job.ini")
        rc = job.risk_calculation

        # It should only be 1 id, actually.
        expected_ids = [x.id for x in files.values() if x.input_type == "exposure"]

        inputs = models.inputs4rcalc(rc.id, input_type="exposure")

        actual_ids = sorted([x.id for x in inputs])

        self.assertEqual(expected_ids, actual_ids)
Exemplo n.º 4
0
    def _store_exposure(self):
        """Load exposure assets and write them to database."""
        [exposure_model_input] = models.inputs4rcalc(
            self.rc, input_type='exposure')

        # If this was an existing model, it was already parsed and should be in
        # the DB.
        if not self.rc.force_inputs and models.ExposureModel.objects.filter(
                input=exposure_model_input).exists():
            return exposure_model_input.exposuremodel

        with logs.tracing('storing exposure'):
            path = os.path.join(self.rc.base_path, exposure_model_input.path)
            exposure_stream = parsers.ExposureModelParser(path)
            w = exposure_writer.ExposureDBWriter(exposure_model_input)
            w.serialize(exposure_stream)
        return w.model
Exemplo n.º 5
0
 def test_no_inputs(self):
     self.assertEqual([], list(models.inputs4rcalc(-1)))