Skip to content

Commit 3a43722

Browse files
Fix colormapping of problem plot
1 parent cb1959c commit 3a43722

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ where `'username'` is your Kattis username/email and `'password'` is your Kattis
2929
kt.problems() # problems you have solved so far
3030
kt.problems(show_partial=False) # exclude partial submissions
3131
kt.problems(*[True]*4) # literally all problems on Kattis
32+
3233
kt.list_unsolved() # let's grind!
3334

3435
kt.plot_problems() # plot the points distribution

autokattis/api/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def problems(self, show_solved=True, show_partial=True, show_tried=False, show_u
106106
# for example:
107107
# - difficulty 9.1-9.6 -> [9.1, 9.6]
108108
# - difficulty 5.0 -> [5.0]
109-
category = re.findall('[A-Za-z]+', columns[7].text)[0]
109+
try: category = re.findall('[A-Za-z]+', columns[7].text)[0]
110+
except: category = 'N/A'
110111
data.append({
111112
'name': name,
112113
'fastest': fastest,
@@ -127,8 +128,14 @@ def plot_problems(self, filepath=None, show_solved=True, show_partial=True, show
127128
'''
128129

129130
df = pd.DataFrame(self.problems(show_solved, show_partial, show_tried, show_untried))
130-
hist = sns.histplot(data=df, x='difficulty', hue='category', multiple='stack', binwidth=0.1)
131-
hist.set(title=f'Solved Kattis Problems ({df.shape[0]})', xlabel='Difficulty')
131+
categories = set(df.category)
132+
hue_order = [c for c in ['Easy', 'Medium', 'Hard', 'N/A'][::-1] if c in categories]
133+
palette = {'Easy': '#39a137', 'Medium': '#ffbe00', 'Hard': '#ff411a', 'N/A': 'gray'}
134+
for c in [*palette]:
135+
if c not in categories: del palette[c]
136+
hist = sns.histplot(data=df, x='difficulty', hue='category', multiple='stack', binwidth=0.1, hue_order=hue_order, palette=palette)
137+
hist.set(title=f'Solved Kattis Problems by {self.user} ({df.shape[0]})', xlabel='Difficulty')
138+
plt.legend(title='Category', loc='upper right', labels=hue_order[::-1])
132139
plt.xticks([*range(math.floor(min(df.difficulty)), math.ceil(max(df.difficulty))+1)])
133140
if filepath != None:
134141
plt.savefig(filepath)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup_args = dict(
77
name='autokattis',
8-
version='1.4.5',
8+
version='1.4.6',
99
description='Updated Kattis API wrapper',
1010
long_description_content_type="text/markdown",
1111
long_description=README,

test/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
kt.problems(), # problems you have solved so far
1010
kt.problems(show_partial=False), # exclude partial submissions
1111
kt.problems(*[True]*4), # literally all problems on Kattis
12-
kt.list_unsolved(), # let's grind!
12+
13+
kt.list_unsolved(), # let's grind!
1314

1415
kt.plot_problems(), # plot the points distribution
1516
kt.plot_problems(filepath='plot.png'), # save to a filepath

0 commit comments

Comments
 (0)