fix: correct per-file GPS and device category in upload handler
- main_simple.py upload: map manifest entries by filename so each file gets its own GPS/timestamp (previously every file was assigned captures[0], breaking multi-file uploads) - device_category now uses the category router's real category (e.g. "Remote Control") instead of the mislabeled "manufacturer - device_name" string; also surface category per matched device - add PLAN_TO_PROD.md / FABLE.md development briefs - add CONTEXT.md (leaked PAT redacted from remote URL) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+24
-4
@@ -395,6 +395,13 @@ async def upload_captures(
|
||||
sub_parser = SubFileParser()
|
||||
gps_extractor = GPSFilenameExtractor()
|
||||
|
||||
# Map manifest entries by filename so each file gets its own GPS/timestamp
|
||||
# (previously every file was assigned captures[0], breaking multi-file uploads)
|
||||
manifest_map = {
|
||||
c.get("filename"): c
|
||||
for c in manifest_data.get("captures", [])
|
||||
}
|
||||
|
||||
successful = []
|
||||
failed = []
|
||||
|
||||
@@ -429,6 +436,18 @@ async def upload_captures(
|
||||
# Get best match from unified results
|
||||
best_match = match_results[0] if match_results else None
|
||||
|
||||
# Per-file manifest entry (falls back to first entry, then empty)
|
||||
entry = manifest_map.get(file.filename)
|
||||
if entry is None:
|
||||
entry = manifest_data.get("captures", [{}])[0]
|
||||
|
||||
# The real device category comes from the category router (e.g.
|
||||
# "Weather Sensor", "Remote Control"), carried in match_details.
|
||||
best_category = (
|
||||
best_match.match_details.get("predicted_category")
|
||||
if best_match else None
|
||||
)
|
||||
|
||||
# Use GPS from manifest or filename
|
||||
global upload_counter
|
||||
upload_counter += 1
|
||||
@@ -439,15 +458,15 @@ async def upload_captures(
|
||||
"frequency": frequency,
|
||||
"protocol": protocol,
|
||||
"preset": preset,
|
||||
"latitude": gps_coords.latitude if gps_coords else manifest_data.get("captures", [{}])[0].get("latitude"),
|
||||
"longitude": gps_coords.longitude if gps_coords else manifest_data.get("captures", [{}])[0].get("longitude"),
|
||||
"latitude": gps_coords.latitude if gps_coords else entry.get("latitude"),
|
||||
"longitude": gps_coords.longitude if gps_coords else entry.get("longitude"),
|
||||
"gps_source": gps_coords.source if gps_coords else "manual",
|
||||
"timestamp": manifest_data.get("captures", [{}])[0].get("timestamp", ""),
|
||||
"timestamp": entry.get("timestamp", ""),
|
||||
"data_source": manifest_data.get("data_source", "production"), # production, test, or mock
|
||||
"session_id": manifest_data.get("session_uuid", ""),
|
||||
# Device identification fields (from unified matcher)
|
||||
"device_name": best_match.device_name if best_match else None,
|
||||
"device_category": f"{best_match.manufacturer} - {best_match.device_name}" if best_match else None,
|
||||
"device_category": best_category,
|
||||
"match_confidence": best_match.confidence if best_match else None,
|
||||
"match_method": best_match.match_method if best_match else None,
|
||||
"device_description": f"{best_match.manufacturer} {best_match.device_name}" if best_match else None,
|
||||
@@ -456,6 +475,7 @@ async def upload_captures(
|
||||
{
|
||||
"device_name": m.device_name,
|
||||
"manufacturer": m.manufacturer,
|
||||
"category": m.match_details.get("predicted_category"),
|
||||
"confidence": m.confidence,
|
||||
"method": m.match_method,
|
||||
"details": m.match_details
|
||||
|
||||
Reference in New Issue
Block a user