From f0988ace4b7f2f97c9b5df2061fdf55c69db094f Mon Sep 17 00:00:00 2001
From: "Hock, Martin" <martin.hock@fst.tu-darmstadt.de>
Date: Fri, 3 Mar 2023 09:30:42 +0100
Subject: [PATCH] Docstrings, formatting. Rewrite of sum_kpi.

---
 functions/calculation_rules.py | 40 +++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/functions/calculation_rules.py b/functions/calculation_rules.py
index 7633378..092fc43 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
-- 
GitLab