Add default values when there are no consumption and therefore no emissions can be calculated
This commit is contained in:
parent
d23de74ed3
commit
42d881dbb4
@ -22,6 +22,8 @@ class Co2Emission:
|
|||||||
cte.RENEWABLE: 0}
|
cte.RENEWABLE: 0}
|
||||||
self._emissions_factor = emissions_factor
|
self._emissions_factor = emissions_factor
|
||||||
self._building = building
|
self._building = building
|
||||||
|
self._year = [0]
|
||||||
|
self._month = [0 for _ in range(12)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def building(self) -> Building:
|
def building(self) -> Building:
|
||||||
@ -63,11 +65,23 @@ class Co2Emission:
|
|||||||
values = [v * emission_factor for v in self._building.lighting_electrical_demand[time_period]]
|
values = [v * emission_factor for v in self._building.lighting_electrical_demand[time_period]]
|
||||||
results_by_time_period[time_period] = values
|
results_by_time_period[time_period] = values
|
||||||
results[cte.LIGHTING] = results_by_time_period
|
results[cte.LIGHTING] = results_by_time_period
|
||||||
|
|
||||||
results_by_time_period = {}
|
results_by_time_period = {}
|
||||||
for time_period in self._building.appliances_electrical_demand:
|
for time_period in self._building.appliances_electrical_demand:
|
||||||
values = [v * emission_factor for v in self._building.appliances_electrical_demand[time_period]]
|
values = [v * emission_factor for v in self._building.appliances_electrical_demand[time_period]]
|
||||||
results_by_time_period[time_period] = values
|
results_by_time_period[time_period] = values
|
||||||
results[cte.APPLIANCES] = results_by_time_period
|
results[cte.APPLIANCES] = results_by_time_period
|
||||||
|
|
||||||
|
if cte.HEATING not in results:
|
||||||
|
results[cte.HEATING] = {cte.YEAR: self._year, cte.MONTH: self._month}
|
||||||
|
if cte.COOLING not in results:
|
||||||
|
results[cte.COOLING] = {cte.YEAR: self._year, cte.MONTH: self._month}
|
||||||
|
if cte.ELECTRICITY not in results:
|
||||||
|
results[cte.ELECTRICITY] = {cte.YEAR: self._year, cte.MONTH: self._month}
|
||||||
|
if cte.LIGHTING not in results:
|
||||||
|
results[cte.LIGHTING] = {cte.YEAR: self._year, cte.MONTH: self._month}
|
||||||
|
if cte.APPLIANCES not in results:
|
||||||
|
results[cte.APPLIANCES] = {cte.YEAR: self._year, cte.MONTH: self._month}
|
||||||
|
if cte.DOMESTIC_HOT_WATER not in results:
|
||||||
|
results[cte.DOMESTIC_HOT_WATER] = {cte.YEAR: self._year, cte.MONTH: self._month}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
@ -62,6 +62,7 @@ class UnitTests(unittest.TestCase):
|
|||||||
for building in self.init.city.buildings:
|
for building in self.init.city.buildings:
|
||||||
result = Co2Emission(building).operational_co2
|
result = Co2Emission(building).operational_co2
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
|
print(result)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
files = glob.glob('output/[!.]*')
|
files = glob.glob('output/[!.]*')
|
||||||
|
Loading…
Reference in New Issue
Block a user