Skip to content

About

Personal golf shot database: scrape TrackMan share reports, track club distances & dispersion, and watch your game trend over time. Web dashboard + CLI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ShotLedger

Personal golf shot database: scrape TrackMan share-report URLs (the web-dynamic-reports.trackmangolf.com/?r=... links) into a growing local SQLite database of your shots, with a web dashboard plus CLI for distance / dispersion stats, charts, and CSVs — including trends across all your range sessions.

No login and no browser scraping: the report page is a React app that pulls full shot JSON from https://golf-player-activities.trackmangolf.com/api/reports/getreport, and this tool calls that API directly with the report id from your share link.

Setup

git clone https://github.com/petecheslock/shotledger.git && cd shotledger
uv sync
uv run pytest        # 128 tests, no network and no data/ needed

Requires uv. Python 3.12 comes from uv.lock; you do not need to install it separately.

Usage

Web dashboard (everything from the browser)

uv run shotledger serve        # → http://127.0.0.1:8321
  • Overview — club stats (longest/middle/shortest, left/right bias, dispersion), distance box plots, TrackMan-style dispersion map: shots on a 25-yd sample fairway with centerline, per club or all clubs with 68%/95% coverage ellipses and gapping bands; scope switch: all / latest / since
  • Trends — carry and dispersion across sessions (fills in as you add reports)
  • Dispersion — your aim window per club (the yard box you actually cover, bounded by your real left/right/short/long extremes), the 1σ/2σ ellipses and 95% circle overlaid on the landing pattern, raw-vs-robust spread, and improvement per club across sessions
  • Shots — filterable, sortable shot table + CSV export
  • Scrape — paste one or many TrackMan share URLs and hit Scrape; results appear per URL with a link into the fresh session. Re-pasting an old URL is safe (idempotent).

Local-only by design: binds 127.0.0.1 and has no auth — don't expose it on your network.

Developing with auto-reload

uv run shotledger serve --reload    # restarts the server when Python files change

Uvicorn's reloader watches this directory for .py changes only, so editing the Jinja templates or the CSS/JS inside them won't restart anything. To watch those too, run uvicorn directly:

uv run uvicorn shotledger.web_app:app --reload \
  --reload-extension .jinja --reload-extension .html \
  --reload-extension .css --reload-extension .js

Both restart the server, not your browser — hit ⌘R after a change.

CLI (unchanged, works alongside the web app)

# 1. Scrape a report (paste the share URL TrackMan gave you). Idempotent.
uv run shotledger scrape "https://web-dynamic-reports.trackmangolf.com/?r=XXXX&nd_ballType=Premium&nd_altitude=0&nd_temperature=25..."

# 2. See what's stored
uv run shotledger list

# 3. Analyze — stats table + charts + CSVs into output/<date>/
uv run shotledger analyze                 # all stored shots
uv run shotledger analyze --scope latest  # just your newest session
uv run shotledger analyze --since 90d     # window (or --since 2026-10-01)
uv run shotledger analyze --club "7 Iron"

# 4. Trends across sessions (fills in as you scrape more reports)
uv run shotledger trends

# 5. Rebuild the database from archived raw JSON if it ever gets corrupted
uv run shotledger rebuild

Configuration

Everything is configured by environment variable or flag; there is no config file.

Setting Env var Flag Default Meaning
Data directory SHOTLEDGER_DATA_DIR --data-dir ./data SQLite db + raw/ report JSON. The history.
Raw-JSON archive SHOTLEDGER_ARCHIVE_DIR scrape --archive-dir unset = off Extra copy of every scraped report's full raw JSON, written to separate storage
Output directory — --output-dir ./output Charts and CSVs from analyze / trends (regenerable, disposable)
Bind address SHOTLEDGER_HOST serve --host 127.0.0.1 Keep it loopback unless you've added auth
Port SHOTLEDGER_PORT serve --port 8321
Reports API URL SHOTLEDGER_API_URL — TrackMan's API Override for tests/mocks

Env vars are read at process start, so restart after changing one. SHOTLEDGER_DATA_DIR is read before argument parsing, which is why the container can set it without a flag.

Long-term raw JSON archive

SHOTLEDGER_ARCHIVE_DIR is the belt-and-braces copy: after a scrape succeeds, the entire raw API response — verbatim, unmodified, all ~38 shot fields plus the ball/club 3D trajectory arrays, video references, environment and device data that never make it into the SQLite table — is written to $SHOTLEDGER_ARCHIVE_DIR/<report-id>.json.

