Пример #1
0
    def setUp(self):
        path = os.path.join(helpers.SCHEMA_EXAMPLES_DIR, "LCB-exposure.yaml")
        inputs = [("exposure", path)]
        self.job = self.setup_classic_job(inputs=inputs)

        [input] = models.inputs4job(self.job.id,
                                    input_type="exposure",
                                    path=path)
        owner = models.OqUser.objects.get(user_name="openquake")
        emdl = input.model()
        if not emdl:
            emdl = models.ExposureModel(owner=owner,
                                        input=input,
                                        description="LCB exposure model",
                                        category="LCB cars",
                                        stco_unit="peanuts",
                                        stco_type="aggregated")
            emdl.save()

        asset_data = [
            (Site(-118.077721, 33.852034), {
                u'stco': 5.07,
                u'asset_ref': u'a5625',
                u'taxonomy': u'HAZUS_RM1L_LC'
            }),
            (Site(-118.077721, 33.852034), {
                u'stco': 5.63,
                u'asset_ref': u'a5629',
                u'taxonomy': u'HAZUS_URML_LC'
            }),
            (Site(-118.077721, 33.852034), {
                u'stco': 11.26,
                u'asset_ref': u'a5630',
                u'taxonomy': u'HAZUS_URML_LS'
            }),
            (Site(-118.077721, 33.852034), {
                u'stco': 5.5,
                u'asset_ref': u'a5636',
                u'taxonomy': u'HAZUS_C3L_MC'
            }),
        ]
        for idx, (site, adata) in enumerate(asset_data):
            location = GEOSGeometry(site.point.to_wkt())
            asset = models.ExposureData(exposure_model=emdl,
                                        site=location,
                                        **adata)
            asset.save()
            RISK_LOSS_CURVE_DATA[idx][1][1] = asset

        output_path = self.generate_output_path(self.job)
        self.display_name = os.path.basename(output_path)

        self.writer = LossCurveDBWriter(output_path, self.job.id)
        self.reader = LossCurveDBReader()
Пример #2
0
    def test_serialize_small(self):
        data = LOSS_CURVE_DATA(20, 4)

        self.job = self.setup_classic_job()
        output_path = self.generate_output_path(self.job)

        for i in xrange(0, 20):
            lcw = LossCurveDBWriter(output_path + str(i), self.job.id)

            # Call the function under test.
            lcw.serialize(data)