-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.py
96 lines (86 loc) · 2.99 KB
/
analysis.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
# dark mode toggle
darkmode = False
# theme colors
class Colors:
alpha = "dd"
GREEN = "#32a852" + alpha
YELLOW = "#c9a132" + alpha
RED = "#ad2626" + alpha
BLUE = "#3399ff" + alpha
BACKGROUND = (0.133, 0.153, 0.18) if darkmode else None
# creates a pie chart from an iterable
def agr_pie(lst, labels=None, colors=None, title=None):
plt.figure().patch.set_facecolor(Colors.BACKGROUND)
lst = list(lst)
if labels == None:
labels = list(set(lst))
plt.pie(
list( [lst.count(val) for val in labels] ),
labels = list(
[f"{label}\n{lst.count(label)} ({round(lst.count(label)/len(lst)*100, 1)}%)" for label in labels]
),
colors = colors,
labeldistance = 0.5,
)
plt.tight_layout()
title_obj = plt.title(title, fontweight="bold")
plt.setp(title_obj, color='gray')
# saves current fig to a given file
def saveplot(filename):
plt.savefig(
f'analysis_visualizations/{filename}',
transparent=True,
bbox_inches = 'tight',
pad_inches=0
)
# global formatting
matplotlib.rcParams['text.color'] = 'w'
matplotlib.rcParams['font.family'] = 'sans-serif'
matplotlib.rcParams['font.sans-serif'] = 'Segoe UI'
matplotlib.rcParams['font.size'] = '12'
matplotlib.rcParams['font.weight'] = 'bold'
matplotlib.rc('axes',edgecolor='gray')
# import data
df = pd.read_csv('analysis.csv')
# solved problems by difficulty
agr_pie(
df[df["Solved?"]=="Yes"]["Difficulty"],
labels=["Easy", "Medium", "Hard"],
colors=[Colors.GREEN, Colors.YELLOW, Colors.RED],
title="Solved problems by difficulty",
)
saveplot("pie_difficulty.png")
# does a more optimized solution exist?
agr_pie(
df["Better optimization?"],
labels=["Yes", "No"],
colors=[Colors.RED, Colors.GREEN],
title="Does a more optimized solution exist?",
)
saveplot("pie_optimization.png")
# problems solved out of attempted
agr_pie(
["Solved" if i < len(df[df["Solved?"]=="Yes"]) else "Failed" for i in range(len(df))],
labels=["Solved", "Failed"],
colors=[Colors.GREEN, Colors.RED],
title="How many solved of those attempted?",
)
saveplot("pie_attempt.png")
# Time taken to solve problem by difficulty
plt.figure(figsize=(13, 4))
plt.hist(df[df["Difficulty"]=="Easy"]["Stopwatch"], bins=range(0,130,5), facecolor=Colors.GREEN, density=1, alpha=0.5)
plt.hist(df[df["Difficulty"]=="Medium"]["Stopwatch"], bins=range(0,130,5), facecolor=Colors.YELLOW, density=1, alpha=0.5)
plt.hist(df[df["Difficulty"]=="Hard"]["Stopwatch"], bins=range(0,120,5), facecolor=Colors.RED, density=1, alpha=0.5)
plt.tight_layout()
text_objs = []
text_objs.append(plt.title("Histogram of time taken to solve problem by difficulty", fontweight="bold"))
text_objs.append(plt.xlabel("Time (min)"))
text_objs.append(plt.ylabel("Density"))
for t in text_objs:
plt.setp(t, color='gray')
plt.tick_params(axis='x', colors='gray')
plt.tick_params(axis='y', colors='gray')
saveplot("hist.png")