Select Git revision
calculation_rules-checkpoint.py
Forked from
TU-DA Fluidsystemtechnik / Public / Lehre / quality-kpi
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
calculation_rules-checkpoint.py 2.27 KiB
"""
File consists of several functions for the calculation rules of FAIR Quality KPIs
"""
from functions.classes import *
def test_function():
"""Test function to check module functionality"""
print("You called the test function.")
def kpi_mass(system: LegoAssembly)->float:
"""
Calculates the total mass of the system
Args:
system (LegoAssembly): LegoAssembly object that represents the system
Returns:
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
def kpi_availability(system):
# Calculate total delivery time by adding up each component's delivery time
total_delivery_time = sum(c.properties.get("delivery time [days]", 0) for c in system.get_component_list(-1))
# Count how many components are in the system
count = len(system.get_component_list(-1))
# Return the average delivery time or 0 if no components
return total_delivery_time / count if count > 0 else 0
def kpi_acceptance(system):
# Calculate total environmental impact by adding impact for each component based on its mass
total_environmental_impact = sum(
c.properties.get("environmental impact [kg CO2e /kg]", 0) * c.properties.get("mass [g]", 0) / 1000
for c in system.get_component_list(-1)
)
# Count how many components are in the system
count = len(system.get_component_list(-1))
# Return the average impact or 0 if no components
return total_environmental_impact / count if count > 0 else 0
if __name__ == "__main__":
"""
Function to inform that functions in this module is
intended for import not usage as script
"""
print(
"This script contains functions for calculating the FAIR Quality KPIs."
"It is not to be executed independently."
)