refactor: OCR 字段改驼峰(ocrLayout/ocrCourier/ocrSName...)
This commit is contained in:
+8
-8
@@ -14,17 +14,17 @@ from flows.shared import SyncDB, build_stats_rows, emit_sync_summary
|
|||||||
BATCH_SIZE = 200
|
BATCH_SIZE = 200
|
||||||
|
|
||||||
_OCR_FIELD_MAP = [
|
_OCR_FIELD_MAP = [
|
||||||
("layout", "ocr_layout"), ("courier", "ocr_courier"), ("tracking", "ocr_tracking"),
|
("layout", "ocrLayout"), ("courier", "ocrCourier"), ("tracking", "ocrTracking"),
|
||||||
("marker", "ocr_marker"), ("s_name", "ocr_s_name"), ("s_street", "ocr_s_street"),
|
("marker", "ocrMarker"), ("s_name", "ocrSName"), ("s_street", "ocrSStreet"),
|
||||||
("s_city", "ocr_s_city"), ("s_state", "ocr_s_state"), ("s_zip", "ocr_s_zip"),
|
("s_city", "ocrSCity"), ("s_state", "ocrSState"), ("s_zip", "ocrSZip"),
|
||||||
("r_name", "ocr_r_name"), ("r_street", "ocr_r_street"), ("r_city", "ocr_r_city"),
|
("r_name", "ocrRName"), ("r_street", "ocrRStreet"), ("r_city", "ocrRCity"),
|
||||||
("r_state", "ocr_r_state"), ("r_zip", "ocr_r_zip"),
|
("r_state", "ocrRState"), ("r_zip", "ocrRZip"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _result_to_fields(r) -> dict[str, str | None]:
|
def _result_to_fields(r) -> dict[str, str | None]:
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
return {"ocr_layout": "ERROR"}
|
return {"ocrLayout": "ERROR"}
|
||||||
return {col: (getattr(r, attr) or "") for attr, col in _OCR_FIELD_MAP}
|
return {col: (getattr(r, attr) or "") for attr, col in _OCR_FIELD_MAP}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ def process_all(pending: list) -> dict[str, int]:
|
|||||||
unsupp.append((order_no, created_at))
|
unsupp.append((order_no, created_at))
|
||||||
|
|
||||||
if unsupp:
|
if unsupp:
|
||||||
db.update_ocr_batch([(no, ca, {"ocr_layout": "UNSUPPORTED"}) for no, ca in unsupp])
|
db.update_ocr_batch([(no, ca, {"ocrLayout": "UNSUPPORTED"}) for no, ca in unsupp])
|
||||||
stats["unsupported"] = len(unsupp)
|
stats["unsupported"] = len(unsupp)
|
||||||
print(f"[OCR] 不支持国家: {len(unsupp)} 单 → UNSUPPORTED")
|
print(f"[OCR] 不支持国家: {len(unsupp)} 单 → UNSUPPORTED")
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ def process_all(pending: list) -> dict[str, int]:
|
|||||||
results = ocr.recognize_batch(urls, country_code)
|
results = ocr.recognize_batch(urls, country_code)
|
||||||
except Exception as err: # noqa: BLE001
|
except Exception as err: # noqa: BLE001
|
||||||
print(f"[OCR] {country_code} batch {batch_no}/{total_batches} 请求失败: {str(err)[:100]}")
|
print(f"[OCR] {country_code} batch {batch_no}/{total_batches} 请求失败: {str(err)[:100]}")
|
||||||
db.update_ocr_batch([(no, created_map[no], {"ocr_layout": "ERROR"}) for no in created_map])
|
db.update_ocr_batch([(no, created_map[no], {"ocrLayout": "ERROR"}) for no in created_map])
|
||||||
stats["error"] += len(batch)
|
stats["error"] += len(batch)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -111,7 +111,7 @@ class SyncDB:
|
|||||||
sql = (
|
sql = (
|
||||||
'SELECT "orderNo","createdAt","labelPdfUrl","destinationCountry" '
|
'SELECT "orderNo","createdAt","labelPdfUrl","destinationCountry" '
|
||||||
'FROM "Orders" '
|
'FROM "Orders" '
|
||||||
'WHERE "labelPdfUrl" IS NOT NULL AND "ocr_layout" IS NULL'
|
'WHERE "labelPdfUrl" IS NOT NULL AND "ocrLayout" IS NULL'
|
||||||
)
|
)
|
||||||
params: list = []
|
params: list = []
|
||||||
if destination_country:
|
if destination_country:
|
||||||
@@ -180,10 +180,10 @@ class SyncDB:
|
|||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'''SELECT
|
'''SELECT
|
||||||
COUNT(*) FILTER (WHERE "ocr_layout" IS NOT NULL AND "ocr_layout" NOT IN ('ERROR','UNSUPPORTED')) AS done,
|
COUNT(*) FILTER (WHERE "ocrLayout" IS NOT NULL AND "ocrLayout" NOT IN ('ERROR','UNSUPPORTED')) AS done,
|
||||||
COUNT(*) FILTER (WHERE "ocr_layout"='ERROR') AS error,
|
COUNT(*) FILTER (WHERE "ocrLayout"='ERROR') AS error,
|
||||||
COUNT(*) FILTER (WHERE "ocr_layout"='UNSUPPORTED') AS unsupported,
|
COUNT(*) FILTER (WHERE "ocrLayout"='UNSUPPORTED') AS unsupported,
|
||||||
COUNT(*) FILTER (WHERE "ocr_layout" IS NULL AND "labelPdfUrl" IS NOT NULL) AS pending
|
COUNT(*) FILTER (WHERE "ocrLayout" IS NULL AND "labelPdfUrl" IS NOT NULL) AS pending
|
||||||
FROM "Orders" WHERE "systemName"=%s''',
|
FROM "Orders" WHERE "systemName"=%s''',
|
||||||
("SDS",),
|
("SDS",),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user