-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoring.py
More file actions
59 lines (43 loc) · 1.57 KB
/
scoring.py
File metadata and controls
59 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import datetime
import pandas as pd
import os
from os import path
CSV_DIR = 'csv'
IMAGE_DIR = 'images'
for directory in [CSV_DIR, IMAGE_DIR]:
if not path.isdir(directory):
os.makedirs(directory)
class Board:
def __init__(self, channel_id):
self.file_path = f'{CSV_DIR}/{channel_id}.csv'
self.image_path = f'{IMAGE_DIR}/{channel_id}.png'
if path.exists(self.file_path):
self.df = pd.read_csv(self.file_path, index_col=0)
self.df.index = pd.to_datetime(self.df.index)
else:
self.df = pd.DataFrame()
def __del__(self):
self.df.to_csv(self.file_path)
def add_member(self, name):
self.df[name] = 0
def add_score(self, name, score):
today = pd.to_datetime(datetime.date.today())
name = str(name)
# Insert row if not exist
if today not in self.df.index:
self.df.loc[today] = 0
# Insert column if not exist
if name not in self.df.columns:
self.add_member(name)
self.df.loc[today, name] += score
def get_timeline(self):
figure = self.df.plot(figsize=(15, 6)).get_figure()
figure.savefig(self.image_path)
return self.image_path
def clear(self):
self.df = pd.DataFrame()
def get_summary_pic(self, user_map):
df = self.df.rename(columns=user_map)
figure = df.sum().plot.barh(figsize=(15, 6)).get_figure()
figure.savefig(self.image_path)
return self.image_path