fix: resolve out-of-range date error (31 days) in monthly stats calculation

This commit is contained in:
haneulai 2026-06-15 13:53:33 +09:00
parent 72a85b0ff6
commit 5c504f7747

View File

@ -139,10 +139,14 @@ def calculate_monthly_stats(target_month: str):
for pid in plant_ids: for pid in plant_ids:
# 2. 해당 월의 Daily 합계 조회 # 2. 해당 월의 Daily 합계 조회
import calendar
year_str, month_str = target_month.split("-")
last_day = calendar.monthrange(int(year_str), int(month_str))[1]
d_res = client.table("daily_stats").select("total_generation") \ d_res = client.table("daily_stats").select("total_generation") \
.eq("plant_id", pid) \ .eq("plant_id", pid) \
.gte("date", f"{target_month}-01") \ .gte("date", f"{target_month}-01") \
.lte("date", f"{target_month}-31") \ .lte("date", f"{target_month}-{last_day:02d}") \
.execute() .execute()
if not d_res.data: if not d_res.data: