92 lines
2.5 KiB
Python
92 lines
2.5 KiB
Python
"""
|
|
2월 데이터 누락 확인 스크립트
|
|
정확히 어느 날짜의 데이터가 누락되었는지 확인
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from datetime import datetime, timedelta
|
|
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_gaps(plant_id, plant_name):
|
|
"""날짜별 시간별 데이터 누락 확인"""
|
|
|
|
print(f"\n{'='*70}")
|
|
print(f"🔍 [{plant_name}] 2월 시간별 데이터 누락 확인")
|
|
print(f"{'='*70}")
|
|
|
|
client = get_supabase_client()
|
|
if client is None:
|
|
return
|
|
|
|
# 2월 1일부터 27일까지 확인
|
|
start = datetime(2026, 2, 1)
|
|
end = datetime(2026, 2, 27)
|
|
|
|
current = start
|
|
missing_dates = []
|
|
partial_dates = []
|
|
|
|
while current <= end:
|
|
date_str = current.strftime("%Y-%m-%d")
|
|
|
|
# 해당 날짜의 시간별 데이터 개수 확인
|
|
result = client.table("solar_logs") \
|
|
.select("*", count='exact') \
|
|
.eq("plant_id", plant_id) \
|
|
.gte("created_at", f"{date_str}T00:00:00+09:00") \
|
|
.lt("created_at", f"{(current + timedelta(days=1)).strftime('%Y-%m-%d')}T00:00:00+09:00") \
|
|
.execute()
|
|
|
|
count = result.count if hasattr(result, 'count') else len(result.data)
|
|
|
|
if count == 0:
|
|
missing_dates.append(date_str)
|
|
print(f" ❌ {date_str}: 데이터 없음")
|
|
elif count < 24:
|
|
partial_dates.append((date_str, count))
|
|
print(f" ⚠️ {date_str}: {count}건 (불완전)")
|
|
else:
|
|
print(f" ✅ {date_str}: {count}건")
|
|
|
|
current += timedelta(days=1)
|
|
|
|
print(f"\n📊 요약:")
|
|
print(f" 완전 누락: {len(missing_dates)}일")
|
|
print(f" 부분 누락: {len(partial_dates)}일")
|
|
|
|
if missing_dates:
|
|
print(f"\n 누락된 날짜:")
|
|
for d in missing_dates:
|
|
print(f" - {d}")
|
|
|
|
if partial_dates:
|
|
print(f"\n 부분 누락된 날짜:")
|
|
for d, c in partial_dates:
|
|
print(f" - {d}: {c}/24건")
|
|
|
|
def main():
|
|
plants = [
|
|
('kremc-05', '5호기'),
|
|
('nrems-09', '9호기')
|
|
]
|
|
|
|
for plant_id, plant_name in plants:
|
|
check_gaps(plant_id, plant_name)
|
|
|
|
print(f"\n{'='*70}\n")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|