Files

6.1 KiB

Changelog

All notable changes to the chicken-counting-sukawarna-det project are documented in this file.

[Unreleased] - 2026-08-20

🚀 Features & Architectural Improvements

  • Hierarchical Per-Coop & Flexible Cage/Floor Discovery (discovery.py):
    • Implemented dynamic farm discovery engine (discover_farm_structure, get_coop_for_location, resolve_floor_video_dir).
    • Added support for hierarchical coop folders (VIDEOS/cycle7/<Coop>/[L1..Ln, mortality]) where all floors and mortality sit on the same level per coop.
    • Fully dynamic site layout discovery without hardcoding assumptions about numbers of coops (e.g. K1..K5 or custom names) or floors per coop (e.g. 2 floors vs 3 floors).
  • Multi-Coop Mortality Pipeline & Batch Runner (mortality.py, cli.py, run_mortality_all.sh):
    • Added coop and covered floor metadata resolution in run_mortality_count(...) and mortality_report.json.
    • Created run_all_coop_mortality(...) and ./run_mortality_all.sh to batch-process mortality detection across all discovered coops with summary reports.
    • Added CLI flags --coop <ID> and --all-coops to chicken-counter mortality.
  • Dedicated Stationary Inspection Camera Capture & Live API (mortality.py, dashboard.py, templates/index.html):
    • Added support for dedicated per-coop stationary cameras (RTSP IP cameras, HTTP snapshots, and USB cameras) configured in configs/mortality_config.yaml.
    • Added POST /api/mortality/capture endpoint to grab high-res still frames from a coop's stationary camera, timestamp and save them into VIDEOS/cycle7/<Coop>/mortality/<YYYY-MM-DD>/, and run YOLO carcass detection.
    • Added GET /api/mortality/camera/preview to stream live snapshot previews to workers in the webapp before snapping.
    • Added GET /api/mortality/cameras to list all registered coop stationary camera sources.
    • Web UI Mortality Inspector: Integrated live camera preview, one-click "📸 Snap & Count Batch from Camera" button, and support for multi-batch counting per coop per day with cumulative totals.
    • Added fallback manual file upload tab for disk-based images.
  • Dynamic Floor Config Synthesis & Sync Tool (config.py, discovery.py, cli.py):
    • Implemented load_or_synthesize_floor_config allowing chicken-counter batch --floor <ID> to dynamically synthesize settings from cycle7_batch_optimized.yaml in memory without requiring a physical YAML file.
    • Implemented sync_floor_configs and CLI command chicken-counter sync-configs to automatically scan VIDEOS/ and generate boilerplate floor YAML configs for newly added coops/floors.
    • Updated run_all_coops.sh to dynamically discover all floors directly from VIDEOS/ or configs/floor_config/ and seamlessly run physical YAMLs or virtual in-memory configs.
  • Unit Test Suite (tests/test_flexible_discovery.py):
    • Added automated test cases validating dynamic coop and floor extraction, arbitrary site layout adaptation, path resolution, config synchronization, virtual floor config synthesis, and dated mortality discovery.

[1.1.0] - 2026-08-19

🐛 Bug Fixes

  • Multi-Camera Tracker State Isolation (tracking.py & batch_runner.py):
    • Implemented per-camera independent tracker instances keyed by stream_id in DetectionTracker.
    • Fixed tracker state bleed and track ID jumping in tensor_batching and multi-camera batch modes when camera frames are processed or when active camera sets shrink.
    • Added unit test suite tests/test_tracking.py covering multi-stream tracker isolation.
  • Multi-Floor Script Syntax (run_all_coops.sh):
    • Resolved fatal syntax error: unexpected end of file caused by missing done in floor configuration discovery loop.
    • Expanded config discovery pattern from K*-L*.yaml to *.yaml to support custom named coops (e.g. kandang-atas.yaml).
  • Excel Report Empty Result Crash (export_excel_report.py):
    • Added empty DataFrame pre-check to prevent IndexError when exporting reports for dates with no batch runs or newly initialized databases.
  • Multi-Threaded SQLite Concurrency (dashboard.py):
    • Replaced global single sqlite3 connection with thread-local connections (threading.local()) to prevent cursor collision and race conditions across concurrent HTTP worker threads.
    • Enabled PRAGMA busy_timeout = 5000 and PRAGMA journal_mode = WAL to avoid database lock conflicts during batch processing writes.
  • Editable Package Installation:
    • Configured pip install -e . in environment setup to resolve chicken_counter imports and enable automatic unit test discovery without manual PYTHONPATH prefixes.

⚡ Performance & Optimization

  • Secondary Database Indexing (dashboard.py, batch_runner.py, store_results.py):
    • Added idx_batch_date, idx_batch_camera, and idx_batch_location indexes on batch_runs to accelerate single camera, location, and date historical queries.
  • Atomic Config Persistence (dashboard.py):
    • Added _config_write_lock and atomic temporary file replacement (os.replace) in _persist_cycle_start_date to prevent race conditions or half-written YAML reads.
  • Streaming Socket Keepalive (dashboard.py):
    • Added an idle keepalive heartbeat (b"--frame\r\n\r\n") every 3 seconds to immediately detect and terminate disconnected MJPEG streaming threads during pipeline idle periods.
  • Disk Traversal Caching in Live Dashboard (dashboard.py):
    • Replaced repetitive Path.rglob() scans on every /api/mortality/* endpoint with a thread-safe 15-second in-memory TTL cache (_MORTALITY_CACHE_TTL = 15.0s).
    • Added O(1) memory index lookup for serving annotated images (/api/mortality/image/<filename>), eliminating full filesystem traversals across 30GB+ video datasets.

📁 Configuration & Directory Structure

  • Floor Configuration & Skeleton Paths:
    • Created configs/floor_config/kandang-atas.yaml extending cycle7_batch_optimized.yaml.
    • Initialized missing directory skeletons for coops K1-L1 through K5-L2 under ../VIDEOS/cycle7/.
  • Documentation:
    • Updated README.md and RUN.md with editable install steps and updated project layout.