Skip to content

Commit

Permalink
Fixed bug in base.List count function and added min function to base.…
Browse files Browse the repository at this point in the history
…List
  • Loading branch information
g0ulash committed Jun 9, 2020
1 parent 7d42a97 commit ed55884
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/libs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit ed55884

Please sign in to comment.