feat: connect-id suffix matching for OCR + bump SW cache to v10
This commit is contained in:
+24
-3
@@ -66,6 +66,12 @@ def find_asset_by_normalized_id(db_path: str, normalized: str) -> list:
|
||||
Search assets.db for any asset whose serial_number, machine_id, connect_id,
|
||||
equipment_id, or barcode matches the given normalized identifier.
|
||||
|
||||
Supports:
|
||||
- Exact match: normalized string equals the DB field (after normalization)
|
||||
- Suffix match: if the normalized value is all digits and >= 7 chars,
|
||||
match against the last N digits of connect_id and equipment_id (for
|
||||
partial OCR reads that capture only the numeric tail of a longer ID).
|
||||
|
||||
Returns a list of matching rows (dicts).
|
||||
"""
|
||||
if not normalized or len(normalized) < 3:
|
||||
@@ -74,7 +80,22 @@ def find_asset_by_normalized_id(db_path: str, normalized: str) -> list:
|
||||
import sqlite3
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
rows = conn.execute("""
|
||||
|
||||
# Suffix matching: if the scanned text is purely numeric and >= 7 chars,
|
||||
# search for assets whose connect_id or equipment_id ends with those digits.
|
||||
# Connect IDs often look like VM-05064-0000099387; OCR might only read "0000099387".
|
||||
suffix_conditions = ''
|
||||
suffix_params = []
|
||||
if len(normalized) >= 7 and normalized.isdigit():
|
||||
# Match against the last N digits of connect_id and equipment_id.
|
||||
# Use LIKE with rightmost-anchored pattern: %<digits>
|
||||
suffix_conditions = """
|
||||
OR replace(replace(replace(replace(upper(connect_id), '-', ''), '.', ''), ' ', ''), '/', '') LIKE ?
|
||||
OR replace(replace(replace(replace(upper(equipment_id), '-', ''), '.', ''), ' ', ''), '/', '') LIKE ?
|
||||
"""
|
||||
suffix_params = ['%' + normalized, '%' + normalized]
|
||||
|
||||
rows = conn.execute(f"""
|
||||
SELECT id, machine_id, name, serial_number, connect_id, equipment_id,
|
||||
barcode, make, model, category
|
||||
FROM assets
|
||||
@@ -83,8 +104,8 @@ def find_asset_by_normalized_id(db_path: str, normalized: str) -> list:
|
||||
OR replace(replace(replace(replace(upper(equipment_id), '-', ''), '.', ''), ' ', ''), '/', '') = ?
|
||||
OR replace(replace(replace(replace(upper(machine_id), '-', ''), '.', ''), ' ', ''), '/', '') = ?
|
||||
OR replace(replace(replace(replace(upper(barcode), '-', ''), '.', ''), ' ', ''), '/', '') = ?
|
||||
-- Connect-ID suffix match (last 7+ digits → equipment_id suffix)
|
||||
""", (normalized, normalized, normalized, normalized, normalized)).fetchall()
|
||||
{suffix_conditions}
|
||||
""", (normalized, normalized, normalized, normalized, normalized, *suffix_params)).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
// Caches app shell + CDN deps. Network-first for API, cache fallback for static.
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
const CACHE_NAME = 'canteen-v9';
|
||||
const CACHE_NAME = 'canteen-v10';
|
||||
|
||||
// App shell — core resources needed to boot the PWA
|
||||
const APP_SHELL = [
|
||||
|
||||
Reference in New Issue
Block a user