[예측] - OpenDrift Python API 서버 및 스크립트 추가 (prediction/opendrift/) - 시뮬레이션 상태 폴링 훅(useSimulationStatus), 로딩 오버레이 추가 - HydrParticleOverlay: deck.gl 기반 입자 궤적 시각화 레이어 - OilSpillView/LeftPanel/RightPanel: 시뮬레이션 실행·결과 표시 UI 개편 - predictionService/predictionRouter: 시뮬레이션 CRUD 및 상태 관리 API - simulation.ts: OpenDrift 연동 엔드포인트 확장 - docs/PREDICTION-GUIDE.md: 예측 기능 개발 가이드 추가 [CCTV/항공방제] - CCTV 오일 감지 GPU 추론 연동 (OilDetectionOverlay, useOilDetection) - CCTV 안전관리 감지 기능 추가 (선박 출입, 침입 감지) - oil_inference_server.py: Python GPU 추론 서버 [관리자] - 관리자 화면 고도화 (사용자/권한/게시판/선박신호 패널) - AdminSidebar, BoardMgmtPanel, VesselSignalPanel 신규 컴포넌트 [기타] - DB: 시뮬레이션 결과, 선박보험 시드(1391건), 역할 정리 마이그레이션 - 팀 워크플로우 v1.6.1 동기화 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
import os
|
|
import glob
|
|
from datetime import datetime
|
|
|
|
def find_nearest_earlier_file(folder_path, target_time_str):
|
|
"""
|
|
주어진 폴더에서 target_time_str (yyyymmddhhmmss)보다 빠르면서
|
|
가장 가까운 시간의 파일을 찾습니다.
|
|
|
|
:param folder_path: 파일을 검색할 폴더 경로
|
|
:param target_time_str: 기준 시간 문자열 (yyyymmddhhmmss 형식)
|
|
:return: 찾은 파일의 전체 경로 (없으면 None)
|
|
"""
|
|
# 1. 대상 시간을 datetime 객체로 변환
|
|
try:
|
|
# 파일명 형식 (yyyy-mm-dd hh:mm:ss)과 일치하는 포맷
|
|
target_time = datetime.strptime(target_time_str, '%Y-%m-%d %H:%M:%S')
|
|
except ValueError:
|
|
return f"오류: 입력된 기준 시간 '{target_time_str}'의 형식이 'yyyymmddhhmmss'와 일치하지 않습니다."
|
|
|
|
# 2. 폴더 내 파일 목록 가져오기 및 시간 정보 파싱
|
|
# '??????????????.png' 패턴으로 파일명 필터링
|
|
file_pattern = os.path.join(folder_path, '*.png')
|
|
all_files = glob.glob(file_pattern)
|
|
|
|
# 시간 차이와 파일 경로를 저장할 리스트
|
|
earlier_files = []
|
|
|
|
for file_path in all_files:
|
|
# 파일명에서 확장자를 제외한 부분 (시간 문자열) 추출
|
|
base_name = os.path.basename(file_path)
|
|
file_time_str = base_name.split('.')[0]
|
|
|
|
# 파일명 길이가 yyyymmddhhmmss (14자리)인지 확인
|
|
if len(file_time_str) == 14:
|
|
try:
|
|
# 파일 시간을 datetime 객체로 변환
|
|
file_time = datetime.strptime(file_time_str, '%Y%m%d%H%M%S')
|
|
|
|
# 3. 기준 시간보다 **이전**인 파일만 필터링
|
|
if file_time <= target_time:
|
|
# 기준 시간과의 차이 (양수)를 계산하고 저장
|
|
time_difference = target_time - file_time
|
|
earlier_files.append((time_difference, file_path))
|
|
|
|
except ValueError:
|
|
# 파일명이 14자리여도 datetime 변환에 실패하면 건너뜀
|
|
continue
|
|
|
|
# 4. 필터링된 파일 중 시간 차이가 가장 작은 (가장 가까운) 파일 찾기
|
|
if not earlier_files:
|
|
return None # 기준 시간보다 이전인 파일이 없는 경우
|
|
|
|
# 시간 차이를 기준으로 오름차순 정렬 (가장 작은 차이가 첫 번째 요소)
|
|
earlier_files.sort(key=lambda x: x[0])
|
|
|
|
# 가장 가까운 파일의 경로 반환
|
|
return earlier_files[0][1]
|