Add category class.
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user