- growth_model.py: load best_weight_model.pkl (hybrid_allometric_rf) with local chicken-weighing/ path first, external as fallback - aggregation.py: pass minor/major axis medians into predict_chicken_weight - run_daily_weighing.sh: run local chicken-weighing/weighing_inference.py - vendor chicken-weighing/ mirror (models, db, services, dashboard) - configs: stage boundaries 0-14 early / 15+ mid; floor_config extends simulation_experiment - services: fix paths to Project_FOLDER/.Codes - requirements: add scikit-learn, lightgbm, pytest - docs: sync README/RUN/API/ERD/CHANGELOG/CENTRAL_DASHBOARD to current code state
13 KiB
🐔 Central Dashboard API Integration & Data Mapping Guide
Edge Device Host: http://192.168.192.106:8090
Protocol: HTTP REST (JSON) + Multipart MJPEG Live Streams
Repository: chicken-counting-sukawarna-det
Site: Site A (Sukawarna Farm)
1. 🌐 System Overview & Base URL
The edge machine at 192.168.192.106 runs the Chicken Counting Vision Pipeline and hosts the local API server on port 8090.
Base API URL: http://192.168.192.106:8090
Health Check / Heartbeat Endpoint
GET http://192.168.192.106:8090/api/status
Response Example:
{
"status": "running",
"is_counting_active": true,
"active_cameras": ["CC1", "CC2", "CC3", "CC4"],
"latest_counted_date": "2026-06-18",
"total_chickens_all_time": 146418,
"cycle_start_date": "2026-10-01",
"doc_weight_g": 32.0,
"timestamp": "2026-09-02T10:45:00.000000+00:00"
}
2. 🏛️ Farm Hierarchy & 2-Coop / 8-Camera Test Setup
The system organizes farm video and camera streams in a 4-tier hierarchy:
\text{Site} \longrightarrow \text{Coop (Kandang)} \longrightarrow \text{Floor / Location} \longrightarrow \text{Camera (CC1..CC4)}
| Level | Identifier | Test Values (2 Coops / 8 Cameras) |
|---|---|---|
| Site | site |
site_a |
| Coop 1 | location |
test-coop-1 (Cameras: CC1, CC2, CC3, CC4) |
| Coop 2 | location |
test-coop-2 (Cameras: CC1, CC2, CC3, CC4) |
| Total Test Scope | — | 8 camera feeds total |
Auth (central-side): The central database also holds an
API_KEYStable (id,user_idFK →USER_ACCESS,name,prefix,key_hash,is_active,last_used_at,created_at,updated_at) storing machine credentials so edge/client machines can call the API via header auth instead of username/password sessions. SeeERD.mdfor the full schema. No edge endpoint manages these keys yet — they are provisioned directly in the central dashboard.
3. 🗺️ Master Field Mappings (Edge API \longrightarrow Central DB)
When the Central Dashboard pulls data from the edge device, map the edge fields to the Central Database tables as follows:
A. Table CHICKEN_COUNTING (Headcount & Mortality)
| Edge API Field / Source | Central Table Field | Type | Description / Aggregation Logic |
|---|---|---|---|
date |
date |
DATE |
Batch run date (YYYY-MM-DD) |
location |
floor_id |
VARCHAR |
Floor/Coop ID (e.g., test-coop-1, K1-L1) |
\sum total_entered |
total_count |
INTEGER |
Sum of total_entered across CC1..CC4 for that floor |
total_mortality |
mortality_count |
INTEGER |
Carcass count from /api/mortality/date/{date} |
| Matched Date | cycle_id |
INTEGER |
References active commercial cycle in Central DB |
B. Table CHICKEN_WEIGHT (Flock Growth & Morphometrics)
| Edge API Field / Source | Central Table Field | Type | Description / Units |
|---|---|---|---|
coop |
coop / kandang_id |
VARCHAR |
Parent coop / kandang (e.g., K1 for Kandang 1) |
location |
floor_id |
VARCHAR |
Floor/location ID (e.g., K1-L1, test-coop-1) |
camera_id |
camera_id |
VARCHAR |
Camera ID (CC1..CC4) or FUSED for flock aggregate |
cycle_day |
age |
INTEGER |
Flock age in days (0 = \text{DOC Arrival}, 1+ = \text{Weight active}) |
predicted_weight_g / fused_prediction_g |
average_weight |
FLOAT |
Predicted weight in grams (g) |
n_valid_samples / frequency |
chicken_count |
INTEGER |
Number of non-outlier validated chickens weighed |
excluded |
excluded_count |
INTEGER |
Number of discarded outlier / non-crossing observations |
uniformity |
uniformity |
FLOAT |
Flock weight uniformity percentage (\pm 10\% of median area) |
area_cm2_median |
area_cm2_median |
FLOAT |
Calibrated median body projected area (cm^2) |
major_axis_cm_median |
major_axis_cm_median |
FLOAT |
Calibrated median body length (cm) |
minor_axis_cm_median |
minor_axis_cm_median |
FLOAT |
Calibrated median body width (cm) |
gompertz_baseline_g |
gompertz_baseline_g |
FLOAT |
Theoretical Gompertz growth curve baseline (g) |
vision_gain_g |
vision_gain_g |
FLOAT |
Vision-derived allometric gain residual (g) |
rejection_rate |
rejection_rate |
FLOAT |
Outlier filter rejection rate (0.0 \text{ to } 1.0) |
C. Table DETECTIONS / BATCH_RUNS (Per-Camera Telemetry)
| Edge API Field | Central Table Field | Type | Description |
|---|---|---|---|
camera_id |
camera_id |
VARCHAR |
CC1, CC2, CC3, or CC4 |
frames_processed |
frames_processed |
INTEGER |
Total video frames analyzed |
elapsed_seconds |
elapsed_seconds |
REAL |
Pipeline execution time in seconds |
stopped_reason |
stopped_reason |
VARCHAR |
Reason run ended (completed or backward optical flow) |
D. Table CYCLES — New Close-Out & Feed Balance Fields (Central Schema v31.4.5)
These fields exist in the central CYCLES table (see ERD.md) but are not yet returned by any edge API endpoint — central dashboard developers should treat them as centrally-managed until edge support lands:
| Central Table Field | Type | Description / Availability |
|---|---|---|
proposed_end_date |
DATE |
Proposed cycle end date — ⚠️ not yet available from edge API |
close_requested_at |
TIMESTAMP |
When cycle close was requested — ⚠️ not yet available from edge API |
close_requested_by_id |
INTEGER |
FK → USER_ACCESS — ⚠️ not yet available from edge API |
feed_initial_balance |
INTEGER |
Opening feed stock for the cycle — ⚠️ not yet available from edge API |
feed_initial_balance_date |
DATE |
Date of opening feed stock count — ⚠️ not yet available from edge API |
E. Table API_KEYS — Machine Credentials (Central-Only)
The API_KEYS table is central-only (provisioned in the central dashboard, no edge endpoint). Edge/client machines present a key via request header instead of a username/password session:
| Central Table Field | Type | Description |
|---|---|---|
id |
INTEGER |
Primary key |
user_id |
INTEGER |
FK → USER_ACCESS (key owner) |
name |
VARCHAR(100) |
Human-readable key label |
prefix |
VARCHAR(12) |
Public key prefix for lookup |
key_hash |
VARCHAR(64) |
Hashed secret (never store plaintext) |
is_active |
BOOLEAN |
Revocation flag |
last_used_at |
TIMESTAMP |
Last successful authentication |
created_at / updated_at |
TIMESTAMP |
Audit timestamps |
F. Table MANUAL_INPUT — New Feed-Out Fields (Central Schema v31.4.5)
| Central Table Field | Type | Description / Availability |
|---|---|---|
feed_out_manual |
INTEGER |
Manual feed-out count — ⚠️ not yet available from edge API |
feed_out_manual_total |
INTEGER |
Cumulative manual feed-out — ⚠️ not yet available from edge API |
4. 📡 Primary REST API Endpoints
1. Overall Summary
GET http://192.168.192.106:8090/api/db/summary
Response:
{
"days": 1,
"locations": 2,
"total_runs": 8,
"total_chickens": 14280,
"total_hours": 0.45
}
2. Historical & 8-Camera Date Records
GET http://192.168.192.106:8090/api/db/date/2026-06-18
Response (8 Camera Runs across 2 Coops):
{
"date": "2026-06-18",
"total": {
"total": 14280,
"minutes": 27.2
},
"cameras": [
{
"camera_id": "CC1",
"location": "test-coop-1",
"total_entered": 1820,
"predicted_weight_g": 1430.5,
"frames_processed": 5120,
"elapsed_seconds": 184.2,
"stopped_reason": "completed"
},
{
"camera_id": "CC2",
"location": "test-coop-1",
"total_entered": 1750,
"predicted_weight_g": 1415.2,
"frames_processed": 5120,
"elapsed_seconds": 185.0,
"stopped_reason": "completed"
},
{
"camera_id": "CC3",
"location": "test-coop-1",
"total_entered": 1890,
"predicted_weight_g": 1442.0,
"frames_processed": 5120,
"elapsed_seconds": 183.8,
"stopped_reason": "completed"
},
{
"camera_id": "CC4",
"location": "test-coop-1",
"total_entered": 1710,
"predicted_weight_g": 1408.3,
"frames_processed": 5120,
"elapsed_seconds": 182.1,
"stopped_reason": "completed"
},
{
"camera_id": "CC1",
"location": "test-coop-2",
"total_entered": 1790,
"predicted_weight_g": 1425.0,
"frames_processed": 5120,
"elapsed_seconds": 186.4,
"stopped_reason": "completed"
},
{
"camera_id": "CC2",
"location": "test-coop-2",
"total_entered": 1810,
"predicted_weight_g": 1432.1,
"frames_processed": 5120,
"elapsed_seconds": 184.9,
"stopped_reason": "completed"
},
{
"camera_id": "CC3",
"location": "test-coop-2",
"total_entered": 1760,
"predicted_weight_g": 1410.8,
"frames_processed": 5120,
"elapsed_seconds": 185.7,
"stopped_reason": "completed"
},
{
"camera_id": "CC4",
"location": "test-coop-2",
"total_entered": 1750,
"predicted_weight_g": 1420.4,
"frames_processed": 5120,
"elapsed_seconds": 183.0,
"stopped_reason": "completed"
}
]
}
3. Filter by Individual Coop Location
GET http://192.168.192.106:8090/api/db/location/test-coop-1
GET http://192.168.192.106:8090/api/db/location/test-coop-2
Response:
{
"location": "test-coop-1",
"summary": {
"days": 1,
"total": 7170,
"hours": 0.22
},
"history": [
{
"date": "2026-06-18",
"cameras": "CC1, CC2, CC3, CC4",
"total": 7170,
"minutes": 13.5
}
]
}
4. Weight Predictions & Morphometrics
GET http://192.168.192.106:8090/api/weight/coops
GET http://192.168.192.106:8090/api/weight/coop/K1
GET http://192.168.192.106:8090/api/weight/predictions?coop=K1
GET http://192.168.192.106:8090/api/weight/predictions/2026-06-18?coop=K1
GET http://192.168.192.106:8090/api/weight/features/2026-06-18?coop=K1
Response (GET /api/weight/predictions/2026-06-18?coop=K1):
{
"date": "2026-06-18",
"records": [
{
"date": "2026-06-18",
"coop": "K1",
"location": "K1-L1",
"camera_id": "FUSED",
"cycle_day": 27,
"predicted_weight_g": 1424.2,
"doc_weight_g": 42.0,
"gompertz_baseline_g": 1390.0,
"vision_gain_g": 34.2,
"n_valid_samples": 6840,
"frequency": 6840,
"excluded": 328,
"uniformity": 87.4,
"rejection_rate": 0.046,
"dominant_camera": "CC2",
"area_cm2_median": 245.3,
"major_axis_cm_median": 22.4,
"minor_axis_cm_median": 14.1
}
],
"frequency": 6840,
"excluded": 328,
"uniformity": 87.4,
"total_records": 1
}
Note (central schema v31.4.5): When persisting the above into central
CHICKEN_WEIGHT, the central row also carriesdoc_weight,average_daily_gain,created_at, andupdated_at(seeERD.md). Cycle-level fields (proposed_end_date,close_requested_*,feed_initial_balance*) live on centralCYCLESand are not yet returned by the edge API — manage them centrally until edge support lands.
5. Mortality (Dead Bird) Reports
GET http://192.168.192.106:8090/api/mortality/coops
GET http://192.168.192.106:8090/api/mortality/date/2026-06-18
Response:
[
{
"coop": "K1",
"covered_floors": ["K1-L1", "K1-L2"],
"total_carcasses": 5,
"latest_date": "2026-06-18",
"latest_count": 5
},
{
"coop": "K2",
"covered_floors": ["K2-L1", "K2-L2"],
"total_carcasses": 3,
"latest_date": "2026-06-18",
"latest_count": 3
}
]
6. Live MJPEG Camera Streams & Real-Time Stats
- Live Video Streams:
http://192.168.192.106:8090/stream/CC1http://192.168.192.106:8090/stream/CC2http://192.168.192.106:8090/stream/CC3http://192.168.192.106:8090/stream/CC4
- Real-time Stats:
GET http://192.168.192.106:8090/shm/CC1/stats.json
5. 🧪 Testing Script for Central Dashboard Developers
#!/bin/bash
BASE="http://192.168.192.106:8090"
echo "=== 1. System Status ==="
curl -s "$BASE/api/status" | jq .
echo "=== 2. Overall Summary (All 8 Cameras) ==="
curl -s "$BASE/api/db/summary" | jq .
echo "=== 3. Coop 1 Data ==="
curl -s "$BASE/api/db/location/test-coop-1" | jq .
echo "=== 4. Coop 2 Data ==="
curl -s "$BASE/api/db/location/test-coop-2" | jq .
echo "=== 5. Weight Predictions ==="
curl -s "$BASE/api/weight/predictions" | jq .
echo "=== 6. Mortality Summary ==="
curl -s "$BASE/api/mortality/coops" | jq .