""" DB에 저장된 시간별 데이터의 current_kw 값 확인 """ import sys import os from datetime import datetime from dotenv import load_dotenv load_dotenv() if sys.platform.startswith('win'): sys.stdout.reconfigure(encoding='utf-8') sys.stderr.reconfigure(encoding='utf-8') current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) from database import get_supabase_client def check_current_kw(plant_id, plant_name, date_str): """특정 날짜의 시간별 데이터 current_kw 값 확인""" print(f"\n{'='*70}") print(f"🔍 [{plant_name}] {date_str} 시간별 데이터 확인") print(f"{'='*70}") client = get_supabase_client() if not client: return # 해당 날짜의 시간별 데이터 조회 result = client.table("solar_logs") \ .select("created_at, current_kw, today_kwh") \ .eq("plant_id", plant_id) \ .gte("created_at", f"{date_str}T00:00:00+09:00") \ .lt("created_at", f"{date_str}T23:59:59+09:00") \ .order("created_at", desc=False) \ .limit(30) \ .execute() if not result.data: print(" ❌ 데이터 없음") return print(f" 총 {len(result.data)}건 (최대 30건만 표시)\n") print(f" {'시간':<20} | {'current_kw':>12} | {'today_kwh':>12}") print(f" {'-'*20}+{'-'*14}+{'-'*14}") current_kw_zero_count = 0 current_kw_nonzero_count = 0 for record in result.data: created_at = record['created_at'] current_kw = record.get('current_kw', 0) or 0 today_kwh = record.get('today_kwh', 0) or 0 if current_kw == 0: current_kw_zero_count += 1 else: current_kw_nonzero_count += 1 print(f" {created_at:<20} | {current_kw:>12.2f} | {today_kwh:>12.2f}") print(f"\n 📊 통계:") print(f" current_kw = 0: {current_kw_zero_count}건") print(f" current_kw ≠ 0: {current_kw_nonzero_count}건") if current_kw_zero_count == len(result.data): print(f"\n ⚠️ 모든 current_kw 값이 0입니다!") print(f" ⚠️ 과거 데이터는 current_kw 대신 today_kwh(시간별 발전량)가 저장됩니다.") print(f" ⚠️ 차트는 today_kwh를 사용해야 합니다.") def main(): plants = [ ('kremc-05', '5호기'), ('nrems-09', '9호기') ] dates = ['2026-02-25', '2026-02-01'] for plant_id, plant_name in plants: for date_str in dates: check_current_kw(plant_id, plant_name, date_str) print(f"\n{'='*70}\n") if __name__ == "__main__": main()