버전 업그레이드

This commit is contained in:
2026-06-18 13:38:27 +09:00
parent a48a4b5fe5
commit ba33a78fec
37 changed files with 3355 additions and 1165 deletions

View File

@@ -2,17 +2,19 @@
import cv2
import numpy as np
# Cognex 카메라 셀 매핑 (GV 방식 fallback용으로 유지)
PATTERN_RESULT_CELLS = {
"A27": {"id": 1, "name": "LOW REF", "model": "LX3", "type": "RH"},
"A77": {"id": 2, "name": "LOW REF", "model": "LX3", "type": "LH"},
"A127": {"id": 3, "name": "LOW REF NAS", "model": "LX3", "type": "RH"},
"A177": {"id": 4, "name": "LOW REF NAS", "model": "LX3", "type": "LH"},
}
from db.sql_client import SQLClient
from logic.products import model_display_label
class Inspector:
def __init__(self):
self._pattern_cells: dict = {}
def set_pattern_cells(self, cells: dict):
"""DB 기반 PatMax 셀 매핑 (refresh_wk_results 시 갱신)."""
self._pattern_cells = cells or {}
# ── Python PatMax 매칭 (주 경로) ─────────────────────────────────── #
def match_image(self, image_bytes: bytes, matcher: "PatternMatcher") -> dict:
@@ -47,9 +49,9 @@ class Inspector:
# ── Cognex GV 셀 방식 (fallback) ────────────────────────────────── #
def read_patmax_results(self, insight) -> dict:
"""A27/A77/A127/A177 셀 조회 → #ERR이면 실패, 그 외 점수 파싱."""
"""PatMax 결과 셀 조회 → #ERR이면 실패, 그 외 점수 파싱."""
results = {}
for cell, model_info in PATTERN_RESULT_CELLS.items():
for cell, model_info in self._pattern_cells.items():
try:
insight._send(f"GV{cell}")
code = insight._read_line()
@@ -85,8 +87,10 @@ class Inspector:
# ── 공통: 모델 판별 + 판정 ──────────────────────────────────────── #
def identify_model(self, results: dict, allowed_model_ids: list) -> dict:
"""매칭된 패턴 중 점수가 가장 높은 것을 선택해 허용 모델 여부 판별."""
def identify_model(self, results: dict,
allowed_model_ids: "list | None" = None,
allowed_article_ids: "set | None" = None) -> dict:
"""매칭된 패턴 중 점수가 가장 높은 것을 선택해 허용 여부 판별."""
matched_patterns = [
(cell, info) for cell, info in results.items()
if info["matched"]
@@ -100,19 +104,26 @@ class Inspector:
}
_best_cell, best_info = max(matched_patterns, key=lambda x: x[1]["score"])
model = best_info["model"]
in_allowed = model["id"] in allowed_model_ids
model = best_info["model"]
label = model_display_label(model)
if allowed_article_ids is not None:
in_allowed = (
SQLClient._norm_id(model.get("article_id")) in allowed_article_ids
)
else:
in_allowed = model["id"] in (allowed_model_ids or [])
return {
"matched": True,
"in_allowed": in_allowed,
"model": model,
"score": best_info["score"],
"matched": True,
"in_allowed": in_allowed,
"model": model,
"score": best_info["score"],
"cognex_pass": in_allowed,
"status": (
f"{model['name']} {model['model']} {model['type']} ({best_info['score']:.1f}점)"
f"{label} ({best_info['score']:.1f}점)"
if in_allowed
else f"허용 외 모델: {model['name']} {model['model']} {model['type']}"
else f"작업 대상 외: {label}"
),
}