🔧 볼트 재질 정보 개선 및 A320/A194M 패턴 지원
Some checks failed
SonarQube Analysis / SonarQube Scan (push) Has been cancelled
Some checks failed
SonarQube Analysis / SonarQube Scan (push) Has been cancelled
- bolt_classifier.py: A320/A194M 조합 패턴 처리 로직 추가 - material_grade_extractor.py: A320/A194M 패턴 추출 개선 - integrated_classifier.py: SPECIAL, U_BOLT 카테고리 우선 분류 - 데이터베이스: 492개 볼트의 material_grade를 완전한 형태로 업데이트 - A320/A194M GR B8/8: 78개 - A193/A194 GR B7/2H: 414개 - 프론트엔드: BOLT 카테고리 전용 UI (길이 표시) - Excel 내보내기: BOLT용 컬럼 순서 및 재질 정보 개선 - SPECIAL, U_BOLT 카테고리 지원 추가
This commit is contained in:
114
backend/scripts/26_update_bolt_material_grades.py
Normal file
114
backend/scripts/26_update_bolt_material_grades.py
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
볼트 재질 정보 업데이트 스크립트
|
||||
A320/A194M 패턴 등을 올바르게 인식하도록 기존 볼트들의 material_grade 재분류
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import psycopg2
|
||||
from psycopg2.extras import RealDictCursor
|
||||
|
||||
# 프로젝트 루트 디렉토리를 Python 경로에 추가
|
||||
sys.path.append('/app')
|
||||
|
||||
from app.services.bolt_classifier import classify_bolt_material
|
||||
|
||||
def update_bolt_material_grades():
|
||||
"""기존 볼트들의 material_grade 업데이트"""
|
||||
|
||||
# 데이터베이스 연결
|
||||
try:
|
||||
conn = psycopg2.connect(
|
||||
host=os.getenv('DB_HOST', 'postgres'),
|
||||
port=os.getenv('DB_PORT', '5432'),
|
||||
database=os.getenv('DB_NAME', 'tk_mp_bom'),
|
||||
user=os.getenv('DB_USER', 'tkmp_user'),
|
||||
password=os.getenv('DB_PASSWORD', 'tkmp2024!')
|
||||
)
|
||||
|
||||
cursor = conn.cursor(cursor_factory=RealDictCursor)
|
||||
|
||||
print("🔧 볼트 재질 정보 업데이트 시작...")
|
||||
|
||||
# 볼트 카테고리 자재들 조회
|
||||
cursor.execute("""
|
||||
SELECT id, original_description, material_grade, full_material_grade
|
||||
FROM materials
|
||||
WHERE classified_category = 'BOLT'
|
||||
ORDER BY id
|
||||
""")
|
||||
|
||||
bolts = cursor.fetchall()
|
||||
print(f"📊 총 {len(bolts)}개 볼트 발견")
|
||||
|
||||
updated_count = 0
|
||||
|
||||
for bolt in bolts:
|
||||
bolt_id = bolt['id']
|
||||
original_desc = bolt['original_description'] or ''
|
||||
current_material_grade = bolt['material_grade'] or ''
|
||||
current_full_grade = bolt['full_material_grade'] or ''
|
||||
|
||||
# 볼트 재질 재분류
|
||||
material_result = classify_bolt_material(original_desc)
|
||||
|
||||
if material_result and material_result.get('standard') != 'UNKNOWN':
|
||||
new_standard = material_result.get('standard', '')
|
||||
new_grade = material_result.get('grade', '')
|
||||
|
||||
# 새로운 material_grade 구성
|
||||
if new_grade and new_grade != 'UNKNOWN':
|
||||
if new_standard in new_grade:
|
||||
# 이미 standard가 포함된 경우 (예: "ASTM A320/A194M")
|
||||
new_material_grade = new_grade
|
||||
else:
|
||||
# standard + grade 조합 (예: "ASTM A193" + "B7")
|
||||
new_material_grade = f"{new_standard} {new_grade}" if new_grade not in new_standard else new_standard
|
||||
else:
|
||||
new_material_grade = new_standard
|
||||
|
||||
# 기존 값과 다른 경우에만 업데이트
|
||||
if new_material_grade != current_material_grade:
|
||||
print(f"🔄 ID {bolt_id}: '{current_material_grade}' → '{new_material_grade}'")
|
||||
print(f" 원본: {original_desc}")
|
||||
|
||||
cursor.execute("""
|
||||
UPDATE materials
|
||||
SET material_grade = %s
|
||||
WHERE id = %s
|
||||
""", (new_material_grade, bolt_id))
|
||||
|
||||
updated_count += 1
|
||||
|
||||
# 변경사항 커밋
|
||||
conn.commit()
|
||||
|
||||
print(f"✅ 볼트 재질 정보 업데이트 완료: {updated_count}개 업데이트됨")
|
||||
|
||||
# 업데이트 결과 확인
|
||||
cursor.execute("""
|
||||
SELECT material_grade, COUNT(*) as count
|
||||
FROM materials
|
||||
WHERE classified_category = 'BOLT'
|
||||
GROUP BY material_grade
|
||||
ORDER BY count DESC
|
||||
""")
|
||||
|
||||
results = cursor.fetchall()
|
||||
print("\n📈 업데이트 후 볼트 재질 분포:")
|
||||
for result in results:
|
||||
print(f" {result['material_grade']}: {result['count']}개")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 오류 발생: {str(e)}")
|
||||
if conn:
|
||||
conn.rollback()
|
||||
finally:
|
||||
if cursor:
|
||||
cursor.close()
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_bolt_material_grades()
|
||||
Reference in New Issue
Block a user