Updated Kattis API wrapper
Project description
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') # which will then prompt you for the password
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
Kattisas a shorthand form ofOpenKattis.
Problem-specific
kt.problems() # problems you have solved so far
kt.problems(show_partial=False) # exclude partial submissions
kt.problems(low_detail_mode=False) # include more data for each problem
kt.problems(*[True]*4) # show literally all problems on Open Kattis
kt.plot_problems() # plot the points distribution
kt.plot_problems(filepath='plot.png') # save to a filepath
kt.plot_problems(show_partial=False) # plot fully solved submissions
kt.problem('2048') # fetch info about a problem
kt.problem(['2048', 'abinitio', 'dasort']) # fetch multiple in one
kt.problem({'2048', 'abinitio', 'dasort'}) # tuples or sets also allowed
kt.problem('2048', download_files=True) # download files too
kt.stats() # your best submission for each problem
kt.stats('Java') # all your Java submissions
kt.stats(('Python3', 'Cpp')) # multiple languages
kt.suggest() # what's the next problem for me?
kt.achievements() # do I have any?
kt.problem_authors() # list down all problem authors
kt.problem_sources() # list down all problem sources
Ranklist
kt.ranklist() # people around you
kt.user_ranklist() # top 100 users in general ladder
kt.challenge_ranklist() # top 100 users in challenge ladder
kt.country_ranklist() # top 100 countries
kt.country_ranklist('Singapore') # specific country
kt.country_ranklist('SGP') # use country code instead
kt.university_ranklist() # top 100 universities
kt.university_ranklist(university='National University of Singapore') # specific university
kt.university_ranklist(university='nus.edu.sg') # use university domain instead
NUSKattis
Problem-specific
kt.problems() # problems you have solved so far, only supports low detail mode
kt.problems(show_solved=False) # show literally all problems on NUS Kattis
kt.problem('2048') # fetch info about a problem
kt.problem(['2048', 'abinitio', 'dasort']) # fetch multiple in one
kt.problem({'2048', 'abinitio', 'dasort'}) # tuples or sets also allowed
kt.problem('2048', download_files=True) # download files too
kt.stats() # your best submission for each problem
kt.stats('Java') # all your Java submissions
kt.stats(('Python3', 'Cpp')) # multiple languages
Course-specific
kt.courses() # current and recently ended courses
kt.offerings('CS3233') # course offerings
kt.assignments('CS3233_S2_AY2223') # offering assignments but course ID not provided
kt.assignments('CS3233_S2_AY2223', 'CS3233') # offering assignments
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 = ... # see scenario 1 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
-
Old UI Kattis API wrapper: https://github.com/terror/kattis-api
Most of the work in
autokattisis heavily inspired and motivated by this repository. -
Kattis official CLI tool: https://github.com/Kattis/kattis-cli
Since Kattis has provided an official tool to automate submissions, there won't be such feature in
autokattis.
Contributing
Feel free to suggest anything or add on some implementation by simply creating a pull request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autokattis-2.0.tar.gz.
File metadata
- Download URL: autokattis-2.0.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e77674579f5037b8ff24a49ba78ec3ab9a1a5d08b83f4adf2bcc607e925250d
|
|
| MD5 |
a819090f8a3982b755dc32c514f3b200
|
|
| BLAKE2b-256 |
50b09b27948cba5ea77f54ff44d5cfd370564729949176f5d98fdb803d59f8fe
|
File details
Details for the file autokattis-2.0-py3-none-any.whl.
File metadata
- Download URL: autokattis-2.0-py3-none-any.whl
- Upload date:
- Size: 72.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfa8323f7355ef20c9a22ac417781e4befcd62b1a2bbc8df86ad3fe12a59ea6f
|
|
| MD5 |
3428670b23b45c1ed92a06b881ea04e0
|
|
| BLAKE2b-256 |
617097d25fb0353ae8ae7156388c36b61d7ddf748537c2ca3a89b041ca509ac4
|