Redo category docstrings.
This commit is contained in:
+75
-11
@@ -9,18 +9,41 @@ class Category:
|
|||||||
"""Stores a category's information and relative scores."""
|
"""Stores a category's information and relative scores."""
|
||||||
|
|
||||||
def __init__(self, name: str, ascending: bool, time_record: bool, score_map: dict) -> None:
|
def __init__(self, name: str, ascending: bool, time_record: bool, score_map: dict) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for Category class.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): Category's name
|
||||||
|
ascending (bool): If category is ascending or decending
|
||||||
|
time_record (bool): If category is time record or not
|
||||||
|
score_map (dict): map of Scores
|
||||||
|
"""
|
||||||
self._name: str = name
|
self._name: str = name
|
||||||
self._ascending: bool = ascending
|
self._ascending: bool = ascending
|
||||||
self._time_record: bool = time_record
|
self._time_record: bool = time_record
|
||||||
self._scores_map: dict = score_map
|
self._scores_map: dict = score_map
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Creates a string from the class."""
|
"""
|
||||||
|
Returns Category class as a string for printing.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Category class as a string
|
||||||
|
"""
|
||||||
return json.dumps(self.to_dict(), indent=4)
|
return json.dumps(self.to_dict(), indent=4)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, name: str, data: dict):
|
def from_dict(cls, name: str, data: dict):
|
||||||
"""Fills out category from passed dictionary"""
|
"""
|
||||||
|
Creates a Category class from the passed data.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): Category name
|
||||||
|
data (dict): Rest of Category data in dictionary format
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Category: Populated Category class
|
||||||
|
"""
|
||||||
ascending = data["ascending"]
|
ascending = data["ascending"]
|
||||||
time_record = data["time_record"]
|
time_record = data["time_record"]
|
||||||
score_map = {}
|
score_map = {}
|
||||||
@@ -34,26 +57,51 @@ class Category:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ascending(self) -> bool:
|
def ascending(self) -> bool:
|
||||||
"""Getter for ascending bool."""
|
"""
|
||||||
|
Getter for is ascending
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: is ascending
|
||||||
|
"""
|
||||||
return self._ascending
|
return self._ascending
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Getter for name."""
|
"""
|
||||||
|
Getter for name.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: name
|
||||||
|
"""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def time_record(self) -> bool:
|
def time_record(self) -> bool:
|
||||||
"""Getter for time record bool."""
|
"""
|
||||||
|
Getter for is time record.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: is time record
|
||||||
|
"""
|
||||||
return self._time_record
|
return self._time_record
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scores(self) -> "list[Score]":
|
def scores(self) -> "list[Score]":
|
||||||
"""Getter for scores list."""
|
"""
|
||||||
|
Getter for Scores list.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[Score]: List of Scores in this Category
|
||||||
|
"""
|
||||||
return self._scores_map.values()
|
return self._scores_map.values()
|
||||||
|
|
||||||
def add_score(self, score: Score) -> None:
|
def add_score(self, score: Score) -> None:
|
||||||
"""Adds a score to dictionary storage. Then sorts dictionary by score value."""
|
"""
|
||||||
|
Adds score to dictionary storage map. Sorts dictionary by score value.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
score (Score): Score to be added
|
||||||
|
"""
|
||||||
if score.user in self._scores_map:
|
if score.user in self._scores_map:
|
||||||
self._scores_map[score.user].value = score.value
|
self._scores_map[score.user].value = score.value
|
||||||
else:
|
else:
|
||||||
@@ -64,20 +112,36 @@ class Category:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_user_score(self, user: str) -> Score:
|
def get_user_score(self, user: str) -> Score:
|
||||||
"""Gets a user's score. None if doesn't exist."""
|
"""
|
||||||
|
Gets a user's score. Returns None if user is not found.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user (str): Name of score to find
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Score: User's Score or None
|
||||||
|
"""
|
||||||
if user in self.scores:
|
if user in self.scores:
|
||||||
return self._scores_map[user]
|
return self._scores_map[user]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def remove_score(self, score: Score) -> None:
|
def remove_score(self, score: str) -> None:
|
||||||
"""Removes a score from dictionary storage."""
|
"""
|
||||||
score = self._scores_map.pop(score.user)
|
Removes a user's score from dictionary storage.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
score (str): user whose score to remove
|
||||||
|
"""
|
||||||
|
score = self._scores_map.pop(score)
|
||||||
del score
|
del score
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
"""
|
"""
|
||||||
Saves category data as a python dictionary.
|
Saves category data as a python dictionary.
|
||||||
Does not include category name. It should be the key of above data structure.
|
Does not include category name. It should be the key of above data structure.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Category class in dictionary format
|
||||||
"""
|
"""
|
||||||
data = {}
|
data = {}
|
||||||
data["ascending"] = self.ascending
|
data["ascending"] = self.ascending
|
||||||
|
|||||||
Reference in New Issue
Block a user