How sleepingarhat/tianxi-racing works
Tianxi Database is a Hong Kong horse-racing data platform: it scrapes HKJC and related sources into reusable racing datasets, with a backend API and prediction/analysis services. The main workflow is source collection, structured ingestion and integrity checking, database/API serving, then analysis and race-day picks with a lock-time freeze. The README also describes Elo ratings, odds, profiles, membership, alerts, and research/backtesting. Edges are limited to relationships stated in the README or shown in excerpts/index references; several backend and scraper subsystems are represented by their supported paths without inferred call chains.
Main entry points: index.ts Backend API · types.ts D1 racing store · analyze.ts Race analysis · freeze-ledger.ts Prediction freeze
Components 24
Data Collection
- Racing scrapers
RacingData_Scraper.py - Specialized scrapers
- Backend ingestion
backend/scripts/ingest - Horse profiles
HorseData_Scraper.py
Data and API
- CSV data archive
- D1 racing store
backend/src/types.ts - Backend API
backend/src/index.ts - Race and entity APIs
backend/src/routes/meetings.ts
Ratings and Picks
- Elo calculation
backend/scripts/elo/engine_v12.ts - Elo batch driver
backend/scripts/elo/compute_v12.ts - Race analysis
backend/src/routes/analyze.ts
Race-Day Operations
- Prediction freeze
backend/src/lib/freeze-ledger.ts - Freeze recovery
backend/src/lib/freeze-recovery.ts - Lock window
backend/src/lib/lock-window.ts - Odds collection
backend/src/lib/odds-collection.ts - Engine health
backend/src/lib/engine-health.ts - Membership and access
backend/src/routes/membership.ts - Notifications and watch
backend/src/routes/notify.ts
Research and Integrity
- Integrity audit
tools/data_integrity_audit.py - Upcoming prediction
backend/scripts/backtest/predict_upcoming.py - Profile coverage
tools/horse_profile_coverage.py - Model research
backend/scripts/backtest
Other components
- HKJC sources
- Downstream clients
Connections 27
- HKJC sources → Racing scrapers: scrape
README.md - Racing scrapers → CSV data archive: produce CSV
README.md - HKJC sources → Specialized scrapers: collect racing data
README.md - Specialized scrapers → CSV data archive: produce CSV
- HKJC sources → Backend ingestion: fetch racecards
backend/scripts/ingest/lib/hkjc-racecard-query.graphql - Backend ingestion → D1 racing store: ingest data
README.md - CSV data archive → Integrity audit: audit archive
- CSV data archive → Downstream clients: fetch CSV
README.md - D1 racing store → Backend API: read and write
backend/src/index.ts - Backend API → Downstream clients: serve API
README.md - Elo batch driver → Elo calculation: compute ratings
- D1 racing store → Elo batch driver: read race data
- Race analysis → D1 racing store: query race data
backend/src/routes/analyze.ts - Backend API → Race analysis: route analysis
backend/src/index.ts - Upcoming prediction → Model research: evaluate predictions
backend/scripts/backtest/predict_upcoming.py - Race analysis → Prediction freeze: record frozen picks
backend/src/routes/analyze.ts - Prediction freeze → Lock window: check lock
backend/src/lib/freeze-ledger.ts - Prediction freeze → Freeze recovery: recover originals
backend/src/lib/freeze-ledger.ts - Backend API → Engine health: build health
backend/src/index.ts - Engine health → Lock window: check meeting lock
backend/src/lib/engine-health.ts - Engine health → Odds collection: read freshness
backend/src/lib/engine-health.ts - Backend API → Race and entity APIs: route race APIs
backend/src/index.ts - Backend API → Membership and access: route membership
backend/src/index.ts - Backend API → Notifications and watch: route notifications
backend/src/index.ts - HKJC sources → Horse profiles: scrape profiles
- Horse profiles → Profile coverage: measure coverage
- Backend API → Downstream clients: publish racing data
README.md