added Machine and Vehicle classes to Life Cycle Assessment
This commit is contained in:
parent
0439ab0cd2
commit
97ec2a1436
78
city_model_structure/machine.py
Normal file
78
city_model_structure/machine.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
"""
|
||||
LifeCycleAssessment retrieve the specific Life Cycle Assessment module for the given region
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2020 Project Author Atiya
|
||||
"""
|
||||
|
||||
class Machine:
|
||||
"""
|
||||
Machine class
|
||||
"""
|
||||
|
||||
def __init__(self, machine_id, name, work_efficiency, work_efficiency_unit, energy_consumption_rate, energy_consumption_unit,
|
||||
carbon_emission_factor, carbon_emission_unit):
|
||||
self._machine_id = machine_id
|
||||
self._name = name
|
||||
self._work_efficiency = work_efficiency
|
||||
self._work_efficiency_unit = work_efficiency_unit
|
||||
self._energy_consumption_rate = energy_consumption_rate
|
||||
self._energy_consumption_unit = energy_consumption_unit
|
||||
self._carbon_emission_factor = carbon_emission_factor
|
||||
self._carbon_emission_unit = carbon_emission_unit
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Get machine id
|
||||
"""
|
||||
return self._machine_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Get machine name
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def work_efficiency(self):
|
||||
"""
|
||||
Get machine work efficiency
|
||||
"""
|
||||
return self._work_efficiency
|
||||
|
||||
@property
|
||||
def work_efficiency_unit(self):
|
||||
"""
|
||||
Get machine work efficiency unit
|
||||
"""
|
||||
return self._work_efficiency_unit
|
||||
|
||||
@property
|
||||
def energy_consumption_rate(self):
|
||||
"""
|
||||
Get energy consumption rate
|
||||
"""
|
||||
return self._energy_consumption_rate
|
||||
|
||||
@property
|
||||
def energy_consumption_unit(self):
|
||||
"""
|
||||
Get energy consumption unit
|
||||
"""
|
||||
return self._energy_consumption_unit
|
||||
|
||||
@property
|
||||
def carbon_emission_factor(self):
|
||||
"""
|
||||
Get carbon emission factor
|
||||
"""
|
||||
return self._carbon_emission_factor
|
||||
|
||||
@property
|
||||
def carbon_emission_unit(self):
|
||||
"""
|
||||
Get carbon emission unit
|
||||
"""
|
||||
return self._carbon_emission_unit
|
||||
|
61
city_model_structure/vehicle.py
Normal file
61
city_model_structure/vehicle.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
"""
|
||||
LifeCycleAssessment retrieve the specific Life Cycle Assessment module for the given region
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2020 Project Author Atiya
|
||||
"""
|
||||
|
||||
class Vehicle:
|
||||
"""
|
||||
Vehicle class
|
||||
"""
|
||||
|
||||
def __init__(self, vehicle_id, name, fuel_consumption_rate, fuel_consumption_unit, carbon_emission_factor, carbon_emission_factor_unit):
|
||||
self._vehicle_id = vehicle_id
|
||||
self._name = name
|
||||
self._fuel_consumption_rate = fuel_consumption_rate
|
||||
self._fuel_consumption_unit = fuel_consumption_unit
|
||||
self._carbon_emission_factor = carbon_emission_factor
|
||||
self._carbon_emission_factor_unit = carbon_emission_factor_unit
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Get vehicle id
|
||||
"""
|
||||
return self._vehicle_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Get vehicle name
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def fuel_consumption_rate(self):
|
||||
"""
|
||||
Get vehicle fuel consumption rate
|
||||
"""
|
||||
return self._fuel_consumption_rate
|
||||
|
||||
@property
|
||||
def fuel_consumption_unit(self):
|
||||
"""
|
||||
Get fuel consumption unit
|
||||
"""
|
||||
return self._fuel_consumption_unit
|
||||
|
||||
@property
|
||||
def carbon_emission_factor(self):
|
||||
"""
|
||||
Get vehicle carbon emission factor
|
||||
"""
|
||||
return self._carbon_emission_factor
|
||||
|
||||
@property
|
||||
def carbon_emission_unit(self):
|
||||
"""
|
||||
Get carbon emission units
|
||||
"""
|
||||
return self._carbon_emission_unit
|
||||
|
|
@ -19,6 +19,6 @@ class LcaFuel:
|
|||
|
||||
with open(path) as xml:
|
||||
self._lca = xmltodict.parse(xml.read())
|
||||
for fuel in self._lca["library"]["Fuels"]['fuel']:
|
||||
for fuel in self._lca["library"]["fuels"]['fuel']:
|
||||
self._city.fuels.append(Fuel(fuel['@id'], fuel['@name'], fuel['carbon_emission_factor']['#text'],
|
||||
fuel['carbon_emission_factor']['@unit']))
|
26
imports/life_cycle_assessment/lca_machine.py
Normal file
26
imports/life_cycle_assessment/lca_machine.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
"""
|
||||
CityGml module parses citygml_classes files and import the geometry into the city model structure
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2020 Project Author Atiya
|
||||
"""
|
||||
import xmltodict
|
||||
from pathlib import Path
|
||||
from city_model_structure.machine import Machine
|
||||
|
||||
class LcaMachine:
|
||||
def __init__(self, city, base_path):
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
self._lca = None
|
||||
|
||||
def enrich(self):
|
||||
self._city.machines = []
|
||||
path = Path(self._base_path / 'lca_data.xml').resolve()
|
||||
|
||||
with open(path) as xml:
|
||||
self._lca = xmltodict.parse(xml.read())
|
||||
for machine in self._lca["library"]["machines"]['machine']:
|
||||
self._city.machines.append(Machine(machine['@id'], machine['@name'], machine['work_efficiency']['#text'],
|
||||
machine['work_efficiency']['@unit'], machine['energy_consumption_rate']['#text'],
|
||||
machine['energy_consumption_rate']['@unit'], machine['carbon_emission_factor']['#text'],
|
||||
machine['carbon_emission_factor']['@unit']))
|
25
imports/life_cycle_assessment/lca_vehicle.py
Normal file
25
imports/life_cycle_assessment/lca_vehicle.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""
|
||||
CityGml module parses citygml_classes files and import the geometry into the city model structure
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2020 Project Author Atiya
|
||||
"""
|
||||
import xmltodict
|
||||
from pathlib import Path
|
||||
from city_model_structure.vehicle import Vehicle
|
||||
|
||||
class LcaVehicle:
|
||||
def __init__(self, city, base_path):
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
self._lca = None
|
||||
|
||||
def enrich(self):
|
||||
self._city.vehicles = []
|
||||
path = Path(self._base_path / 'lca_data.xml').resolve()
|
||||
|
||||
with open(path) as xml:
|
||||
self._lca = xmltodict.parse(xml.read())
|
||||
for vehicle in self._lca["library"]["vehicles"]['vehicle']:
|
||||
self._city.vehicles.append(Vehicle(vehicle['@id'], vehicle['@name'], vehicle['fuel_consumption_rate']['#text'],
|
||||
vehicle['fuel_consumption_rate']['@unit'], vehicle['carbon_emission_factor']['#text'],
|
||||
vehicle['carbon_emission_factor']['@unit']))
|
|
@ -5,16 +5,18 @@ Copyright © 2020 Project Author Atiya
|
|||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from imports.life_cicle_analize.lca_fuel import LcaFuel
|
||||
from imports.life_cycle_assessment.lca_fuel import LcaFuel
|
||||
from imports.life_cycle_assessment.lca_vehicle import LcaVehicle
|
||||
from imports.life_cycle_assessment.lca_machine import LcaMachine
|
||||
|
||||
|
||||
class LifeCicleAnalizeFactory:
|
||||
class LifeCycleAssessment:
|
||||
"""
|
||||
Life cicle analize factory class
|
||||
"""
|
||||
def __init__(self, handler, city, base_path=None):
|
||||
if base_path is None:
|
||||
base_path = Path(Path(__file__).parent.parent / 'data/construction')
|
||||
base_path = Path(Path(__file__).parent.parent / 'data/life_cycle_assessment')
|
||||
self._handler = '_' + handler.lower().replace(' ', '_')
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
|
@ -25,6 +27,18 @@ class LifeCicleAnalizeFactory:
|
|||
"""
|
||||
LcaFuel(self._city, self._base_path).enrich()
|
||||
|
||||
def _vehicle(self):
|
||||
"""
|
||||
Enrich the city by adding the vehicle carbon information
|
||||
"""
|
||||
LcaVehicle(self._city, self._base_path).enrich()
|
||||
|
||||
def _machine(self):
|
||||
"""
|
||||
Enrich the city by adding the machine carbon information
|
||||
"""
|
||||
LcaMachine(self._city, self._base_path).enrich()
|
||||
|
||||
def enrich(self):
|
||||
"""
|
||||
Enrich the city given to the class using the class given handler
|
50
unittests/test_life_cycle_assessment_factory.py
Normal file
50
unittests/test_life_cycle_assessment_factory.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
Building test
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2020 Project Author Guille Gutierrez Morote Guillermo.GutierrezMorote@concordia.ca
|
||||
"""
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
from imports.geometry_factory import GeometryFactory
|
||||
from imports.life_cycle_assessment_factory import LifeCycleAssessment
|
||||
|
||||
|
||||
class TestLifeCycleAssessment(TestCase):
|
||||
"""
|
||||
TestBuilding TestCase 1
|
||||
"""
|
||||
def setUp(self) -> None:
|
||||
"""
|
||||
Test setup
|
||||
:return: None
|
||||
"""
|
||||
self._city_gml = None
|
||||
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
||||
|
||||
def test_fuel(self):
|
||||
city_file = "../unittests/tests_data/C40_Final.gml"
|
||||
city = GeometryFactory('citygml', city_file).city
|
||||
LifeCycleAssessment('fuel', city).enrich()
|
||||
for fuel in city.fuels:
|
||||
# print(fuel.name)
|
||||
self.assertTrue(len(city.fuels) > 0)
|
||||
|
||||
def test_vehicle(self):
|
||||
city_file = "../unittests/tests_data/C40_Final.gml"
|
||||
city = GeometryFactory('citygml', city_file).city
|
||||
LifeCycleAssessment('vehicle', city).enrich()
|
||||
for vehicle in city.vehicles:
|
||||
# print(vehicle.name)
|
||||
self.assertTrue(len(city.vehicles) > 0)
|
||||
|
||||
def test_machine(self):
|
||||
city_file = "../unittests/tests_data/C40_Final.gml"
|
||||
city = GeometryFactory('citygml', city_file).city
|
||||
LifeCycleAssessment('machine', city).enrich()
|
||||
for machine in city.machines:
|
||||
# print(machine.name)
|
||||
self.assertTrue(len(city.machines) > 0)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user