dkrak737's picture
Upload folder using huggingface_hub
c8716b4 verified
Raw
History Blame Contribute Delete
2.5 kB
# -*- coding: utf-8 -*-
"""
decide.py
ν‘œμ€€ κ²°κ³Ό(BatteryResult) β†’ 3μ‘΄ νŒμ •. 순수 κ·œμΉ™, μž¬ν•™μŠ΅ μ—†μŒ.
3μ‘΄: 🟒 이상 μ—†μŒ / 🟑 κ²€ν†  ν•„μš” / πŸ”΄ 이상 있음
원칙: recall-first β€” λ†“μΉ˜λŠ” 것보닀 κ³Όν•˜κ²Œ κ±°λ₯΄λŠ” 게 λ‚«λ‹€.
νŒμ • κ·Όκ±°(νŒ€μ› μš΄μ˜κ°’):
- κ²€μΆœμ€ conf 0.05 OR μ§‘κ³„λ‘œ 이미 'λ°œν™”=결함'. μ—¬κΈ°μ„  conf 둜 red/yellow 만 κ°€λ₯Έλ‹€.
- cell porosity λŠ” λ¬Όλ¦¬ν•œκ³„(FP 0.21) β†’ μžλ™ reject κΈˆμ§€, 항상 'κ²€ν†  큐'(yellow).
- module κ²€μΆœ/swelling 은 μ‹ λ’° λ†’μŒ(recall~1.0, FP~0) β†’ ν™•μ‹  conf λ©΄ red.
- swelling 은 배터리 λΉ„μœ¨(>0.1)둜 이미 νŒμ •λ¨ β†’ λ°œν™” μ‹œ red.
"""
# κ²€μΆœ conf 이 이 κ°’ 이상이면 'ν™•μ •'(red), μš΄μ˜μž„κ³„(0.05)~HIGH λ©΄ 'μ•½ν•œ μ‹ ν˜Έ'(yellow).
HIGH = 0.50
# 결함 λ‚΄λΆ€λͺ… β†’ RAG/ν‘œμ‹œμš© 정식λͺ…
DEFECT_CANON = {"porosity": "porosity", "resin": "resin_overflow", "swelling": "swelling"}
def decide(result):
"""λ°˜ν™˜: {zone, defects, red, yellow, worst_conf, reasons}."""
ct = result["cell_type"]
red, yellow, reasons = [], [], []
# (1) swelling β€” module μ „μš©, λΉ„μœ¨λ‘œ 이미 배터리 νŒμ •λ¨
sw = result["swelling"]
if sw["flag"]:
red.append("swelling")
reasons.append(f"swelling 슬라이슀 λΉ„μœ¨ {sw['ratio']*100:.0f}% (>10%) β†’ μ „μ—­ 팽창")
# (2) κ²€μΆœ 결함 (porosity / resin) β€” ν˜•νƒœλ³„ μ‹ λ’°λ„λ‘œ zone λΆ„κΈ°
for d in ("porosity", "resin"):
info = result[d]
if not info["flag"]:
continue
cf = info["conf"]
if ct == "cell":
yellow.append(d)
reasons.append(f"{d} κ²€μΆœ (cell λ¬Όλ¦¬ν•œκ³„ β†’ κ²€ν†  큐, conf {cf:.2f})")
elif cf >= HIGH:
red.append(d)
reasons.append(f"{d} ν™•μ • (conf {cf:.2f})")
else:
yellow.append(d)
reasons.append(f"{d} μ•½ν•œ μ‹ ν˜Έ (conf {cf:.2f})")
# (3) μ‘΄ κ²°μ • β€” λ‚˜μœ μͺ½ μš°μ„ 
if red:
zone = "πŸ”΄ 이상 있음"
elif yellow:
zone = "🟑 κ²€ν†  ν•„μš”"
else:
zone = "🟒 이상 μ—†μŒ"
reasons.append("μ„Έ 결함 λͺ¨λ‘ 미탐지")
return {
"zone": zone,
"defects": red + yellow, # λ‚΄λΆ€λͺ…(porosity/resin/swelling)
"red": red,
"yellow": yellow,
"worst_conf": max(result["porosity"]["conf"], result["resin"]["conf"], sw["conf"]),
"reasons": reasons,
}