fix: gross-based batch discard, direction-correct event logs, wire CSV logger
ci / smoke (push) Canceled after 0s
ci / smoke (push) Canceled after 0s
This commit is contained in:
1 parent
508bee736d
commit
d3357fccef
8 files changed
+200
-22
No files matched your search
+21
-2
@@ -39,7 +39,8 @@ def test_net_counts_and_discard():
|
||||
assert should_discard_batch(0, 0) is True
|
||||
assert should_discard_batch(1, 0) is False
|
||||
assert should_discard_batch(0, 1) is False
|
||||
assert should_discard_batch(-1, 0) is False
|
||||
assert should_discard_batch(0, 7) is False
|
||||
assert should_discard_batch(5, 0) is False
|
||||
|
||||
|
||||
def test_classify_unit_tokens():
|
||||
@@ -265,7 +266,7 @@ def test_start_stop_auto_409(dash_client):
|
||||
assert res.status_code == 409
|
||||
|
||||
|
||||
def test_stop_discard_both_nets_zero(dash_client):
|
||||
def test_stop_discard_gross_zero(dash_client):
|
||||
client, mode_path, state_path, _ = dash_client
|
||||
office = {"Host": f"localhost:{cd_office_port()}"}
|
||||
client.post("/api/batch/mode", json={"mode": "manual"}, headers=office)
|
||||
@@ -283,6 +284,24 @@ def test_stop_discard_both_nets_zero(dash_client):
|
||||
assert not state_path.exists()
|
||||
|
||||
|
||||
def test_stop_discards_zero_loading_with_unloading(dash_client):
|
||||
client, mode_path, state_path, _ = dash_client
|
||||
office = {"Host": f"localhost:{cd_office_port()}"}
|
||||
client.post("/api/batch/mode", json={"mode": "manual"}, headers=office)
|
||||
state_path.write_text(json.dumps({
|
||||
"counting_date": "2026-09-24", "batch_number": 97,
|
||||
"count": 0, "box_count": 0, "box_unloading": 0, "unloading": 7,
|
||||
"start_time": "2026-09-24T00:00:00",
|
||||
"model_mode": "C",
|
||||
}))
|
||||
res = client.post("/api/batch/stop", headers={"Host": "localhost:5000"})
|
||||
body = res.get_json()
|
||||
assert res.status_code == 200
|
||||
assert body["discarded"] is True
|
||||
assert body["net_sack"] == -7
|
||||
assert not state_path.exists()
|
||||
|
||||
|
||||
def test_stop_keeps_box_only_batch(dash_client):
|
||||
client, mode_path, state_path, _ = dash_client
|
||||
office = {"Host": f"localhost:{cd_office_port()}"}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Smoke tests for src/logger.py (CSVLogger) — stdlib only, no flask/cv2."""
|
||||
|
||||
import csv
|
||||
|
||||
from src.batch import BatchRecord
|
||||
from src.logger import CSVLogger
|
||||
|
||||
|
||||
def test_log_batch_and_log_event_write_csvs(tmp_path):
|
||||
logger = CSVLogger(str(tmp_path))
|
||||
rec = BatchRecord(
|
||||
batch_id=7,
|
||||
start_time=1700000000.0,
|
||||
end_time=1700000060.0,
|
||||
loading_count=5,
|
||||
unloading_count=2,
|
||||
box_loading_count=1,
|
||||
box_unloading_count=0,
|
||||
)
|
||||
logger.log_batch(rec)
|
||||
logger.log_event(7, 123, "unloading", 1700000030.0, "sack")
|
||||
|
||||
batch_csv = tmp_path / "batch_summary.csv"
|
||||
event_csv = tmp_path / "sack_events.csv"
|
||||
assert batch_csv.exists() and batch_csv.stat().st_size > 0
|
||||
assert event_csv.exists() and event_csv.stat().st_size > 0
|
||||
|
||||
with open(batch_csv, newline="") as f:
|
||||
rows = list(csv.reader(f))
|
||||
assert rows[0][0] == "batch_id"
|
||||
data = rows[1]
|
||||
assert data[0] == "7"
|
||||
assert data[3] == "60.0" # duration_s
|
||||
assert data[4] == "5" # loading
|
||||
assert data[5] == "2" # unloading
|
||||
assert data[6] == "3" # net
|
||||
assert data[7] == "1" # box_loading
|
||||
|
||||
with open(event_csv, newline="") as f:
|
||||
erows = list(csv.reader(f))
|
||||
assert erows[0][:5] == ["timestamp", "batch_id", "event", "track_id", "direction"]
|
||||
ev = erows[1]
|
||||
assert ev[1] == "7"
|
||||
assert ev[2] == "sack_crossed"
|
||||
assert ev[3] == "T-0123"
|
||||
assert ev[4] == "unloading"
|
||||
|
||||
|
||||
def test_logger_appends_rows_and_creates_nested_dir(tmp_path):
|
||||
nested = tmp_path / "a" / "b"
|
||||
logger = CSVLogger(str(nested))
|
||||
logger.log_batch(BatchRecord(batch_id=1, start_time=0.0, end_time=1.0,
|
||||
loading_count=1, unloading_count=0))
|
||||
logger.log_batch(BatchRecord(batch_id=2, start_time=0.0, end_time=1.0,
|
||||
loading_count=2, unloading_count=0))
|
||||
with open(nested / "batch_summary.csv", newline="") as f:
|
||||
rows = list(csv.reader(f))
|
||||
# header written once, both batches appended
|
||||
assert [r[0] for r in rows[1:]] == ["1", "2"]
|
||||
Reference in new issue
Block a user