import sys, os sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') from database import TradeDB from datetime import datetime db = TradeDB() day8 = "20260831" like = day8 + "%" try: # 1. ls_ws_ticks 오늘 집계 (수집통계 쿼리와 동일) d0 = datetime.strptime(day8, "%Y%m%d") d1 = d0.replace(hour=23, minute=59, second=59) r = db.conn.execute(""" SELECT count(*) as total, MAX(ts) as last_ts, COUNT(DISTINCT code) as codes FROM ls_ws_ticks WHERE ts >= %s AND ts <= %s """, (d0, d1)).fetchone() print("[ls_ws_ticks 오늘]:", dict(r)) # 2. target_candidates 후보 구독 현황 tc_cols = [dict(c)["Field"] for c in db.conn.execute("SHOW COLUMNS FROM target_candidates").fetchall()] print("\n[target_candidates 컬럼]:", tc_cols) tc = db.conn.execute("SELECT count(*) as c, market FROM target_candidates GROUP BY market").fetchall() for row in tc: print(f" {dict(row)}") # 3. target_candidates_history 오늘 tch_cols = [dict(c)["Field"] for c in db.conn.execute("SHOW COLUMNS FROM target_candidates_history").fetchall()] ts_col = next((c for c in ['scan_time','created_at','updated_at','ts'] if c in tch_cols), None) print(f"\n[target_candidates_history 오늘 - {ts_col}]") if ts_col: tch = db.conn.execute(f""" SELECT count(*) as c, COUNT(DISTINCT code) as codes FROM target_candidates_history WHERE DATE({ts_col}) = '2026-08-31' """).fetchone() print(f" {dict(tch)}") latest_tch = db.conn.execute(f"SELECT MAX({ts_col}) as last FROM target_candidates_history").fetchone() print(f" 최근: {dict(latest_tch)['last']}") # 4. ls_candidates_history 오늘 (LS 후보 이력) print("\n[ls_candidates_history 오늘]") lch_cols = [dict(c)["Field"] for c in db.conn.execute("SHOW COLUMNS FROM ls_candidates_history").fetchall()] lch_ts = next((c for c in ['scan_time','created_at','updated_at','ts'] if c in lch_cols), None) if lch_ts: lch = db.conn.execute(f""" SELECT count(*) as c, COUNT(DISTINCT code) as codes FROM ls_candidates_history WHERE DATE({lch_ts}) = '2026-08-31' """).fetchone() print(f" 오늘: {dict(lch)}") latest_lch = db.conn.execute(f"SELECT MAX({lch_ts}) as last FROM ls_candidates_history").fetchone() print(f" 최근: {dict(latest_lch)['last']}") # 5. 수집통계 탭 - LS 틱 후보구독 섹션 조회 # ws_ticks에 source='ls' 가 오늘 있는지 print("\n[ws_ticks에 source=ls 오늘]") ls_in_wsticks = db.conn.execute(f""" SELECT count(*) as c FROM ws_ticks WHERE tick_time LIKE %s AND source = 'ls' """, (like,)).fetchone() print(f" {dict(ls_in_wsticks)}") finally: db.close()