def test_deserialize(self):
        """Hazard map is read back correctly"""
        def _normalize(data):
            result = []

            key = "investigationTimeSpan"
            for pt, val in data:
                new = val.copy()
                new[key] = float(new[key])
                result.append((pt, new))

            return result

        outputs = []
        for idx, hcd in enumerate(HAZARD_CURVE_DATA()):
            output_path = self.generate_output_path(self.job,
                                                    output_type="hazard_curve")
            writer = HazardCurveDBWriter(output_path, self.job.id)
            # Call the function under test.
            writer.serialize(hcd)
            outputs.append((idx, writer.output))

        for idx, output in outputs:
            reader = HazardCurveDBReader()
            data = reader.deserialize(output.id)
            self.assertEquals(self.sort(_normalize(HAZARD_CURVE_DATA()[idx])),
                              self.sort(_normalize(data)))
    def test_deserialize(self):
        """Hazard map is read back correctly"""
        def _normalize(data):
            result = []

            key = "investigationTimeSpan"
            for pt, val in data:
                new = val.copy()
                new[key] = float(new[key])
                result.append((pt, new))

            return result

        outputs = []
        for idx, hcd in enumerate(HAZARD_CURVE_DATA()):
            output_path = self.generate_output_path(self.job,
                                                    output_type="hazard_curve")
            writer = HazardCurveDBWriter(output_path, self.job.id)
            # Call the function under test.
            writer.serialize(hcd)
            outputs.append((idx, writer.output))

        for idx, output in outputs:
            reader = HazardCurveDBReader()
            data = reader.deserialize(output.id)
            self.assertEquals(self.sort(_normalize(HAZARD_CURVE_DATA()[idx])),
                              self.sort(_normalize(data)))
    def test_serialize_small(self):
        data = HAZARD_CURVE_DATA(["1_1", "1_2", "2_2", "2"], 20, 4)

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

        for i in xrange(0, 10):
            hcw = HazardCurveDBWriter(output_path + str(i), self.job.id)

            # Call the function under test.
            hcw.serialize(data)
    def test_serialize_small(self):
        data = HAZARD_CURVE_DATA(['1_1', '1_2', '2_2', '2'], 20, 4)

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

        for i in xrange(0, 10):
            hcw = HazardCurveDBWriter(output_path + str(i), self.job.id)

            # Call the function under test.
            hcw.serialize(data)
    def test_deserialize_small(self):
        data = HAZARD_CURVE_DATA(["1_1", "1_2", "2_2", "2"], 20, 4)

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

        hcw = HazardCurveDBWriter(output_path, self.job.id)
        hcw.serialize(data)

        # deserialize
        hcr = HazardCurveDBReader()

        for i in xrange(0, 10):
            # Call the function under test.
            hcr.deserialize(hcw.output.id)
    def test_deserialize_small(self):
        data = HAZARD_CURVE_DATA(['1_1', '1_2', '2_2', '2'], 20, 4)

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

        hcw = HazardCurveDBWriter(output_path, self.job.id)
        hcw.serialize(data)

        # deserialize
        hcr = HazardCurveDBReader()

        for i in xrange(0, 10):
            # Call the function under test.
            hcr.deserialize(hcw.output.id)
