Ejemplo n.º 1
0
    def _parse_nrml_file(self):
        """Parse loss/loss ratio curve data from NRML file into dictionary."""

        if self.mode == 'loss_ratio':
            nrml_element = risk_parser.LossRatioCurveXMLReader(
                self.nrml_input_path)
        else:
            nrml_element = risk_parser.LossCurveXMLReader(self.nrml_input_path)

        # loss/loss ratio curves have a common *ordinate* for all curves
        # in an NRML file
        for (nrml_point,
             nrml_attr) in nrml_element.filter(region_constraint=None):

            site_hash = nrml_point.hash()
            curve_id = nrml_attr['assetID']

            if site_hash not in self.data:
                self.data[site_hash] = {
                    # capture SVG filename for each site
                    'path': self._generate_filename(site_hash),
                    'curves': {}
                }

            if curve_id not in self.data[site_hash]['curves']:
                self.data[site_hash]['curves'][curve_id] = {}

            self.data[site_hash]['curves'][curve_id] = {
                'abscissa': nrml_attr[nrml_element.abscissa_output_key],
                'abscissa_property': nrml_element.abscissa_property,
                'ordinate': nrml_attr[nrml_element.ordinate_output_key],
                'ordinate_property': nrml_element.ordinate_property,
                'Site': nrml_point,
                'curve_title': self.curve_title
            }
Ejemplo n.º 2
0
    def test_loss_ratio_curve_has_correct_content(self):
        loss_ratio_element = risk_parser.LossRatioCurveXMLReader(
            LOSS_RATIO_CURVE_TEST_FILE)
        expected_result = self.LOSS_RATIO_CURVE_REFERENCE_DATA

        counter = None
        for counter, (nrml_site, nrml_attr) in enumerate(loss_ratio_element):

            # check topological equality for points
            self.assertTrue(
                nrml_site.point.equals(expected_result[counter][0].point),
                "filter yielded unexpected site at position %s: %s, %s" %
                (counter, nrml_site.point, expected_result[counter][0].point))

            self.assertEqual(nrml_attr, expected_result[counter][1],
                "filter yielded unexpected attribute values at position " \
                "%s: %s, %s" % (counter, nrml_attr,
                                expected_result[counter][1]))

        # ensure that generator yielded at least one item
        self.assertTrue(counter is not None,
            "filter yielded nothing although %s item(s) were expected" % \
            len(expected_result))

        # ensure that generator returns exactly the number of items of the
        # expected result list
        self.assertEqual(
            counter,
            len(expected_result) - 1,
            "filter yielded wrong number of items (%s), expected were %s" %
            (counter + 1, len(expected_result)))