-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
64 lines (52 loc) · 1.63 KB
/
graph.py
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
60
61
62
63
64
from matplotlib import pyplot as plt
import json
from datetime import datetime
import seaborn as sns
import os
from dotenv import load_dotenv
load_dotenv()
FRIENDS = os.getenv("FRIENDS")
with open("./output/json/algoX.json", "r") as f:
initialData = json.load(f)
data = {}
# TODO: check if u want only friends or not, (same for algoOnly)
friendsOnly = True
algoOnly = True
for user in initialData:
if algoOnly and initialData[user]["algo"] == 0:
continue
if friendsOnly and user not in FRIENDS:
continue
# if user in ["darelife", "harshb", "acsde", "garam_icecream", "Centelle", "Aashman", "LightHouse1"]:
data[user] = initialData[user]["ratingHistory"]
"""
Data:
-> {user:[{rating, time(unix), rank},...], ...}
We need to plot a multi-line graph (rating vs time) with the following data:
"""
def plot_graph(data):
# sns.set_theme()
sns.set_theme(style="darkgrid")
for user in data:
ratings = []
times = []
for x in data[user]:
# 1640975401
# 1672511401
if x["time"] < 1640975401:
continue
ratings.append(x["rating"])
times.append(datetime.fromtimestamp(int(x["time"])))
# ratings = [x["rating"] for x in data[user]]
# times = [datetime.fromtimestamp(int(x["time"])) for x in data[user]]
plt.plot(times, ratings, label=user)
plt.xlabel("Timeee")
plt.ylabel("Rating")
plt.legend()
# increase the pixel size of the graph
fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
# plt.xticks(rotation=45)
plt.savefig("ratingVsTime.png")
plt.show()
plot_graph(data)