예제 #1
0
class DFragilityDBWriterTestCase(unittest.TestCase, helpers.DbTestCase):
    """
    Test the code that writes discrete fragility model data to the database
    """
    job = None
    path = DISCRETE_FMODEL

    @classmethod
    def setUpClass(cls):
        inputs = [("fragility", cls.path)]
        cls.job = cls.setup_classic_job(inputs=inputs)

    @classmethod
    def tearDownClass(cls):
        cls.teardown_job(cls.job)

    def setUp(self):
        [self.input] = models.inputs4job(self.job.id, input_type="fragility")
        self.parser = FragilityModelParser(self.path)
        self.writer = FragilityDBWriter(self.input, self.parser)

    def test_write_discrete_fragility_model_to_db(self):
        # call tested function
        self.writer.serialize()

        # test results
        model = self.writer.model
        self.assertFalse(model is None)

        self.assertEqual([7.0, 8.0, 9.0, 10.0, 11.0], model.imls)
        self.assertEqual("mmi", model.imt)
        self.assertEqual("discrete", model.format)
        self.assertEqual("Fragility model for Pavia (discrete)",
                         model.description)
        expected_lss = ["minor", "moderate", "severe", "collapse"]
        self.assertEqual(expected_lss, model.lss)
        self.assertIs(self.input, model.input)

        ffcs = model.ffc_set.all()
        ffds = model.ffd_set.all().order_by("taxonomy", "lsi")
        self.assertEqual(0, ffcs.count())
        self.assertEqual(8, ffds.count())

        self.assertEqual(expected_lss * 2, [ff.ls for ff in ffds])

        self.assertEqual("RC/DMRF-D/HR", ffds[0].taxonomy)
        self.assertEqual("minor", ffds[0].ls)
        self.assertEqual([0.0, 0.09, 0.56, 0.92, 0.99], ffds[0].poes)

        self.assertEqual("RC/DMRF-D/HR", ffds[3].taxonomy)
        self.assertEqual("collapse", ffds[3].ls)
        self.assertEqual([0.0, 0.0, 0.0, 0.04, 0.64], ffds[3].poes)

        self.assertEqual("RC/DMRF-D/LR", ffds[5].taxonomy)
        self.assertEqual("moderate", ffds[5].ls)
        self.assertEqual([0.0, 0.0, 0.04, 0.78, 0.96], ffds[5].poes)

        self.assertEqual("RC/DMRF-D/LR", ffds[6].taxonomy)
        self.assertEqual("severe", ffds[6].ls)
        self.assertEqual([0.0, 0.0, 0.0, 0.29, 0.88], ffds[6].poes)
예제 #2
0
 def store_fragility_model(self):
     """Load fragility model and write it to database."""
     new_models = []
     fmis = models.inputs4job(self.job_ctxt.job_id, "fragility")
     for fmi in fmis:
         if fmi.fragilitymodel_set.all().count() > 0:
             continue
         path = os.path.join(self.job_ctxt.base_path, fmi.path)
         parser = fragility.FragilityModelParser(path)
         writer = FragilityDBWriter(fmi, parser)
         writer.serialize()
         new_models.append(writer.model)
     return new_models if new_models else None
예제 #3
0
 def store_fragility_model(self):
     """Load fragility model and write it to database."""
     new_models = []
     fmis = models.inputs4job(self.job_ctxt.job_id, "fragility")
     for fmi in fmis:
         if fmi.fragilitymodel_set.all().count() > 0:
             continue
         path = os.path.join(self.job_ctxt.base_path, fmi.path)
         parser = fragility.FragilityModelParser(path)
         writer = FragilityDBWriter(fmi, parser)
         writer.serialize()
         new_models.append(writer.model)
     return new_models if new_models else None
예제 #4
0
 def setUp(self):
     [self.input] = models.inputs4job(self.job.id, input_type="fragility")
     self.parser = FragilityModelParser(self.path)
     self.writer = FragilityDBWriter(self.input, self.parser)
