fix: OCR last-5-digits extraction, barcode 1D-only scanning, auto-checkin on create
- OCR: Extract only last 5 digits from Connect ID (XXXXX-XXXXXX → last 5) - Barcode: Switch to decodeFromVideoDevice with 1D-only format hints (Code 128/39/EAN/UPC/ITF/Codabar), TRY_HARDER, 50ms scan interval - Auto check-in: New assets auto-checkin with GPS on creation via all three entry modes (barcode, OCR, manual) - Tests: Updated e2e tests for login wait and API flow
This commit is contained in:
@@ -2557,18 +2557,24 @@ async def ocr_sticker(file: UploadFile = File(...)):
|
||||
# Search for XXXXX-XXXXXX pattern (5 digits - 6 digits or more)
|
||||
match = re.search(r"(\d{5})[-\s]*(\d{6,})", text)
|
||||
if match:
|
||||
machine_id = f"{match.group(1)}-{match.group(2)}"
|
||||
# Take only the last 5 digits of the matched ID (e.g., "05912-095330" → "95330")
|
||||
full_match = match.group(0)
|
||||
digits_only = re.sub(r"\D", "", full_match)
|
||||
machine_id = digits_only[-5:]
|
||||
return {
|
||||
"machine_id": machine_id,
|
||||
"raw_text": text.strip()[:500],
|
||||
"raw_match": full_match,
|
||||
"confidence": "high",
|
||||
}
|
||||
|
||||
# Try looser: any 5+ digit number as machine_id
|
||||
# Try looser: any 5+ digit number, take the last 5 digits
|
||||
loose = re.search(r"(\d{5,})", text)
|
||||
if loose:
|
||||
digits = loose.group(1)
|
||||
machine_id = digits[-5:] if len(digits) > 5 else digits
|
||||
return {
|
||||
"machine_id": loose.group(1),
|
||||
"machine_id": machine_id,
|
||||
"raw_text": text.strip()[:500],
|
||||
"confidence": "low",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user