Point it at a mounted share or NAS so the JSON survives the app, the container, and the database:

uv run shotledger scrape "https://web-dynamic-reports.trackmangolf.com/?r=XXXX..." \
  --archive-dir /Volumes/nas/trackman

Behaviour worth knowing:

  • It only writes on success. A failed fetch or parse writes nothing anywhere.
  • It never blocks a scrape. If the archive path is unwritable (unmounted NAS, full disk, wrong permissions) you get warning: could not archive report <id> … on stderr and the scrape still commits to the data dir. Losing the archive copy is bad; losing the scrape is worse.
  • Directories are created for you, and ~ is expanded. Relative paths resolve against the current directory — use absolute paths in Docker.
  • Re-scraping a report rewrites its archive file with the same content (idempotent).
  • The --archive-dir flag overrides SHOTLEDGER_ARCHIVE_DIR for that scrape.

What you get

Per club: shots, longest / avg / middle (median) / middle-60% / shortest carry, left/right bias (avg_side, trimmed mean so a shank can't skew it), dispersion size (side_stdev), and push/pull counts.

Which command writes what, into output/<date>/:

Command Files
analyze shots.csv (every shot, every metric), club_stats.csv, distances.png (box + strip per club), dispersion.png (landing scatter, − left / + right of target)
dispersion dispersion_stats.csv, dispersion_history.csv, aim_zone.csv, aim_window.csv
trends club_history.csv, carry_trend.png, dispersion_trend.png

trends needs 2+ scraped sessions; with one it writes placeholder images and says so.

The aim window

Per club, the app computes the rectangular yard box your club has actually covered, bounded by your own most-left, most-right, shortest and longest shots:

        side_left_yd ──┐  ┌── side_right_yd
                       │  │     ← width_yd
   carry_short_yd ─ ─ ─┼──┼─ ─ ─
                       │× │     ← aim at the × (box centre)
   carry_long_yd  ─ ─ ─┼──┼─ ─ ─
                       │  │     ← depth_yd
Field Meaning
side_left_yd / side_right_yd your most-left / most-right carry offset (− left, + right)
carry_short_yd / carry_long_yd your shortest / longest carry
width_yd / depth_yd the box's side-to-side and front-to-back size
aim_side_yd / aim_carry_yd the centre of the box — aim here and the box sits around you
robust_* the same box with your worst few shots excluded

It makes no distribution assumption — it is literally what you hit, which is why it's the simplest thing to aim with: stand so the width clears the trouble on both sides, and read the depth to know whether the front bunker or the back of the green is the real threat.

Window vs the oval. A window is built from extremes, so it can only grow as you scrape more sessions — the 11th range session cannot shrink your 10-session box. Early on it's a thin rectangle whose corners are set by a couple of lucky shots; as samples build, the corners you never actually hit stay empty and the real shape becomes the oval the 1σ/2σ ellipses describe. That's expected, not regression. Both are drawn together on the dispersion page — green box = window, blue/orange = ellipses, purple = the headline 95% circle — so you can watch them converge:

  • box much bigger than the ellipse → one bad shot is defining your window; play from the robust_* numbers instead.
  • ellipse bigger than the box → you just haven't hit enough shots with that club yet, so the box is flattering you.

aim_window.csv comes out of shotledger dispersion alongside the other CSVs, and the same data is served at GET /api/dispersion/window.

Data layout

  • data/raw/<report-id>.json — verbatim API responses (source of truth)
  • data/shotledger.db — SQLite: reports + shots tables, append per scrape
  • data/prefs.json — your dashboard view preferences
  • <archive-dir>/<report-id>.json — optional long-term copy of the raw JSON (SHOTLEDGER_ARCHIVE_DIR, see Configuration)
  • output/<run>/ — charts and CSVs (gitignored, regenerable)

None of data/ is source code and none of it is in the container image. It is runtime state that must outlive both the process and the container.

All values are converted to yards / mph (TrackMan's API serves metric). Side signs follow TrackMan: negative = left, positive = right (for a right-handed player). The shot table captures ~38 columns — distances, speeds, spin (rate, axis, loft, index), launch/direction/landing angles, curve, peak height, low point, impact, smash, club category, handedness, and tee position. Everything else in the report (ball + club 3D trajectory point arrays, video references, player, device, settings) lives in the raw JSON archive; add any of it to the queryable table later by extending parser.SHOT_COLUMNS and running shotledger rebuild.

Container image

CI builds the image and publishes it to GitHub Container Registry — see .github/workflows/docker.yml. Nothing to configure: the workflow authenticates with the built-in GITHUB_TOKEN.

Trigger Tags published
Push to main :latest, :<git-sha>
Push tag v1.2.3 :v1.2.3, :v1.2, :v1
Pull request built and smoke-tested, not pushed
ghcr.io/petecheslock/shotledger:latest

To publish a pinned version, push a semver tag — CI builds it and emits :v1.2.3, :v1.2 and :v1:

git tag v1.0.0 && git push origin v1.0.0

The image is python:3.12-slim + the installed package, runs as the non-root user shotledger (uid 10001), listens on 8321, and has a HEALTHCHECK that polls /healthz. Entrypoint is the CLI: docker run <image> list, <image> analyze, and the default <image> serve.

The image contains no data. /data and /archive are empty directories meant to be volumes; /app/output is writable and disposable.

Running it on another host

The app is local-only by design and has no auth. Keep it on loopback and reach it over an SSH tunnel rather than exposing 8321.

1. Pull the image

The package is public, so no login is required:

docker pull ghcr.io/petecheslock/shotledger:latest

Published tags: latest and main (every push to main), main-<sha> (exact pin), plus v1.2.3 / v1.2 / v1 when you push a version tag.

Podman works identically: podman pull ghcr.io/petecheslock/shotledger:latest.

If the package is ever made private again, log in once with a GitHub PAT scoped to read:packages:

echo "<github-pat>" | docker login ghcr.io -u <your-github-username> --password-stdin

2. Create the directories that hold the history

This is the part that must not be skipped — a container started without these volumes loses every shot on its next docker rm:

mkdir -p ~/shotledger/{data,archive}
Host directory Mount What lives there Lose it and
~/shotledger/data /data shotledger.db, raw/*.json, prefs.json you lose the entire shot history (recoverable only if the archive still has the JSON)
~/shotledger/archive /archive one raw JSON per report, never rewritten by anything else you lose the long-term copy; the db still works

Both must be writable by uid 10001 (the user inside the image):

sudo chown -R 10001:10001 ~/shotledger/data ~/shotledger/archive

3. Start it

With compose (docker-compose.yml in this repo — copy it to ~/shotledger/docker-compose.yml, which is where the relative volume paths resolve):

cd ~/shotledger && docker compose up -d

Or plain docker:

docker run -d --name shotledger --restart unless-stopped \
  -p 127.0.0.1:8321:8321 \
  -v ~/shotledger/data:/data \
  -v ~/shotledger/archive:/archive \
  -e SHOTLEDGER_DATA_DIR=/data \
  -e SHOTLEDGER_ARCHIVE_DIR=/archive \
  ghcr.io/petecheslock/shotledger:latest

SHOTLEDGER_HOST is already 0.0.0.0 in the image (required for port mapping); the 127.0.0.1: prefix on -p is what keeps the host loopback-only. -p 8321:8321 instead would put an unauthenticated app on your LAN.

Podman notes. Pull and run work identically. podman compose does not: it is a shim that needs a compose provider installed separately (podman-compose, or docker-compose), and fails with exec: "docker-compose": stat …: no such file or directory if none is present. Either install one, or use the podman run form of the command above. On SELinux hosts (Fedora/RHEL) append :z to each -v so uid 10001 can write the mounts: -v ~/shotledger/data:/data:z.

Running commands in the container

The image's ENTRYPOINT is shotledger and its CMD is serve, which means the entrypoint applies only when you start the container — not to exec. Prefix the CLI name or you get executable file 'analyze' not found in $PATH:

docker exec shotledger shotledger list       # right
docker exec shotledger list                  # wrong — no such command
docker exec shotledger python -c "…"         # right — python is on PATH

Useful once it's running:

docker exec shotledger shotledger list                    # what is stored
docker exec shotledger shotledger analyze                 # charts + CSVs -> /app/output
docker exec shotledger shotledger dispersion              # + aim_window.csv
docker exec shotledger shotledger scrape "<share-url>"    # add a session
docker logs --tail 50 shotledger                          # serve logs
curl -fsS http://127.0.0.1:8321/healthz                   # {"status":"ok"}

GET /healthz returns {"status":"ok"} and is what the image's HEALTHCHECK polls (30s interval, 10s start period). First start can take ~10s, so an early failed probe is normal.

4. Reach it

ssh -N -L 8321:127.0.0.1:8321 user@that-host
# then open http://127.0.0.1:8321 locally

Migrating an existing library

Copy the contents of your laptop's data/ into the host's data directory — the db path is relative to the data dir, so nothing needs rewriting:

rsync -av ./data/ user@that-host:~/shotledger/data/
docker restart shotledger

Then re-point the archive somewhere durable (SHOTLEDGER_ARCHIVE_DIR + volume) and restart. Share links may have expired, but data/raw/ means the JSON you already have is safe, and shotledger rebuild can regenerate the db from it.

Restoring the shot history

A fresh clone has no shots: data/ is gitignored and absent from every commit, and the image ships no data. The share URLs are the source of truth — the API needs no login:

uv run shotledger scrape "<share-url>"     # or paste many URLs on the Scrape page

If the database is lost but you still have the JSON (data/raw/ or the archive dir), rebuild without touching the network — each file is a verbatim report, so this restores everything the db held:

cp /path/to/archive/*.json ./data/raw/
uv run shotledger rebuild        # → "Rebuilt database from ./data/raw: N shots."

The raw JSON stores its report Id but not its share URL, so a rebuilt library cannot tell you which link to re-scrape. Save the URLs separately when you first scrape them. Verify any restore with shotledger list and the Overview page.

Upgrading

docker pull ghcr.io/petecheslock/shotledger:latest
docker stop shotledger && docker rm shotledger
cd ~/shotledger && docker compose up -d

Data is untouched — it is on the host, not in the image. Pin a specific tag (:v1.2.3) instead of :latest if you'd rather control upgrades explicitly.

Backups

Back up ~/shotledger/data and ~/shotledger/archive — that's the whole application state. To snapshot the SQLite db safely while the app is running (the backup API copies page-by-page, so it won't hand you a half-written file mid-request):

docker exec shotledger python -c "
import sqlite3
src = sqlite3.connect('/data/shotledger.db')
dst = sqlite3.connect('/data/shotledger.backup.db')
src.backup(dst)
print('backed up', dst.execute('select count(*) from shots').fetchone()[0], 'shots')
"

Or stop the container first and copy the directory. archive/ is append-only JSON, so it copies cleanly any time. output/ is deliberately not backed up — regenerate it with docker exec shotledger shotledger analyze (note the doubled shotledger: see Running commands in the container).

Tests

uv run pytest

The suite includes an end-to-end test that runs the real CLI against a local mock of the reports API using a captured report whose identity fields are synthetic — see Notes. It needs no network and no data/ directory.

Notes

  • Share links can expire; raw JSON is archived on scrape, so already-collected data is safe.
  • data/ is not in the repo, by design. The db and raw/*.json are gitignored and absent from every commit, so nothing here reveals real shots and a fresh clone starts empty. See Restoring the shot history.
  • The test fixture is synthetic. tests/fixtures/sample_report.json is a real session with the identity replaced: Player.Name, Player.Id, the facility User.Name, the report id and the device/group ids are fakes, and Birthday is offset. Every shot value (clubs, carry, total, side, trajectories) is unchanged, so the tests still measure real behaviour. If you re-capture a report into this path, scrub it the same way before committing.
  • Because the repo is public, assume anything you commit here is published permanently; history rewriting after the fact is expensive and does not unpublish old clones.
  • Normalization params (nd_ballType, nd_altitude, nd_temperature) are read from the URL and sent to the API, and stored per report for apples-to-apples comparisons.
  • Distances are auto-detected as metres or millimetres (TrackMan changed units between releases) via magnitude heuristics in src/shotledger/units.py.
  • Design docs for the three major pieces are in docs/plans/ — the scraper, the web app, and the dispersion views. They predate some of the code, so trust the code and this README where they disagree; they're still the fastest way to understand why a piece is shaped the way it is.

License

MIT — see LICENSE.

About

Personal golf shot database: scrape TrackMan share reports, track club distances & dispersion, and watch your game trend over time. Web dashboard + CLI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages