示例#1
0
    def from_row(cls, row: typing.Dict[str, typing.Any]) -> 'ParsedDwellingDataRow':
        if not cls._CHECKER.validate(row):
            error_keys = ', '.join(cls._CHECKER.errors.keys())
            raise InvalidInputDataError(f'Validator failed on keys: {error_keys}')

        parsed = cls._CHECKER.document

        return ParsedDwellingDataRow(
            house_id=parsed['HOUSE_ID'],
            eval_id=parsed['EVAL_ID'],
            file_id=parsed['BUILDER'],
            eval_type=EvaluationType.from_code(parsed['EVAL_TYPE']),
            entry_date=parsed['ENTRYDATE'].date(),
            creation_date=parsed['CREATIONDATE'],
            modification_date=parsed['MODIFICATIONDATE'],
            year_built=parsed['YEARBUILT'],
            city=parsed['CLIENTCITY'],
            region=Region.from_data(parsed['HOUSEREGION']),
            forward_sortation_area=parsed['forwardSortationArea'],

            energy_upgrades=[upgrade.Upgrade.from_data(upgrade_node) for upgrade_node in parsed['upgrades']],
            heated_floor_area=parsed['HEATEDFLOORAREA'],
            house_type=parsed['TYPEOFHOUSE'],

            egh_rating=measurement.Measurement(
                measurement=parsed['EGHRATING'],
                upgrade=parsed['UGRRATING'],
            ),

            ers_rating=measurement.Measurement(
                measurement=parsed['ERSRATING'],
                upgrade=parsed['UGRERSRATING'],
            ),

            greenhouse_gas_emissions=measurement.Measurement(
                measurement=parsed['ERSGHG'],
                upgrade=parsed['UGRERSGHG'],
            ),

            energy_intensity=measurement.Measurement(
                measurement=parsed['ERSENERGYINTENSITY'],
                upgrade=parsed['UGRERSENERGYINTENSITY'],
            ),

            walls=measurement.Measurement(
                measurement=walls.Wall.from_data(
                    parsed['WALLDEF'],
                    parsed['EGHHLWALLS'],
                ),
                upgrade=walls.Wall.from_data(
                    parsed['UGRWALLDEF'],
                    parsed['UGRHLWALLS'],
                ),
            ),
            design_heat_loss=measurement.Measurement(
                measurement=parsed['EGHDESHTLOSS'],
                upgrade=parsed['UGRDESHTLOSS'],
            ),
        )
示例#2
0
def test_seriealize_properties() -> None:
    class Test():
        def __init__(self, a: int) -> None:
            self.a = a

        def to_dict(self) -> typing.Dict[str, int]:
            return {'a': self.a}

    assert measurement.Measurement(measurement=Test(1),
                                   upgrade=Test(2)).to_dict() == {
                                       'measurement': {
                                           'a': 1
                                       },
                                       'upgrade': {
                                           'a': 2
                                       },
                                   }
示例#3
0
    def test_from_row(self, sample_input_d: typing.Dict[str, typing.Any]) -> None:
        output = dwelling.ParsedDwellingDataRow.from_row(sample_input_d)

        assert output == dwelling.ParsedDwellingDataRow(
            house_id=456,
            eval_id=123,
            file_id='4K13D01404',
            eval_type=evaluation_type.EvaluationType.PRE_RETROFIT,
            entry_date=datetime.date(2018, 1, 1),
            creation_date=datetime.datetime(2018, 1, 8, 9),
            modification_date=datetime.datetime(2018, 6, 1, 9),
            year_built=2000,
            city='Ottawa',
            region=region.Region.ONTARIO,
            forward_sortation_area='K1P',
            energy_upgrades=[
                upgrade.Upgrade(
                    upgrade_type='Ceilings',
                    cost=0,
                    priority=12,
                ),
                upgrade.Upgrade(
                    upgrade_type='MainWalls',
                    cost=1,
                    priority=2,
                ),
                upgrade.Upgrade(
                    upgrade_type='Foundation',
                    cost=2,
                    priority=3,
                ),
            ],
            house_type='Single detached',
            heated_floor_area=12.34,
            egh_rating=measurement.Measurement(
                measurement=50.5,
                upgrade=49.0,
            ),
            ers_rating=measurement.Measurement(
                measurement=567,
                upgrade=565,
            ),
            greenhouse_gas_emissions=measurement.Measurement(
                measurement=12.5,
                upgrade=12.34,
            ),
            energy_intensity=measurement.Measurement(
                measurement=0.82,
                upgrade=0.80,
            ),
            walls=measurement.Measurement(
                measurement=walls.Wall(
                    insulation=[
                        composite.CompositeValue(
                            percentage=45.3,
                            value=12.0,
                            value_name='rValue'
                        ),
                        composite.CompositeValue(
                            percentage=50.0,
                            value=12.0,
                            value_name='rValue'
                        ),
                        composite.CompositeValue(
                            percentage=4.7,
                            value=12.0,
                            value_name='rValue'
                        ),
                    ],
                    heat_lost=27799.9
                ),
                upgrade=walls.Wall(
                    insulation=[
                        composite.CompositeValue(
                            percentage=45.3,
                            value=12.0,
                            value_name='rValue'
                        ),
                        composite.CompositeValue(
                            percentage=50.0,
                            value=12.0,
                            value_name='rValue'
                        ),
                        composite.CompositeValue(
                            percentage=4.7,
                            value=10.0,
                            value_name='rValue'
                        ),
                    ],
                    heat_lost=27799.9
                )
            ),
            design_heat_loss=measurement.Measurement(
                measurement=11242.1,
                upgrade=10757.3,
            ),
        )
示例#4
0
    def test_null_fields_are_accepted(self, sample_input_missing: typing.Dict[str, typing.Any]) -> None:
        output = dwelling.ParsedDwellingDataRow.from_row(sample_input_missing)

        assert output.modification_date is None
        assert output.ers_rating == measurement.Measurement(None, None)
示例#5
0
def test_measurement_to_dict() -> None:
    assert measurement.Measurement(measurement=5, upgrade=7).to_dict() == {
        'measurement': 5,
        'upgrade': 7,
    }