diff --git a/Dockerfile b/Dockerfile index 6545d34..89155a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN rm -rf /app/tests/ RUN echo "# Custom configurations added by Dockerfile" >> /root/.bashrc && \ echo "export APP_PATH=/app" >> /root/.bashrc && \ echo "alias ll='ls -la'" >> /root/.bashrc && \ - echo "PASSWORD=\"supersecret\"" >> /root/.bashrc && \ + echo "PASSWORD=\"Aimo@2024\"" >> /root/.bashrc && \ echo "echo -n \"Enter password to access container: \"" >> /root/.bashrc && \ echo "read -s input_password" >> /root/.bashrc && \ echo "echo \"\"" >> /root/.bashrc && \ diff --git a/src/calculation_time_constrains/service.py b/src/calculation_time_constrains/service.py index f53c5c6..7f3a530 100644 --- a/src/calculation_time_constrains/service.py +++ b/src/calculation_time_constrains/service.py @@ -217,16 +217,22 @@ async def get_corrective_cost_time_chart( prediction_data = response.json() # Use the last prediction value for future months - latest_num = prediction_data["data"][-1]["num_fail"] if prediction_data["data"] else 1 - if not latest_num: + # Get the latest number from prediction data + latest_num = prediction_data["data"][-1]["num_fail"] + + # Ensure the value is at least 1 + if not latest_num or latest_num < 1: latest_num = 1 + else: + # Round the number to the nearest integer + latest_num = round(latest_num) # Create prediction dictionary prediction_dict = {} for item in prediction_data["data"]: date = datetime.datetime.strptime(item["date"], "%d %b %Y") month_key = datetime.datetime(date.year, date.month, 1) - prediction_dict[month_key] = item["num_fail"] + prediction_dict[month_key] = round(item["num_fail"]) # Update monthly_data with prediction data for key in prediction_dict: @@ -278,63 +284,13 @@ async def get_corrective_cost_time_chart( # Convert to numpy array monthly_failure = np.array(complete_data) - - # try: - # response = requests.get( - # url, - # headers={ - # "Content-Type": "application/json", - # "Authorization": f"Bearer {token}", - # }, - # ) - # data = response.json() - # latest_num = data["data"][-1]["num_fail"] - - # if not latest_num: - # latest_num = 1 - - # # Create a complete date range for 2025 - # date_range = [start_date + datetime.timedelta(days=x) for x in range(days_difference)] - - # # Create a dictionary of existing data - # data_dict = { - # datetime.datetime.strptime(item["date"], "%d %b %Y"): item["num_fail"] - # for item in data["data"] - # } - - # monthly_data = {} - # current_date = start_date.replace(day=1) - # while current_date <= end_date: - # 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 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 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 - # monthly_failure = np.array(complete_data) - - # Calculate corrective costs cost_per_failure = (material_cost + service_cost) / latest_num if cost_per_failure == 0: raise ValueError("Cost per failure cannot be zero") + # if location_tag == "3TR-TF005": + # raise Exception(cost_per_failure, latest_num) + corrective_costs = monthly_failure * cost_per_failure