Skip to content

Commit

Permalink
Fix colormapping of problem plot
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellDash332 committed Aug 6, 2023
1 parent cb1959c commit 3a43722
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ where `'username'` is your Kattis username/email and `'password'` is your Kattis
kt.problems() # problems you have solved so far
kt.problems(show_partial=False) # exclude partial submissions
kt.problems(*[True]*4) # literally all problems on Kattis

kt.list_unsolved() # let's grind!

kt.plot_problems() # plot the points distribution
Expand Down
13 changes: 10 additions & 3 deletions autokattis/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def problems(self, show_solved=True, show_partial=True, show_tried=False, show_u
# for example:
# - difficulty 9.1-9.6 -> [9.1, 9.6]
# - difficulty 5.0 -> [5.0]
category = re.findall('[A-Za-z]+', columns[7].text)[0]
try: category = re.findall('[A-Za-z]+', columns[7].text)[0]
except: category = 'N/A'
data.append({
'name': name,
'fastest': fastest,
Expand All @@ -127,8 +128,14 @@ def plot_problems(self, filepath=None, show_solved=True, show_partial=True, show
'''

df = pd.DataFrame(self.problems(show_solved, show_partial, show_tried, show_untried))
hist = sns.histplot(data=df, x='difficulty', hue='category', multiple='stack', binwidth=0.1)
hist.set(title=f'Solved Kattis Problems ({df.shape[0]})', xlabel='Difficulty')
categories = set(df.category)
hue_order = [c for c in ['Easy', 'Medium', 'Hard', 'N/A'][::-1] if c in categories]
palette = {'Easy': '#39a137', 'Medium': '#ffbe00', 'Hard': '#ff411a', 'N/A': 'gray'}
for c in [*palette]:
if c not in categories: del palette[c]
hist = sns.histplot(data=df, x='difficulty', hue='category', multiple='stack', binwidth=0.1, hue_order=hue_order, palette=palette)
hist.set(title=f'Solved Kattis Problems by {self.user} ({df.shape[0]})', xlabel='Difficulty')
plt.legend(title='Category', loc='upper right', labels=hue_order[::-1])
plt.xticks([*range(math.floor(min(df.difficulty)), math.ceil(max(df.difficulty))+1)])
if filepath != None:
plt.savefig(filepath)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup_args = dict(
name='autokattis',
version='1.4.5',
version='1.4.6',
description='Updated Kattis API wrapper',
long_description_content_type="text/markdown",
long_description=README,
Expand Down
3 changes: 2 additions & 1 deletion test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
kt.problems(), # problems you have solved so far
kt.problems(show_partial=False), # exclude partial submissions
kt.problems(*[True]*4), # literally all problems on Kattis
kt.list_unsolved(), # let's grind!

kt.list_unsolved(), # let's grind!

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

0 comments on commit 3a43722

Please # to comment.