reviewstats: don't write 'None' if duration is unset #11
@ -9,6 +9,29 @@ class ReviewData:
|
|||||||
user_count: int
|
user_count: int
|
||||||
duration: int
|
duration: int
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return (
|
||||||
|
f"{self.date.strftime('%Y%m%d-%Hh%M')}\t{self.user_count}"
|
||||||
|
f"{f'\t{self.duration}' if self.duration is not None else ''}"
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load(line: str):
|
||||||
|
datas = re.split(r"\s+", line.strip())
|
||||||
|
if len(datas) == 2:
|
||||||
|
return ReviewData(
|
||||||
|
datetime.strptime(datas[0], "%Y%m%d-%Hh%M"),
|
||||||
|
int(datas[1]),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
|
return ReviewData(
|
||||||
|
datetime.strptime(datas[0], "%Y%m%d-%Hh%M"),
|
||||||
|
int(datas[1]),
|
||||||
|
int(datas[2]),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
def __init__(self, datas={}):
|
def __init__(self, datas={}):
|
||||||
@ -148,23 +171,7 @@ class ReviewStats:
|
|||||||
lines = file_handle.read().splitlines()
|
lines = file_handle.read().splitlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip() != "":
|
if line.strip() != "":
|
||||||
datas = re.split(r"\s+", line)
|
self.datas.append(ReviewData.load(line))
|
||||||
if len(datas) == 2:
|
|
||||||
self.datas.append(
|
|
||||||
ReviewData(
|
|
||||||
datetime.strptime(datas[0], "%Y%m%d-%Hh%M"),
|
|
||||||
int(datas[1]),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.datas.append(
|
|
||||||
ReviewData(
|
|
||||||
datetime.strptime(datas[0], "%Y%m%d-%Hh%M"),
|
|
||||||
int(datas[1]),
|
|
||||||
int(datas[2]) if datas[2]!="" else None,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# no file, no stats
|
# no file, no stats
|
||||||
pass
|
pass
|
||||||
@ -174,7 +181,4 @@ class ReviewStats:
|
|||||||
def save(self):
|
def save(self):
|
||||||
with open(self.filepath, "w") as file_handle:
|
with open(self.filepath, "w") as file_handle:
|
||||||
for data in self.datas:
|
for data in self.datas:
|
||||||
file_handle.write(
|
file_handle.write(str(data))
|
||||||
f"{data.date.strftime('%Y%m%d-%Hh%M')}\t"
|
|
||||||
f"{data.user_count}\t{data.duration}\n"
|
|
||||||
)
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
20110930-12h00 1
|
20110930-12h00 1
|
||||||
20111007-12h00 2
|
20111007-12h00 2
|
||||||
20111014-12h00 4
|
20111014-12h00 4
|
||||||
20111021-12h00 5
|
20111021-12h00 5
|
||||||
20111028-12h00 10
|
20111028-12h00 10
|
||||||
20111104-12h00 6
|
20111104-12h00 6
|
||||||
20111111-12h00 1
|
20111111-12h00 1
|
||||||
20111118-12h00 2
|
20111118-12h00 2
|
||||||
20111125-12h00 4
|
20111125-12h00 4
|
||||||
20111202-12h00 5 3
|
20111202-12h00 5 3
|
||||||
20111209-12h00 1 7
|
20111209-12h00 1 7
|
||||||
20111216-12h00 2 17
|
20111216-12h00 2 17
|
||||||
|
|
8
tests/test_review_data.py
Normal file
8
tests/test_review_data.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from review.stats import ReviewData
|
||||||
|
|
||||||
|
|
||||||
|
def test_reviewdata():
|
||||||
|
for filename in ("reviewstats_1.csv", "reviewstats_2.csv"):
|
||||||
|
with open(f"tests/datas/{filename}", "r") as review:
|
||||||
|
for line in review:
|
||||||
|
assert line == str(ReviewData.load(line))
|
Loading…
Reference in New Issue
Block a user