def test_from_data() -> None: insulation = '50;2;50;5' heat_lost = 10 wall = walls.Wall.from_data(insulation, heat_lost) assert wall == walls.Wall(insulation=[ composite.CompositeValue(percentage=50.0, value=2.0, value_name='rValue'), composite.CompositeValue(percentage=50.0, value=5.0, value_name='rValue'), ], heat_lost=10)
def from_data(cls, insulation: typing.Optional[str], heat_lost: typing.Optional[float]) -> 'Wall': if insulation: args = [iter(insulation.split(';'))] * 2 groups = itertools.zip_longest(fillvalue='0', *args) try: composite_insulation = [ composite.CompositeValue( percentage=float(percentage), value=float(r_value), value_name='rValue', ) for percentage, r_value in groups ] except ValueError as exc: raise InvalidEmbeddedDataTypeError(Wall, 'Invalid composite insulation string') from exc else: composite_insulation = [] return Wall( insulation=composite_insulation, heat_lost=heat_lost )
def test_to_dict() -> None: wall = walls.Wall(insulation=[ composite.CompositeValue(percentage=50.0, value=2.0, value_name='rValue'), composite.CompositeValue(percentage=50.0, value=5.0, value_name='rValue'), ], heat_lost=10) assert wall.to_dict() == { 'insulation': [{ 'percentage': 50.0, 'rValue': 2.0, }, { 'percentage': 50.0, 'rValue': 5.0, }], 'heatLost': 10 }
def from_data(cls, insulation: typing.Optional[str], heat_lost: typing.Optional[float]) -> 'Wall': if insulation: args = [iter(insulation.split(';'))] * 2 groups = itertools.zip_longest(fillvalue='0', *args) composite_insulation = [ composite.CompositeValue( percentage=float(percentage), value=float(r_value), value_name='rValue', ) for percentage, r_value in groups ] else: composite_insulation = [] return Wall( insulation=composite_insulation, heat_lost=heat_lost )
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, ), )