Exemplo n.º 1
0
    def test_loss_curve_computation(self):
        loss_ratio_curve = shapes.Curve([(0.1, 1.0), (0.2, 2.0), (0.3, 3.0)])
        loss_curve = common.compute_loss_curve(loss_ratio_curve, ASSET_VALUE)

        self.assertEqual(shapes.Curve([(0.1 * ASSET_VALUE, 1.0),
                (0.2 * ASSET_VALUE, 2.0), (0.3 * ASSET_VALUE, 3.0)]),
                loss_curve)
Exemplo n.º 2
0
    def test_loss_curve_computation(self):
        loss_ratio_curve = shapes.Curve([(0.1, 1.0), (0.2, 2.0), (0.3, 3.0)])
        loss_curve = common.compute_loss_curve(loss_ratio_curve, ASSET_VALUE)

        self.assertEqual(shapes.Curve([(0.1 * ASSET_VALUE, 1.0),
                (0.2 * ASSET_VALUE, 2.0), (0.3 * ASSET_VALUE, 3.0)]),
                loss_curve)
Exemplo n.º 3
0
    def compute_loss_curve(self, point, loss_ratio_curve, asset):
        """
        Computes the loss ratio and store it in kvs to provide
        data to the @output decorator which does the serialization
        in the RiskJobMixin, more details inside
        openquake.risk.job.RiskJobMixin -- for details see
        RiskJobMixin._write_output_for_block and the output decorator

        :param point: the point of the grid we want to compute
        :type point: :py:class:`openquake.shapes.GridPoint`
        :param loss_ratio_curve: the loss ratio curve
        :type loss_ratio_curve: :py:class `openquake.shapes.Curve`
        :param asset: the asset for which to compute the loss curve
        :type asset: :py:class:`dict` as provided by
               :py:class:`openquake.parser.exposure.ExposurePortfolioFile`
        """

        loss_curve = compute_loss_curve(loss_ratio_curve, asset['assetValue'])
        loss_key = kvs.tokens.loss_curve_key(self.job_id, point.row,
                                             point.column, asset['assetID'])

        kvs.set(loss_key, loss_curve.to_json())
Exemplo n.º 4
0
    def compute_loss_curve(self, point, loss_ratio_curve, asset):
        """
        Computes the loss ratio and store it in kvs to provide
        data to the @output decorator which does the serialization
        in the RiskJobMixin, more details inside
        openquake.risk.job.RiskJobMixin -- for details see
        RiskJobMixin._write_output_for_block and the output decorator

        :param point: the point of the grid we want to compute
        :type point: :py:class:`openquake.shapes.GridPoint`
        :param loss_ratio_curve: the loss ratio curve
        :type loss_ratio_curve: :py:class `openquake.shapes.Curve`
        :param asset: the asset for which to compute the loss curve
        :type asset: :py:class:`dict` as provided by
               :py:class:`openquake.parser.exposure.ExposurePortfolioFile`
        """

        loss_curve = compute_loss_curve(loss_ratio_curve, asset['assetValue'])
        loss_key = kvs.tokens.loss_curve_key(self.job_id, point.row,
            point.column, asset['assetID'])

        kvs.set(loss_key, loss_curve.to_json())
Exemplo n.º 5
0
 def test_a_loss_curve_is_not_defined_when_the_asset_is_invalid(self):
     self.assertEqual(common.compute_loss_curve(
             shapes.Curve([(0.1, 1.0), (0.2, 2.0), (0.3, 3.0)]),
             INVALID_ASSET_VALUE),
             shapes.EMPTY_CURVE)
Exemplo n.º 6
0
 def test_empty_loss_curve(self):
     self.assertEqual(common.compute_loss_curve(shapes.EMPTY_CURVE, None),
             shapes.EMPTY_CURVE)
Exemplo n.º 7
0
 def test_a_loss_curve_is_not_defined_when_the_asset_is_invalid(self):
     self.assertEqual(common.compute_loss_curve(
             shapes.Curve([(0.1, 1.0), (0.2, 2.0), (0.3, 3.0)]),
             INVALID_ASSET_VALUE),
             shapes.EMPTY_CURVE)
Exemplo n.º 8
0
 def test_empty_loss_curve(self):
     self.assertEqual(common.compute_loss_curve(shapes.EMPTY_CURVE, None),
             shapes.EMPTY_CURVE)