diff --git a/compose.yml b/compose.yml index 149eac9..4214dac 100644 --- a/compose.yml +++ b/compose.yml @@ -31,6 +31,8 @@ services: security_opt: - no-new-privileges:true restart: unless-stopped + ports: + - 8086:8086 environment: DOCKER_INFLUXDB_INIT_MODE: "setup" DOCKER_INFLUXDB_INIT_USERNAME: "admin" diff --git a/provider_portal/app/api/customer_api/customer_api.py b/provider_portal/app/api/customer_api/customer_api.py index 1d51717..c7b5639 100644 --- a/provider_portal/app/api/customer_api/customer_api.py +++ b/provider_portal/app/api/customer_api/customer_api.py @@ -102,22 +102,27 @@ def get_meter_measurements(self, start_time, end_time, data_interval, meter_UID) Raises: ValueError: If the specified time range is in the future or exceeds the maximum data points allowed. """ - # Check if end_time is in the future - current_time = datetime.now(timezone(timedelta(hours=1))) - if datetime.fromisoformat(end_time.replace(" ", "+")) > current_time: - raise ValueError("error_no_data") - - # Check the number of data points based on the specified time range and data interval - time_diff = datetime.fromisoformat(end_time.replace(" ", "+")) - datetime.fromisoformat( - start_time.replace(" ", "+")) - num_data_points = int(time_diff.total_seconds() / int(data_interval)) - - if num_data_points > 3600: - raise ValueError("error_over_maximum") - - converted_start_time = start_time.replace(" ", "+") - converted_end_time = end_time.replace(" ", "+") - converted_data_interval = data_interval + "s" + try: + # Check if end_time is in the future + current_time = datetime.now(timezone(timedelta(hours=1))) + if datetime.fromisoformat(end_time.replace(" ", "+")) > current_time: + raise ValueError("error_no_data") + + # Check the number of data points based on the specified time range and data interval + time_diff = datetime.fromisoformat(end_time.replace(" ", "+")) - datetime.fromisoformat( + start_time.replace(" ", "+")) + num_data_points = int(time_diff.total_seconds() / int(data_interval)) + + if num_data_points > 3600: + raise ValueError("error_over_maximum") + + converted_start_time = start_time.replace(" ", "+") + converted_end_time = end_time.replace(" ", "+") + converted_data_interval = data_interval + "s" + except Exception as err: + logger.error(f"An exception occurred while decoding time format") + raise ValueError("error_decoding") + influxdb = InfluxDB() reading = influxdb.read(start_time=converted_start_time, end_time=converted_end_time, diff --git a/provider_portal/app/api/customer_api/routes.py b/provider_portal/app/api/customer_api/routes.py index bd41434..53c8aac 100644 --- a/provider_portal/app/api/customer_api/routes.py +++ b/provider_portal/app/api/customer_api/routes.py @@ -117,9 +117,10 @@ def meter_measurements(): api = CustomerAPI(customer_UID=customer_UID, api_key=api_key) auth_status = api.authenticate_customer_portal() else: + logger.error(f"An error while authenticating has occurred") raise ValueError("error_decoding") except Exception as err: - logger.error(f"An error has occurred within the get measurements: {err}") + logger.error(f"An error has occurred within the get measurements, while validation: {err}") res = {"message": "error_decoding"} return Response(dict=res).create_response()