diff --git a/review/stats.py b/review/stats.py index 89e341a..472a175 100644 --- a/review/stats.py +++ b/review/stats.py @@ -11,7 +11,7 @@ class ReviewData: class Board: - def __init__(self, datas): + def __init__(self, datas={}): self.datas = {} self.init(datas) @@ -34,43 +34,46 @@ class Board: @property def min(self): - if self.datas == []: + if self.datas == {}: return 0 - return min(self.datas.values()) + return min(self.datas.keys()) @property def max(self): - if self.datas == []: + if self.datas == {}: return 0 - return max(self.datas.values()) + return max(self.datas.keys()) @property def avg(self): - if self.datas == []: + if self.datas == {}: return 0 - return self.sum / len(self.datas) + return self.sum / sum(self.datas.values()) @property def sum(self): - if self.datas == []: - return 0 - return sum(self.datas.values()) + result = 0 + for data in self.datas: + result += self.datas[data] * data + return result class UserBoard(Board): def init(self, datas): for data in datas: - if data.user_count not in self.datas: - self.datas[data.user_count] = 0 - self.datas[data.user_count] += 1 + if data.user_count is not None: + if data.user_count not in self.datas: + self.datas[data.user_count] = 0 + self.datas[data.user_count] += 1 class DurationBoard(Board): def init(self, datas): for data in datas: - if data.duration not in self.datas: - self.datas[data.duration] = 0 - self.datas[data.duration] += 1 + if data.duration is not None: + if data.duration not in self.datas: + self.datas[data.duration] = 0 + self.datas[data.duration] += 1 class ReviewStats: @@ -159,7 +162,7 @@ class ReviewStats: ReviewData( datetime.strptime(datas[0], "%Y%m%d-%Hh%M"), int(datas[1]), - int(datas[2]), + int(datas[2]) if datas[2]!="" else None, ) ) except FileNotFoundError: