From de73056ca9a8b9e0a4471bb6c7aeeb19d5f666e2 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Tue, 25 Feb 2025 12:29:49 +0700 Subject: [PATCH] fix --- src/calculation_time_constrains/service.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calculation_time_constrains/service.py b/src/calculation_time_constrains/service.py index 18770f4..580503a 100644 --- a/src/calculation_time_constrains/service.py +++ b/src/calculation_time_constrains/service.py @@ -165,27 +165,29 @@ async def get_corrective_cost_time_chart( for item in data["data"] } - # Initialize all months in the range with 0 monthly_data = {} current_date = start_date.replace(day=1) while current_date <= end_date: - monthly_data[current_date] = 0 + monthly_data[current_date] = float('inf') # Start with infinity to find minimum # Move to next month if current_date.month == 12: current_date = datetime.datetime(current_date.year + 1, 1, 1) else: current_date = datetime.datetime(current_date.year, current_date.month + 1, 1) - # Get the last day's value for each month + # Get the minimum value for each month for date in data_dict.keys(): month_key = datetime.datetime(date.year, date.month, 1) if month_key in monthly_data and data_dict[date] is not None: - # Update only if the value is higher (to get the last day's value) - monthly_data[month_key] = max(monthly_data[month_key], data_dict[date]) + # Update only if the value is lower (to get the minimum value) + monthly_data[month_key] = min(monthly_data[month_key], data_dict[date]) # Convert to list maintaining chronological order complete_data = [] for month in sorted(monthly_data.keys()): + # Replace any remaining infinity values with 0 or another appropriate default + if monthly_data[month] == float('inf'): + monthly_data[month] = 0 complete_data.append(monthly_data[month]) # Convert to numpy array