autokattis
Updated Kattis API wrapper as of May 2023 after the major UI/UX change.
Setup
Simply install it as a Python package.
$ pip install autokattis
Use Cases
For now, this package supports OpenKattis
and NUSKattis
.
Login
Construct an OpenKattis
object that takes in the username and the password.
from autokattis import OpenKattis
kt = OpenKattis('username', 'password')
kt = OpenKattis('username')
where 'username'
is your Kattis username/email and 'password'
is your Kattis account password. Both should be provided as Python strings.
Similarly if you want to login to NUS Kattis.
from autokattis import NUSKattis
kt = NUSKattis('username', 'password')
kt = NUSKattis('username')
OpenKattis
Due to backwards compatibility, you can still use Kattis
as a shorthand form of OpenKattis
.
Problem-specific
kt.problems()
kt.problems(show_partial=False)
kt.problems(low_detail_mode=False)
kt.problems(*[True]*4)
kt.plot_problems()
kt.plot_problems(filepath='plot.png')
kt.plot_problems(show_partial=False)
kt.problem('2048')
kt.problem(['2048', 'abinitio', 'dasort'])
kt.problem({'2048', 'abinitio', 'dasort'})
kt.problem('2048', download_files=True)
kt.stats()
kt.stats('Java')
kt.stats(('Python3', 'Cpp'))
kt.suggest()
kt.achievements()
kt.problem_authors()
kt.problem_sources()
Ranklist
kt.ranklist()
kt.user_ranklist()
kt.challenge_ranklist()
kt.country_ranklist()
kt.country_ranklist('Singapore')
kt.country_ranklist('SGP')
kt.university_ranklist()
kt.university_ranklist(university='National University of Singapore')
kt.university_ranklist(university='nus.edu.sg')
NUSKattis
Problem-specific
kt.problems()
kt.problems(show_solved=False)
kt.problem('2048')
kt.problem(['2048', 'abinitio', 'dasort'])
kt.problem({'2048', 'abinitio', 'dasort'})
kt.problem('2048', download_files=True)
kt.stats()
kt.stats('Java')
kt.stats(('Python3', 'Cpp'))
Course-specific
kt.courses()
kt.offerings('CS3233')
kt.assignments('CS3233_S2_AY2223')
kt.assignments('CS3233_S2_AY2223', 'CS3233')
Convert to DataFrame
As simple as adding .to_df()
!
kt.problems().to_df()
kt.ranklist().to_df()
Other Scenarios
Some scenarios you can perform when using autokattis
:
- Mapping problem ID with its difficulty
okt = OpenKattis(...)
df = okt.problems().to_df()
diff_map = dict(zip(df.id, df.difficulty))
- Find the number of questions on every assignment on an NUS course offering
nkt = NUSKattis(...)
df = nkt.assignments('CS3233_S2_AY2324').to_df()
df['n_problems'] = df['problems'].apply(lambda x: len(x.split(',')))
df[['name', 'n_problems']]
- Find the average difficulty of every assignment on an NUS course offering
diff_map = ...
nkt = NUSKattis(...)
avg_2dp = lambda x: round(sum(y:=[v for v in x if v != None])/max(len(y), 1), 2)
df = nkt.assignments('CS3233_S2_AY2324').to_df()
df['avg_diff'] = df['problems'].apply(lambda x: avg_2dp(map(diff_map.get, x.split(','))))
df[['name', 'avg_diff']]
- Group top 100 users by country
okt = OpenKattis(...)
okt.user_ranklist().to_df().groupby('country').size()
More Information
The docstrings might be a great help if you want to know more about the JSON return values!
from autokattis import OpenKattis
help(OpenKattis)
Testing
The test
directory is provided within this repository. You are free to test autokattis
with these anytime.
>>> python test/openkattis.py
...
>>> python test/nuskattis.py
...
Useful References
Contributing
Feel free to suggest anything or add on some implementation by simply creating a pull request!