#!/usr/bin/env python3 """ settings를 올바르게 로드 (key-value 구조) """ import sqlite3 from pathlib import Path import pandas as pd def load_settings_correctly(): """settings를 올바르게 로드""" # XLSX에서 settings 로드 (헤더 없이) df = pd.read_excel('GatherTradingData.xlsx', sheet_name='settings', header=None) print("settings 원본 데이터:") print(f" Shape: {df.shape}") print(f" Row 0: {df.iloc[0, 0]} = {df.iloc[0, 1]}") # Column 0: key, Column 1: value, Column 2: note settings_list = [] for idx, row in df.iterrows(): key = str(row[0]) if pd.notna(row[0]) else "" value = str(row[1]) if pd.notna(row[1]) else "" note = str(row[2]) if pd.notna(row[2]) else "" if key: settings_list.append({ "ordinal": idx + 1, "key": key, "value": value, "note": note }) print(f"\n변환된 settings: {len(settings_list)} 행") print(f"첫 항목: {settings_list[0]}") # DB에 로드 db_path = Path('src/quant_engine/snapshot_admin.db') conn = sqlite3.connect(db_path) cursor = conn.cursor() # 기존 설정 스키마와 맞추기 # snapshot_admin_store_v1.py에서 기대하는 스키마 확인 cursor.execute("DROP TABLE IF EXISTS settings") cursor.execute(""" CREATE TABLE settings ( ordinal INTEGER PRIMARY KEY, key TEXT, value TEXT, note TEXT ) """) # 데이터 삽입 for row in settings_list: cursor.execute( "INSERT INTO settings (ordinal, key, value, note) VALUES (?, ?, ?, ?)", (row['ordinal'], row['key'], row['value'], row['note']) ) conn.commit() # 검증 cursor.execute("SELECT COUNT(*) FROM settings") count = cursor.fetchone()[0] print(f"\n[OK] settings 로드 완료: {count} rows") # 샘플 출력 print("\n샘플 데이터:") cursor.execute("SELECT ordinal, key, value FROM settings LIMIT 5") for ordinal, key, value in cursor.fetchall(): print(f" {ordinal}. {key} = {value}") conn.close() if __name__ == "__main__": load_settings_correctly()