예제 #5
0
class CFragilityDBWriterTestCase(unittest.TestCase, helpers.DbTestCase):
    """
    Test the code that writes continuous fragility model data to the database
    """
    job = None
    path = CONTINUOUS_FMODEL

    @classmethod
    def setUpClass(cls):
        inputs = [("fragility", cls.path)]
        cls.job = cls.setup_classic_job(inputs=inputs)

    @classmethod
    def tearDownClass(cls):
        cls.teardown_job(cls.job)

    def setUp(self):
        [self.input] = models.inputs4job(self.job.id, input_type="fragility")
        self.parser = FragilityModelParser(self.path)
        self.writer = FragilityDBWriter(self.input, self.parser)

    def test_write_continuous_fragility_model_to_db(self):
        # call tested function
        self.writer.serialize()

        # test results
        model = self.writer.model
        self.assertFalse(model is None)

        self.assertIs(None, model.imls)
        self.assertIs(None, model.imt)
        self.assertEqual("continuous", model.format)
        self.assertEqual("Fragility model for Pavia (continuous)",
                         model.description)
        expected_lss = ["slight", "moderate", "extensive", "complete"]
        self.assertEqual(expected_lss, model.lss)
        self.assertIs(self.input, model.input)

        ffcs = model.ffc_set.all().order_by("taxonomy", "lsi")
        ffds = model.ffd_set.all()
        self.assertEqual(8, ffcs.count())
        self.assertEqual(0, ffds.count())

        self.assertEqual(expected_lss * 2, [ff.ls for ff in ffcs])

        self.assertIs(None, ffcs[0].ftype)
        self.assertEqual("RC/DMRF-D/HR", ffcs[0].taxonomy)
        self.assertEqual("slight", ffcs[0].ls)
        self.assertEqual(11.18, ffcs[0].mean)
        self.assertEqual(8.28, ffcs[0].stddev)

        self.assertIs(None, ffcs[3].ftype)
        self.assertEqual("RC/DMRF-D/HR", ffcs[3].taxonomy)
        self.assertEqual("complete", ffcs[3].ls)
        self.assertEqual(108.8, ffcs[3].mean)
        self.assertEqual(123.6, ffcs[3].stddev)

        self.assertEqual("lognormal", ffcs[5].ftype)
        self.assertEqual("RC/DMRF-D/LR", ffcs[5].taxonomy)
        self.assertEqual("moderate", ffcs[5].ls)
        self.assertEqual(27.98, ffcs[5].mean)
        self.assertEqual(20.677, ffcs[5].stddev)

        self.assertEqual("lognormal", ffcs[6].ftype)
        self.assertEqual("RC/DMRF-D/LR", ffcs[6].taxonomy)
        self.assertEqual("extensive", ffcs[6].ls)
        self.assertEqual(48.05, ffcs[6].mean)
        self.assertEqual(42.49, ffcs[6].stddev)
예제 #6
0
 def setUp(self):
     [self.input] = models.inputs4job(self.job.id, input_type="fragility")
     self.parser = FragilityModelParser(self.path)
     self.writer = FragilityDBWriter(self.input, self.parser)
예제 #7
0
class DFragilityDBWriterTestCase(unittest.TestCase, helpers.DbTestCase):
    """
    Test the code that writes discrete fragility model data to the database
    """
    job = None
    path = DISCRETE_FMODEL

    @classmethod
    def setUpClass(cls):
        inputs = [("fragility", cls.path)]
        cls.job = cls.setup_classic_job(inputs=inputs)

    @classmethod
    def tearDownClass(cls):
        cls.teardown_job(cls.job)

    def setUp(self):
        [self.input] = models.inputs4job(self.job.id, input_type="fragility")
        self.parser = FragilityModelParser(self.path)
        self.writer = FragilityDBWriter(self.input, self.parser)

    def test_write_discrete_fragility_model_to_db(self):
        # call tested function
        self.writer.serialize()

        # test results
        model = self.writer.model
        self.assertFalse(model is None)

        self.assertEqual([7.0, 8.0, 9.0, 10.0, 11.0], model.imls)
        self.assertEqual("mmi", model.imt)
        self.assertEqual("discrete", model.format)
        self.assertEqual("Fragility model for Pavia (discrete)",
                         model.description)
        expected_lss = ["minor", "moderate", "severe", "collapse"]
        self.assertEqual(expected_lss, model.lss)
        self.assertIs(self.input, model.input)
        self.assertEqual(0.2, model.no_damage_limit)

        ffcs = model.ffc_set.all()
        ffds = model.ffd_set.all().order_by("taxonomy", "lsi")
        self.assertEqual(0, ffcs.count())
        self.assertEqual(8, ffds.count())

        self.assertEqual(expected_lss * 2, [ff.ls for ff in ffds])

        self.assertEqual("RC/DMRF-D/HR", ffds[0].taxonomy)
        self.assertEqual("minor", ffds[0].ls)
        self.assertEqual([0.0, 0.09, 0.56, 0.92, 0.99], ffds[0].poes)

        self.assertEqual("RC/DMRF-D/HR", ffds[3].taxonomy)
        self.assertEqual("collapse", ffds[3].ls)
        self.assertEqual([0.0, 0.0, 0.0, 0.04, 0.64], ffds[3].poes)

        self.assertEqual("RC/DMRF-D/LR", ffds[5].taxonomy)
        self.assertEqual("moderate", ffds[5].ls)
        self.assertEqual([0.0, 0.0, 0.04, 0.78, 0.96], ffds[5].poes)

        self.assertEqual("RC/DMRF-D/LR", ffds[6].taxonomy)
        self.assertEqual("severe", ffds[6].ls)
        self.assertEqual([0.0, 0.0, 0.0, 0.29, 0.88], ffds[6].poes)
