86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""도면 분할 통합 테스트
|
|
|
|
테스트 항목:
|
|
1. split_drawings() 호출 → 도면 영역 목록 반환
|
|
2. extract_region() 호출 → 각 도면별 엔티티 추출
|
|
3. 검증: 도면별 엔티티 합계 vs 전체 엔티티 수
|
|
4. 처리 시간 측정 (< 30초)
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "mcp-server"))
|
|
|
|
from pipeline.extractor import PidGeometricExtractor
|
|
|
|
|
|
def main():
|
|
dxf_path = "src/Web/uploads/pid/No-10_Plant_PID.dxf"
|
|
if not os.path.exists(dxf_path):
|
|
print(f"파일을 찾을 수 없습니다: {dxf_path}")
|
|
sys.exit(1)
|
|
|
|
t0 = time.time()
|
|
print(f"DXF 로드: {dxf_path}")
|
|
extractor = PidGeometricExtractor(dxf_path)
|
|
|
|
# 1. 전체 추출 (비교 기준)
|
|
t1 = time.time()
|
|
geo_path = "/tmp/test_full_geo.json"
|
|
extractor.extract_and_save(geo_path)
|
|
import json
|
|
with open(geo_path) as f:
|
|
full_data = json.load(f)
|
|
full_count = len(full_data)
|
|
print(f"전체 추출: {full_count}개 엔티티 ({time.time()-t1:.1f}s)")
|
|
|
|
# 2. 도면 분할
|
|
t2 = time.time()
|
|
regions = extractor.split_drawings()
|
|
print(f"\n도면 분할: {len(regions)}개 영역 ({time.time()-t2:.1f}s)")
|
|
for r in regions:
|
|
print(f" 도면 #{r.drawing_no}: X={r.x_min:.0f}~{r.x_max:.0f}, Y={r.y_min:.0f}~{r.y_max:.0f}, 엔티티={r.entity_count}")
|
|
|
|
# 3. 영역별 추출
|
|
t3 = time.time()
|
|
total_region_entities = 0
|
|
all_region_ids = set()
|
|
for region in regions:
|
|
region_data = extractor.extract_region(region)
|
|
count = len(region_data)
|
|
total_region_entities += count
|
|
region_ids = {e["entity_id"] for e in region_data}
|
|
all_region_ids.update(region_ids)
|
|
print(f" 도면 #{region.drawing_no} 추출: {count}개 엔티티")
|
|
print(f"영역별 추출 완료: {time.time()-t3:.1f}s")
|
|
|
|
# 4. 검증
|
|
print(f"\n=== 검증 ===")
|
|
print(f"전체 엔티티: {full_count}")
|
|
print(f"도면별 엔티티 합계: {total_region_entities}")
|
|
print(f"도면별 고유 엔티티: {len(all_region_ids)}")
|
|
|
|
if total_region_entities == full_count:
|
|
print("✅ 엔티티 수 일치")
|
|
else:
|
|
diff = abs(total_region_entities - full_count)
|
|
print(f"⚠️ 차이: {diff}개 ({diff/full_count*100:.1f}%)")
|
|
|
|
total_time = time.time() - t0
|
|
print(f"\n총 처리 시간: {total_time:.1f}s")
|
|
if total_time < 30:
|
|
print("✅ 30초 이내 완료")
|
|
else:
|
|
print("❌ 30초 초과")
|
|
|
|
# 정리
|
|
os.unlink(geo_path)
|
|
print("\n테스트 완료.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|