#!/usr/bin/env python3
import sqlite3
from pathlib import Path

db_path = 'src/quant_engine/kis_data_collection.db'
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# 테이블 확인
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = [row[0] for row in cursor.fetchall()]

print('='*80)
print('KIS Data Collection DB Status')
print('='*80)
print(f'File size: {Path(db_path).stat().st_size / 1024:.2f} KB')
print(f'Tables: {tables}')

# data_feed 레코드 조회
if 'data_feed' in tables:
    cursor.execute('SELECT COUNT(*) FROM data_feed')
    count = cursor.fetchone()[0]
    print(f'\ndata_feed table: {count} records')

    # 샘플 출력
    cursor.execute('''
        SELECT ticker, name, close_price, entry_date, entry_stage, sector
        FROM data_feed
        ORDER BY entry_date DESC
    ''')

    print('\n[Loaded Records]')
    for row in cursor.fetchall():
        ticker, name, price, date, stage, sector = row
        print(f'  {ticker:8} | {name:15} | {price:>10.0f} KRW | {date} | {stage:4} | {sector}')

conn.close()
