Пример #1
0
def _validated(row: typing.Dict[str, typing.Any],
               validator: cerberus.Validator) -> typing.Dict[str, typing.Any]:
    if not validator.validate(row):
        error_keys = ', '.join(validator.errors.keys())
        raise InvalidInputDataError(
            f'Validator failed on keys: {error_keys} for {row.get("BUILDER")}')
    return validator.document
Пример #2
0
 def from_code(cls, code: str) -> 'EvaluationType':
     if code == cls.PRE_RETROFIT.value:
         return EvaluationType.PRE_RETROFIT
     elif code == cls.POST_RETROFIT.value:
         return EvaluationType.POST_RETROFIT
     else:
         raise InvalidInputDataError(f'Invalid code: {code}')
Пример #3
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'],
            ),
        )
Пример #4
0
    def from_row(cls, row: typing.Dict[str, typing.Any]) -> 'ParsedDwellingDataRow':
        checker = validator.DwellingValidator(cls._SCHEMA, allow_unknown=True)
        if not checker.validate(row):
            error_keys = ', '.join(checker.errors.keys())
            raise InvalidInputDataError(f'Validator failed on keys: {error_keys}')

        parsed = checker.document
        codes = code.Codes.from_data(parsed['codes'])

        foundations = []
        foundations.extend(
            [basement.Basement.from_data(basement_node) for basement_node in parsed['basements']]
        )
        foundations.extend(
            [basement.Basement.from_data(crawlspace_node) for crawlspace_node in parsed['crawlspaces']]
        )
        foundations.extend(
            [basement.Basement.from_data(slab_node) for slab_node in parsed['slabs']]
        )

        return ParsedDwellingDataRow(
            eval_id=parsed['EVAL_ID'],
            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'],
            ceilings=[ceiling.Ceiling.from_data(ceiling_node) for ceiling_node in parsed['ceilings']],
            floors=[floor.Floor.from_data(floor_node) for floor_node in parsed['floors']],
            walls=[wall.Wall.from_data(wall_node, codes.wall) for wall_node in parsed['walls']],
            doors=[door.Door.from_data(door_node) for door_node in parsed['doors']],
            windows=[window.Window.from_data(window_node, codes.window) for window_node in parsed['windows']],
            heated_floor=heated_floor_area.HeatedFloorArea.from_data(parsed['heatedFloorArea'])
            if parsed['heatedFloorArea'] is not None else None,

            water_heatings=water_heating.WaterHeating.from_data(parsed['waterHeatings'])
            if parsed['waterHeatings'] is not None else [],

            ventilations=[ventilation.Ventilation.from_data(ventilation_node)
                          for ventilation_node in parsed['ventilations']],
            heating_system=heating.Heating.from_data(parsed['heating_cooling'])
            if parsed['heating_cooling'] is not None else None,

            foundations=foundations,
            ers_rating=parsed['ersRating'],
            energy_upgrades=[upgrade.Upgrade.from_data(upgrade_node) for upgrade_node in parsed['upgrades']],
            file_id=parsed['BUILDER'],
        )
Пример #5
0
    def _from_parsed_group(cls, data: typing.List[ParsedDwellingDataRow]) -> 'Dwelling':
        if len(data) == 1 and data[0].eval_type is EvaluationType.POST_RETROFIT:
            raise InvalidInputDataError('Only Pre-retrofit evaluations are allowed a group size of 1')

        if len(data) == 1 or len(data) == 2:
            evaluations = [Evaluation.from_data(row) for row in data]
            return Dwelling(
                house_id=data[0].eval_id,
                year_built=data[0].year_built,
                city=data[0].city,
                region=data[0].region,
                forward_sortation_area=data[0].forward_sortation_area,
                evaluations=evaluations,
            )
        else:
            raise InvalidGroupSizeError(f'Invalid group size "{len(data)}". Groups must be size 1 or 2')