82 lines
2.5 KiB
Markdown
82 lines
2.5 KiB
Markdown
# ERD — DO-gated manual batch (delivery orders)
|
|
|
|
Mermaid ER for karung feedmill counter. Soft FK: no DB foreign keys enforced;
|
|
`delivery_orders.batch_id` is informational once a batch row exists. While a
|
|
batch is active, membership lives in `current_batch.json` (`do_ids`).
|
|
|
|
```mermaid
|
|
erDiagram
|
|
batches ||--o{ delivery_orders : "soft via do_numbers / batch_id"
|
|
batches ||--o{ daily_summaries : "rolls up by counting_date"
|
|
|
|
batches {
|
|
INTEGER id PK
|
|
TEXT counting_date
|
|
INTEGER batch_number
|
|
TEXT camera_name
|
|
TEXT object_label
|
|
INTEGER count
|
|
TEXT start_time
|
|
TEXT end_time
|
|
INTEGER box_loading
|
|
INTEGER box_unloading
|
|
TEXT model_mode
|
|
TEXT plate
|
|
TEXT do_numbers
|
|
INTEGER expected_sack
|
|
INTEGER expected_box
|
|
INTEGER net_sack
|
|
INTEGER net_box
|
|
TIMESTAMP created_at
|
|
}
|
|
|
|
delivery_orders {
|
|
INTEGER id PK
|
|
TEXT counting_date
|
|
TEXT photo_path
|
|
TEXT no_do
|
|
TEXT plate
|
|
INTEGER expected_sack
|
|
INTEGER expected_box
|
|
TEXT ocr_raw
|
|
TEXT status
|
|
INTEGER batch_id
|
|
TIMESTAMP created_at
|
|
TIMESTAMP updated_at
|
|
}
|
|
|
|
daily_summaries {
|
|
INTEGER id PK
|
|
TEXT counting_date
|
|
TEXT camera_name
|
|
TEXT object_label
|
|
INTEGER total_count
|
|
INTEGER total_batches
|
|
TIMESTAMP updated_at
|
|
}
|
|
```
|
|
|
|
## Relationships (logical)
|
|
|
|
| From | To | How |
|
|
|---|---|---|
|
|
| `delivery_orders` → `batches` | N—1 | On stop: `batches.do_numbers` JSON array of `No. DO`; `delivery_orders.batch_id` set best-effort. Active batch: `current_batch.json.do_ids`. |
|
|
| `batches` → `daily_summaries` | N—1 | Same counting_date/camera/label; stop recompute `SUM(count)`. |
|
|
|
|
## Status (`delivery_orders.status`)
|
|
|
|
`draft` → `staged` (saved/edited) → `attached` (in active/stopped batch) |
|
|
`discarded` (deleted). Discarded stop (both nets 0) returns DOs to `staged`.
|
|
|
|
## JSON sidecars + photo tree (not in SQLite)
|
|
|
|
| Path | Role |
|
|
|---|---|
|
|
| `$OUTPUT_DIR/batch_mode.json` | `{mode: auto\|do_manual\|manual}` |
|
|
| `$OUTPUT_DIR/current_batch.json` | active batch + `do_ids`, plate, expected_*, nets inputs |
|
|
| `$OUTPUT_DIR/do_settings.json` | `require_plate`, `require_do`, `ocr_engine` |
|
|
| `$OUTPUT_DIR/do_photos/YYYY-MM-DD/do_<uuid>.jpg` | source photos (7-day retention) |
|
|
|
|
Schema DDL: `counter_dashboard.py` `_ensure_db()` (additive PRAGMA migrations
|
|
on `batches` + `CREATE TABLE delivery_orders`).
|