diff --git a/functions/calculation_rules.py b/functions/calculation_rules.py index 7633378a7df56a9567f90008a96876f7ed536712..092fc43faeb2308eb40199d1dd32a9fcf9f81d88 100644 --- a/functions/calculation_rules.py +++ b/functions/calculation_rules.py @@ -4,20 +4,48 @@ File consists of several functions for the calculation rules of FAIR Quality KPI def test_function(): + """Test function to check module functionality""" print("You called the test function.") -# Function to calculate KPIS that use sums -# Or function to calculate the mass with sum? + def kpi_sum(*args): - return sum(args[0]) + """ + Calculates the sum of one or more integers or lists. + + Args: + *args: One or more integers or lists. + + Returns: + total (int): The sum of all given integers and/or the sum + of all items in all given lists. + + Raises: + TypeError: If an argument with unsupported type is passed + (i.e. anything other than int or list). + """ + total = 0 + for arg in args: + if isinstance(arg, int): # Check if argument is an integer + total += arg + elif isinstance(arg, list): # Check if argument is a list + total += sum(arg) + else: + raise TypeError( + f"Unsupported type {type(arg)} passed to kpi_sum()") + return total + # if arguments are handed over not as a list: sum(list(args)) -# KPI for calculating some real complicated metric +# Add new functions for calculating some real complicated metrics 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." + "This script contains functions for calculating the FAIR Quality KPIs." + "It is not to be executed independently." ) - pass