fix: Ensure current year is included in yearly stats even if no data
This commit is contained in:
parent
39c7928895
commit
3b9403b654
|
|
@ -143,12 +143,17 @@ async def get_plant_stats(
|
|||
year_key = date_str[:4]
|
||||
yearly[year_key] = yearly.get(year_key, 0) + val
|
||||
|
||||
sorted_keys = sorted(yearly.keys())
|
||||
data = [
|
||||
{"label": k, "value": round(yearly[k], 2)}
|
||||
for k in sorted_keys
|
||||
if k >= str(start_date.year)
|
||||
]
|
||||
# 최근 10년 (또는 지정된 기간) 연도별 데이터 생성 (데이터 없으면 0)
|
||||
data = []
|
||||
target_start_year = start_date.year
|
||||
current_year = today.year
|
||||
|
||||
for y in range(target_start_year, current_year + 1):
|
||||
y_str = str(y)
|
||||
data.append({
|
||||
"label": y_str,
|
||||
"value": round(yearly.get(y_str, 0), 2)
|
||||
})
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user