From bac64110c1500271647fdccec24b329061fc628b Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Sat, 30 Jul 2022 22:31:40 -0400 Subject: [PATCH] Add category class. --- data/category.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 data/category.py diff --git a/data/category.py b/data/category.py new file mode 100644 index 0000000..894be21 --- /dev/null +++ b/data/category.py @@ -0,0 +1,45 @@ +"""File for Category class.""" + +from data.score import Score # pylint: disable=import-error + + +class Category: + """Stores a category's information and relative scores.""" + + def __init__(self, name: str, ascending: bool, time_record: bool) -> None: + self._name = name + self._ascending = ascending + self._time_record = time_record + self._scores: dict(Score) = {} + + @property + def ascending(self) -> bool: + """Getter for ascending bool.""" + return self._ascending + + @property + def name(self) -> str: + """Getter for name.""" + return self._name + + @property + def time_record(self) -> bool: + """Getter for time record bool.""" + return self._time_record + + @property + def scores(self) -> "list[Score]": + """Getter for scores list.""" + return self._scores.values() + + def add_score(self, score: Score) -> None: + """Adds a score to dictionary storage. Sorts dictionary by score value.""" + self._scores[score.user] = score + + self._scores = dict( + sorted(self._scores.items(), key=lambda x: x[1].score, reverse=not self.ascending) + ) + + def remove_score(self, score: Score) -> None: + """Removes a score from dictionary storage.""" + self._scores.pop(score.user)