wing-ops/backend/src/db/seedHns.ts
Nan Kyung Lee 8f98f63aa5 feat(aerial): CCTV 실시간 HLS 스트림 + HNS 분석 고도화
CCTV 실시간 영상:
- CCTVPlayer 컴포넌트 (hls.js 기반 HLS/MJPEG/MP4 재생)
- 백엔드 HLS 프록시 엔드포인트 (CORS 우회, m3u8 URL 재작성)
- KHOA 15개 + KBS 6개 실제 해안 CCTV 연동
- Vite dev proxy, 스트림 타입 자동 감지 유틸리티

HNS 분석:
- HNS 시나리오 저장/불러오기/재계산 기능
- 물질 DB 검색 및 상세 정보 연동
- 좌표/파라미터 입력 UI 개선
- Python 확산 모델 스크립트 (hns_dispersion.py)

공통:
- 3D 지도 토글, 보고서 생성 개선
- useSubMenu 훅, mapUtils 확장
- ESLint set-state-in-effect 수정

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 17:21:41 +09:00

70 lines
2.2 KiB
TypeScript

import 'dotenv/config'
import { readFileSync } from 'node:fs'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { wingPool } from './wingDb.js'
const __dirname = dirname(fileURLToPath(import.meta.url))
// 통합 물질 데이터 JSON (기존 20종 상세 + Excel 1,202종 기본)
const dataPath = resolve(__dirname, '../../../frontend/src/data/hnsSubstanceData.json')
const HNS_SEARCH_DB = JSON.parse(readFileSync(dataPath, 'utf-8'))
async function seedHnsSubstances() {
console.log('HNS 물질정보 시드 시작...')
console.log(`${HNS_SEARCH_DB.length}종 물질 데이터 삽입 예정`)
const client = await wingPool.connect()
try {
await client.query('BEGIN')
// 기존 데이터 삭제
await client.query('DELETE FROM HNS_SUBSTANCE')
let inserted = 0
for (const s of HNS_SEARCH_DB) {
// 검색용 컬럼 추출, 나머지는 DATA JSONB로 저장
const { abbreviation, nameKr, nameEn, unNumber, casNumber, sebc, ...detailData } = s
await client.query(
`INSERT INTO HNS_SUBSTANCE (SBST_SN, ABBREVIATION, NM_KR, NM_EN, UN_NO, CAS_NO, SEBC, DATA)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT (SBST_SN) DO UPDATE SET
ABBREVIATION = EXCLUDED.ABBREVIATION,
NM_KR = EXCLUDED.NM_KR,
NM_EN = EXCLUDED.NM_EN,
UN_NO = EXCLUDED.UN_NO,
CAS_NO = EXCLUDED.CAS_NO,
SEBC = EXCLUDED.SEBC,
DATA = EXCLUDED.DATA`,
[s.id, abbreviation, nameKr, nameEn, unNumber, casNumber, sebc, JSON.stringify(detailData)]
)
inserted++
if (inserted % 100 === 0) {
console.log(` ${inserted}/${HNS_SEARCH_DB.length}건 삽입 완료...`)
}
}
await client.query('COMMIT')
// 결과 확인
const { rows } = await client.query('SELECT COUNT(*) as count FROM HNS_SUBSTANCE')
console.log(`시드 완료! 총 ${rows[0].count}종의 HNS 물질이 저장되었습니다.`)
} catch (err) {
await client.query('ROLLBACK')
console.error('HNS 시드 실패:', err)
throw err
} finally {
client.release()
await wingPool.end()
}
}
seedHnsSubstances().catch((err) => {
console.error(err)
process.exit(1)
})