From ed558844b69320e758ba8c7b161a720aa5a38dd1 Mon Sep 17 00:00:00 2001 From: Jules Kruijswijk Date: Tue, 9 Jun 2020 09:42:34 +0200 Subject: [PATCH] Fixed bug in base.List count function and added min function to base.List --- app/libs/base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/libs/base.py b/app/libs/base.py index 78726c8..0dd8841 100644 --- a/app/libs/base.py +++ b/app/libs/base.py @@ -366,6 +366,15 @@ def max(self): return self.random() else: return max_key + + def min(self): + """ Finds the minimum main value from all Base classes. + If there are multiple minima available (for example because all main values are 0) \ + it will return a random min + """ + d = self.get_value() + min_key = min(d, key=d.get) + return min_key def count(self): """ Checks if the Base class has a counter. If that's the case, it will @@ -375,7 +384,7 @@ def count(self): if "n" not in v.get_dict(): return 0 else: - return int(sum(v.get_dict().get("n") for v in self.base_list.values())) + return sum(int(v.get_dict().get("n")) for v in self.base_list.values()) def random(self): """ Return a random choice from the value_names list.