Newer
Older
File consists of several functions for the calculation rules of FAIR Quality KPIs
"""Test function to check module functionality"""
def kpi_mass(system: LegoAssembly)->float:
Calculates the total mass of the system
system (LegoAssembly): LegoAssembly object that represents the system
total_mass (float): Sum of masses of all components in the system in g
Raises:
TypeError: If an argument with unsupported type is passed
(i.e. anything other than LegoAssembly).
if not isinstance(system, LegoAssembly):
raise TypeError(f"Unsupported type {type(system)} passed to kpi_mass()")
total_mass = 0
for c in system.get_component_list(-1):
total_mass += c.properties["mass [g]"]
return total_mass # alternative: sum(c.properties["mass [g]"] for c in system.get_component_list(-1))
# Add new functions for calculating metrics

Rivera Alcalde, Andrés Daniel
committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def kpi_delivery_time(system: LegoAssembly)->float:
"""
Calculates the total delivery time of the system
Args:
system(LegoAssembly): LegoAssembly object that represents the system
Returns:
total_delivery_time (float): The amount of time of all components of the system it takes to arrive
Raises:
TypeError: If an argument with unsupported type is passed
(i.e. anything other than LegoAssembly).
"""
if not isinstance(system, LegoAssembly):
raise TypeError(f"Unsupported type {type(system)} passed to kpi_delivery_time()")
total_delivery_time=max(c.properties['delivery time [days]'] for c in system.get_component_list(-1))
return total_delivery_time
def kpi_total_co2_emissions(system: LegoAssembly) -> float:
"""
Calculates the total mass of CO2 emitted in the production of the system.
Args:
system (LegoAssembly): LegoAssembly object that represents the system
Returns:
total_co2_emissions (float): Sum of all CO2 emitted in the production of the system
Raises:
TypeError: If an argument with unsupported type is passed
(i.e. anything other than LegoAssembly).
"""

Rivera Alcalde, Andrés Daniel
committed
if not isinstance(system, LegoAssembly):
raise TypeError(f"Unsupported type {type(system)} passed to kpi_total_co2_emissions()")

Rivera Alcalde, Andrés Daniel
committed
total_co2_emissions = sum(
(c.properties["environmental impact [kg CO2e /kg]"] * (c.properties["mass [g]"])) / 1000

Rivera Alcalde, Andrés Daniel
committed
for c in system.get_component_list(-1)
)
return total_co2_emissions

Rivera Alcalde, Andrés Daniel
committed
def kpi_total_price(system: LegoAssembly) -> float:
"""
Calculates the total price of the system.
Args:
system (LegoAssembly): LegoAssembly object that represents the system
Returns:
total_price (float): Sum of prices of all component prices of the system
Raises:
TypeError: If an argument with unsupported type is passed
(i.e. anything other than LegoAssembly).
"""
if not isinstance(system, LegoAssembly):
raise TypeError(f"Unsupported type {type(system)} passed to kpi_total_price()")
total_price = sum(c.properties["price [Euro]"] for c in system.get_component_list(-1))
return total_price

Rivera Alcalde, Andrés Daniel
committed
if __name__ == "__main__":
"""
Function to inform that functions in this module is
intended for import not usage as script
"""
"This script contains functions for calculating the FAIR Quality KPIs."
"It is not to be executed independently."