# Chicken Counter API Base URL: `http://:8080` ## Live Dashboard ### `GET /` Returns the dashboard HTML page. ### `GET /api/cameras` List cameras currently writing to `/dev/shm`. ```json {"cameras": ["CC1", "CC2", "CC3"]} ``` ### `GET /shm//stats.json` Live stats for the active pipeline. ```json { "frame_index": 5120, "inside_box_count": 42, "total_entered_count": 1858, "track_count": 99, "backward_active": false, "smoothed_speed": 4.3, "count_events": 0, "run_date": "2026-06-10" } ``` ### `GET /shm//frame.jpg` Live JPEG frame from the active pipeline. --- ## Database All endpoints require the dashboard to be started with `--db `. If no DB exists, endpoints return `[]` or `{}`. ### `GET /api/db/summary` Overall totals across all dates and locations. ```json { "days": 12, "locations": 2, "total_runs": 48, "total_chickens": 125000, "total_hours": 8.5 } ``` ### `GET /api/db/history` Per-date summary, newest first (max 50 rows). ```json [ { "date": "2026-06-10", "location": "kandang-atas", "cams": 4, "total": 5570, "minutes": 40.2 } ] ``` ### `GET /api/db/date/` Detail for a specific date. Format: `YYYY-MM-DD`. ```json { "date": "2026-06-10", "total": {"total": 5570, "minutes": 40.2}, "cameras": [ { "camera_id": "CC1", "total_entered": 1500, "frames_processed": 24800, "elapsed_seconds": 600.5, "stopped_reason": "backward", "source_video": "kandang_1_camera_1_2026-06-10_120056.mp4", "location": "kandang-atas" } ] } ``` ### `GET /api/db/camera/` History for a specific camera across all dates (max 50 rows). ```json [ { "date": "2026-06-10", "location": "kandang-atas", "total_entered": 1500, "frames_processed": 24800, "elapsed_seconds": 600.5, "stopped_reason": "backward" } ] ``` ### `GET /api/db/location/` Summary and history for a specific location. ```json { "location": "kandang-atas", "summary": {"days": 5, "total": 25000, "hours": 3.2}, "history": [ { "date": "2026-06-10", "cameras": "CC1, CC2, CC3, CC4", "total": 5570, "minutes": 40.2 } ] } ``` --- ## Database Schema ```sql CREATE TABLE batch_runs ( id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, location TEXT NOT NULL, camera_id TEXT NOT NULL, total_entered INTEGER NOT NULL DEFAULT 0, frames_processed INTEGER NOT NULL DEFAULT 0, elapsed_seconds REAL NOT NULL DEFAULT 0.0, stopped_reason TEXT NOT NULL DEFAULT '', source_video TEXT NOT NULL DEFAULT '', generated_at TEXT NOT NULL DEFAULT '', UNIQUE(date, location, camera_id) ); ``` Data is inserted automatically by the batch runner when `location` and `db_path` are configured in the batch YAML, or manually via: ```bash python3 store_results.py output/counts_2026-06-10.json --location kandang-atas --db chicken_counts.db ```