Files
TK-BOM-Project/test_valve_classifier.py
Hyungi Ahn 92a78225f0 feat: 밸브 분류 시스템 및 구매 관리 시스템 기초 구현
 밸브 분류 시스템:
- VALVE 상세 정보 저장 로직 추가 (backend/app/routers/files.py)
- 프론트엔드 밸브 사양서 표시 로직 추가 (MaterialsPage.jsx)
- 밸브 분류기 테스트 스크립트 및 데이터 (test_valve_classifier.py, test_valve_bom.csv)

🛒 구매 관리 시스템:
- 구매 관리 테이블 스키마 (08_create_purchase_tables.sql)
- 구매확정 페이지 컴포넌트 (PurchaseConfirmationPage.jsx)
- MaterialsPage에 구매확정 버튼 추가

🎯 주요 기능:
- 밸브 타입, 연결방식, 압력등급, 재질 분류
- 구매 품목 마스터, 주문 관리, 리비전 추적
- 파이프 절단손실 및 6M 단위 계산 준비
2025-07-18 13:12:41 +09:00

156 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""
밸브 분류기 테스트
실제 밸브 데이터로 분류 성능 확인
"""
import sys
import os
sys.path.append('backend')
from app.services.valve_classifier import classify_valve
def test_valve_classifier():
"""다양한 밸브 데이터로 분류 테스트"""
print("🔧 밸브 분류기 테스트 시작\n")
# 테스트 데이터 (실제 BOM에서 가져온 데이터)
test_valves = [
{
"description": "GATE VALVE, 150LB, FL, 4\", ASTM A216 WCB, RF",
"main_nom": "4\"",
"expected": "GATE_VALVE"
},
{
"description": "BALL VALVE, 300LB, THREADED, 2\", SS316, FULL PORT",
"main_nom": "2\"",
"expected": "BALL_VALVE"
},
{
"description": "GLOBE VALVE, 600LB, SW, 1\", A105, Y-TYPE",
"main_nom": "1\"",
"expected": "GLOBE_VALVE"
},
{
"description": "CHECK VALVE, 150LB, WAFER, 6\", DCI, DUAL PLATE",
"main_nom": "6\"",
"expected": "CHECK_VALVE"
},
{
"description": "BUTTERFLY VALVE, 150LB, WAFER, 12\", DCI, GEAR OPERATED",
"main_nom": "12\"",
"expected": "BUTTERFLY_VALVE"
},
{
"description": "NEEDLE VALVE, 6000LB, SW, 1/2\", A182 F316, FINE ADJUST",
"main_nom": "1/2\"",
"expected": "NEEDLE_VALVE"
},
{
"description": "RELIEF VALVE, PSV, 150LB, FL, 3\", A216 WCB, SET 150 PSI",
"main_nom": "3\"",
"expected": "RELIEF_VALVE"
},
{
"description": "SOLENOID VALVE, 24VDC, 150LB, THD, 1/4\", SS316, 2-WAY NC",
"main_nom": "1/4\"",
"expected": "SOLENOID_VALVE"
}
]
total_tests = len(test_valves)
passed_tests = 0
for i, test_data in enumerate(test_valves, 1):
print(f"\n📋 테스트 {i}/{total_tests}: {test_data['description'][:50]}...")
# 분류 실행
result = classify_valve("", test_data["description"], test_data["main_nom"])
# 결과 출력
category = result.get("category", "UNKNOWN")
confidence = result.get("overall_confidence", 0.0)
valve_type = result.get("valve_type", {}).get("type", "UNKNOWN")
connection = result.get("connection_method", {}).get("method", "UNKNOWN")
pressure = result.get("pressure_rating", {}).get("rating", "UNKNOWN")
print(f" ✅ 분류: {category}")
print(f" 🔧 밸브타입: {valve_type}")
print(f" 🔗 연결방식: {connection}")
print(f" 📊 압력등급: {pressure}")
print(f" 🎯 신뢰도: {confidence:.2f}")
# 성공 여부 확인
if category == "VALVE" and valve_type == test_data["expected"]:
print(f" ✅ 성공: 예상({test_data['expected']}) = 결과({valve_type})")
passed_tests += 1
else:
print(f" ❌ 실패: 예상({test_data['expected']}) ≠ 결과({valve_type})")
# 실패 원인 분석
evidence = result.get("valve_type", {}).get("evidence", [])
print(f" 증거: {evidence}")
# 최종 결과
success_rate = (passed_tests / total_tests) * 100
print(f"\n🎉 테스트 완료!")
print(f"📊 성공률: {passed_tests}/{total_tests} ({success_rate:.1f}%)")
if success_rate >= 80:
print("✅ 밸브 분류기 성능 양호!")
elif success_rate >= 60:
print("⚠️ 밸브 분류기 성능 보통 - 개선 필요")
else:
print("❌ 밸브 분류기 성능 불량 - 대폭 개선 필요")
def test_special_valve_cases():
"""특수한 밸브 케이스 테스트"""
print("\n🔍 특수 밸브 케이스 테스트\n")
special_cases = [
{
"description": "밸브 없는 파이프",
"data": "PIPE, 4\", SCH40, ASTM A106 GR B, SMLS",
"main_nom": "4\"",
"should_reject": True
},
{
"description": "밸브 키워드만 있는 애매한 케이스",
"data": "VALVE HOUSING GASKET, 4\", GRAPHITE",
"main_nom": "4\"",
"should_reject": True
},
{
"description": "복합 밸브 (여러 타입 혼재)",
"data": "GATE BALL VALVE ASSEMBLY, 150LB, 2\"",
"main_nom": "2\"",
"should_reject": False
}
]
for case in special_cases:
print(f"📝 {case['description']}: {case['data']}")
result = classify_valve("", case["data"], case["main_nom"])
category = result.get("category", "UNKNOWN")
confidence = result.get("overall_confidence", 0.0)
print(f" 결과: {category} (신뢰도: {confidence:.2f})")
if case["should_reject"]:
if category == "UNKNOWN" or confidence < 0.5:
print(" ✅ 올바르게 거부됨")
else:
print(" ❌ 잘못 수용됨")
else:
if category == "VALVE" and confidence >= 0.5:
print(" ✅ 올바르게 수용됨")
else:
print(" ❌ 잘못 거부됨")
print()
if __name__ == "__main__":
test_valve_classifier()
test_special_valve_cases()