예제 #8
0
class CFragilityDBWriterTestCase(unittest.TestCase, helpers.DbTestCase):
    """
    Test the code that writes continuous fragility model data to the database
    """
    job = None
    path = CONTINUOUS_FMODEL

    @classmethod
    def setUpClass(cls):
        inputs = [("fragility", cls.path)]
        cls.job = cls.setup_classic_job(inputs=inputs)

    @classmethod
    def tearDownClass(cls):
        cls.teardown_job(cls.job)

    def setUp(self):
        [self.input] = models.inputs4job(self.job.id, input_type="fragility")
        self.parser = FragilityModelParser(self.path)
        self.writer = FragilityDBWriter(self.input, self.parser)

    def test_write_continuous_fragility_model_to_db(self):
        # call tested function
        self.writer.serialize()

        # test results
        model = self.writer.model
        self.assertFalse(model is None)

        self.assertIs(None, model.imls)
        self.assertIs(None, model.imt)
        self.assertEqual("continuous", model.format)
        self.assertEqual("Fragility model for Pavia (continuous)",
                         model.description)
        expected_lss = ["slight", "moderate", "extensive", "complete"]
        self.assertEqual(expected_lss, model.lss)
        self.assertIs(self.input, model.input)
        self.assertIs(None, model.no_damage_limit)

        ffcs = model.ffc_set.all().order_by("taxonomy", "lsi")
        ffds = model.ffd_set.all()
        self.assertEqual(8, ffcs.count())
        self.assertEqual(0, ffds.count())

        self.assertEqual(expected_lss * 2, [ff.ls for ff in ffcs])

        self.assertIs(None, ffcs[0].ftype)
        self.assertEqual("RC/DMRF-D/HR", ffcs[0].taxonomy)
        self.assertEqual("slight", ffcs[0].ls)
        self.assertEqual(11.18, ffcs[0].mean)
        self.assertEqual(8.28, ffcs[0].stddev)

        self.assertIs(None, ffcs[3].ftype)
        self.assertEqual("RC/DMRF-D/HR", ffcs[3].taxonomy)
        self.assertEqual("complete", ffcs[3].ls)
        self.assertEqual(108.8, ffcs[3].mean)
        self.assertEqual(123.6, ffcs[3].stddev)

        self.assertEqual("lognormal", ffcs[5].ftype)
        self.assertEqual("RC/DMRF-D/LR", ffcs[5].taxonomy)
        self.assertEqual("moderate", ffcs[5].ls)
        self.assertEqual(27.98, ffcs[5].mean)
        self.assertEqual(20.677, ffcs[5].stddev)

        self.assertEqual("lognormal", ffcs[6].ftype)
        self.assertEqual("RC/DMRF-D/LR", ffcs[6].taxonomy)
        self.assertEqual("extensive", ffcs[6].ls)
        self.assertEqual(48.05, ffcs[6].mean)
        self.assertEqual(42.49, ffcs[6].stddev)