Exemple #7
0
    def setUp(self):
        self.job = self.setup_classic_job()
        output_path = self.generate_output_path(self.job)
        self.display_name = os.path.basename(output_path)

        self.writer = HazardCurveDBWriter(output_path, self.job.id)
        self.reader = HazardCurveDBReader()
 def setUp(self):
     self.job = self.setup_classic_job()
     output_path = self.generate_output_path(self.job,
                                             output_type="hazard_curve")
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(HAZARD_CURVE_DATA())
     output_path = self.generate_output_path(self.job,
                                             output_type="hazard_curve")
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(MEAN_CURVE_DATA())
     output_path = self.generate_output_path(self.job,
                                             output_type="hazard_curve")
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(QUANTILE_CURVE_DATA())
    def test_serialize(self):
        """serialize() inserts the output and the hazard_map_data records."""
        # This job has no outputs before calling the function under test.
        self.assertEqual(0, len(self.job.output_set.all()))

        for hcd in HAZARD_CURVE_DATA():
            output_path = self.generate_output_path(self.job,
                                                    output_type="hazard_curve")
            writer = HazardCurveDBWriter(output_path, self.job.id)
            # Call the function under test.
            writer.serialize(hcd)

        # After calling the function under test we see the expected output.
        self.job = models.OqJob.objects.get(id=self.job.id)
        self.assertEqual(4, len(self.job.output_set.all()))

        # After calling the function under test we see the expected map data.
        hcs = models.HazardCurve.objects.filter(output__oq_job=self.job)
        self.assertEqual(4, len(hcs))

        # read data from the DB and check that it's equal to the original data

        ebl2index = {"1_1": 0, "1_2": 1, "2": 2}
        for hc in hcs:
            indb = []
            ebl = hc.end_branch_label
            hdidx = 3 if ebl is None else ebl2index[ebl]
            for hcd in hc.hazardcurvedata_set.all():
                location = hcd.location
                node = (Site(location.x, location.y),
                        {'PoEValues': hcd.poes})
                if hc.end_branch_label:
                    node[1]['endBranchLabel'] = hc.end_branch_label
                else:
                    node[1]['statistics'] = hc.statistic_type
                    if hc.quantile is not None:
                        node[1]['quantileValue'] = hc.quantile

                indb.append(node)
            self.assertEquals(self.normalize(HAZARD_CURVE_DATA()[hdidx]),
                              self.normalize(indb))
    def test_serialize(self):
        """serialize() inserts the output and the hazard_map_data records."""
        # This job has no outputs before calling the function under test.
        self.assertEqual(0, len(self.job.output_set.all()))

        for hcd in HAZARD_CURVE_DATA():
            output_path = self.generate_output_path(self.job,
                                                    output_type="hazard_curve")
            writer = HazardCurveDBWriter(output_path, self.job.id)
            # Call the function under test.
            writer.serialize(hcd)

        # After calling the function under test we see the expected output.
        self.job = models.OqJob.objects.get(id=self.job.id)
        self.assertEqual(4, len(self.job.output_set.all()))

        # After calling the function under test we see the expected map data.
        hcs = models.HazardCurve.objects.filter(output__oq_job=self.job)
        self.assertEqual(4, len(hcs))

        # read data from the DB and check that it's equal to the original data

        ebl2index = {"1_1": 0, "1_2": 1, "2": 2}
        for hc in hcs:
            indb = []
            ebl = hc.end_branch_label
            hdidx = 3 if ebl is None else ebl2index[ebl]
            for hcd in hc.hazardcurvedata_set.all():
                location = hcd.location
                node = (Site(location.x, location.y),
                        {'PoEValues': hcd.poes})
                if hc.end_branch_label:
                    node[1]['endBranchLabel'] = hc.end_branch_label
                else:
                    node[1]['statistics'] = hc.statistic_type
                    if hc.quantile is not None:
                        node[1]['quantileValue'] = hc.quantile

                indb.append(node)
            self.assertEquals(self.normalize(HAZARD_CURVE_DATA()[hdidx]),
                              self.normalize(indb))
 def setUp(self):
     self.job = self.setup_classic_job()
     output_path = self.generate_output_path(self.job)
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(HAZARD_CURVE_DATA())
Exemple #12
0
 def setUp(self):
     self.job = self.setup_classic_job()
     output_path = self.generate_output_path(self.job,
                                             output_type="hazard_curve")
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(HAZARD_CURVE_DATA())
     output_path = self.generate_output_path(self.job,
                                             output_type="hazard_curve")
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(MEAN_CURVE_DATA())
     output_path = self.generate_output_path(self.job,
                                             output_type="hazard_curve")
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(QUANTILE_CURVE_DATA())
Exemple #13
0
 def setUp(self):
     self.job = self.setup_classic_job()
     output_path = self.generate_output_path(self.job)
     hcw = HazardCurveDBWriter(output_path, self.job.id)
     hcw.serialize(HAZARD_CURVE_DATA())