Skip to content

add AtCoder commands: problems, contests, top, user, search - #1

Open
tamnd wants to merge 1 commit into
mainfrom
feat/pr1-atcoder-commands
Open

add AtCoder commands: problems, contests, top, user, search#1
tamnd wants to merge 1 commit into
mainfrom
feat/pr1-atcoder-commands

Conversation

@tamnd

@tamnd tamnd commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Implements atcoder-cli (binary `atcoder`) reading AtCoder data via the kenkoooo.com public API.

Commands

  • `problems` -- list all AtCoder problems with difficulty ratings (joined from IRT models); supports `--difficulty` and `--contest` filters
  • `contests` -- list contests newest-first with start time, duration, and rated range
  • `top` -- top-rated problems sorted by IRT difficulty descending
  • `user ` -- user global AC rank; `--submissions` adds recent submissions
  • `search ` -- case-insensitive title substring match across all problems

Every command accepts `-o table|json|jsonl|csv|tsv|url|raw`, `--fields`, `--template`, `-n`, and all standard transport flags (`--delay`, `--timeout`, `--retries`, `--user-agent`).

Data source

Primary data from kenkoooo.com public API (no auth required):

  • `/resources/problems.json` -- full problem list
  • `/resources/problem-models.json` -- IRT difficulty per problem
  • `/resources/contests.json` -- full contest list
  • `/atcoder-api/v3/user/ac_rank` -- user AC rank
  • `/atcoder-api/v3/user/submissions` -- user submissions

Problems and difficulty models are fetched concurrently with `sync.WaitGroup` and joined in memory on `problem_id`.

Tests

Nine tests in `atcoder/atcoder_test.go` run against local `httptest.Server` instances. All pass with `go test -race`.

test verifies
`TestGetSendsUserAgent` User-Agent header present
`TestGetRetriesOn503` retry logic + backoff timing
`TestGetNullReturnsError` 404 returns ErrNotFound
`TestProblems` join + sort by contest_id desc
`TestContests` sort by start_epoch_second desc
`TestUserACRank` handle/rank/count populated
`TestUserSubmissions` sort newest first, URL built
`TestSearch` case-insensitive substring match
`TestTop` sort difficulty desc, zero-diff excluded

Test plan

  • `go build ./...` green
  • `go test -race -count=1 ./...` green
  • `go run ./cmd/atcoder problems -n 5` returns 5 rows
  • `go run ./cmd/atcoder user tourist` shows rank + AC count
  • `go run ./cmd/atcoder top -n 5 -o jsonl | jq .difficulty` shows descending values
  • `go run ./cmd/atcoder problems -o foo` exits 2
  • `go run ./cmd/atcoder user no_such_user_9999` exits 3

…commands

Five commands built on the kenkoooo.com API: problems (with difficulty/contest
filters), contests (newest first), user (AC rank + optional submissions), search
(case-insensitive title match), and top (hardest by IRT difficulty score).
Concurrent fetch for problems + models endpoints, 500ms rate, 60s timeout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant