diff --git a/src/forecaster/service/ForecasterServiceServicerImpl.py b/src/forecaster/service/ForecasterServiceServicerImpl.py index c480d3c95fd29189f538aed801879303a3db3ff5..41f6a59fd1e99f1ca336b65139eb9399d1aeec1a 100644 --- a/src/forecaster/service/ForecasterServiceServicerImpl.py +++ b/src/forecaster/service/ForecasterServiceServicerImpl.py @@ -25,11 +25,11 @@ from common.proto.forecaster_pb2_grpc import ForecasterServiceServicer from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.tools.context_queries.Link import get_link from common.tools.context_queries.Topology import get_topology_details +from common.tools.timestamp.Converters import timestamp_utcnow_to_float from context.client.ContextClient import ContextClient from forecaster.Config import FORECAST_TO_HISTORY_RATIO from forecaster.service.Forecaster import compute_forecast from forecaster.service.KpiManager import KpiManager -from forecaster.service.Tools import time_utc_now_to_float LOGGER = logging.getLogger(__name__) @@ -66,7 +66,7 @@ class ForecasterServiceServicerImpl(ForecasterServiceServicer): } kpi_id = link_uuid__to__kpi_id[link_uuid] - end_timestamp = time_utc_now_to_float() + end_timestamp = timestamp_utcnow_to_float() start_timestamp = end_timestamp - history_window_seconds df_historical_data = self._kpi_manager.get_kpi_id_samples([kpi_id], start_timestamp, end_timestamp) forecast_used_capacity_gbps = compute_forecast(df_historical_data, kpi_id) @@ -110,7 +110,7 @@ class ForecasterServiceServicerImpl(ForecasterServiceServicer): } kpi_ids = list(link_uuid__to__kpi_id.values()) - end_timestamp = time_utc_now_to_float() + end_timestamp = timestamp_utcnow_to_float() start_timestamp = end_timestamp - history_window_seconds df_historical_data = self._kpi_manager.get_kpi_id_samples(kpi_ids, start_timestamp, end_timestamp) diff --git a/src/forecaster/service/Tools.py b/src/forecaster/service/Tools.py deleted file mode 100644 index 93e052fe8535b9d7d5a6753133e948c45c17f037..0000000000000000000000000000000000000000 --- a/src/forecaster/service/Tools.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import calendar -from datetime import datetime, timezone - -def time_datetime_to_int(dt_time : datetime) -> int: - return int(calendar.timegm(dt_time.timetuple())) - -def time_datetime_to_float(dt_time : datetime) -> float: - return time_datetime_to_int(dt_time) + (dt_time.microsecond / 1.e6) - -def time_utc_now_to_datetime() -> datetime: - return datetime.now(tz=timezone.utc) - -def time_utc_now_to_float() -> float: - return time_datetime_to_float(time_utc_now_to_datetime()) diff --git a/src/forecaster/tests/Tools.py b/src/forecaster/tests/Tools.py index 5815112b4449d808d52725994887e56216ccbdca..9968eaea998bd53d1fc9b0290647d5a93ac0a29e 100644 --- a/src/forecaster/tests/Tools.py +++ b/src/forecaster/tests/Tools.py @@ -12,31 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -import calendar, logging, math, pandas -from datetime import datetime, timezone +import logging, math, pandas from typing import Dict from common.tools.object_factory.Context import json_context from common.tools.object_factory.Device import ( json_device_emulated_connect_rules, json_device_emulated_packet_router_disabled, json_device_id ) -from common.tools.object_factory.EndPoint import json_endpoint, json_endpoint_descriptor, json_endpoint_id +from common.tools.object_factory.EndPoint import json_endpoint, json_endpoint_id from common.tools.object_factory.Link import json_link from common.tools.object_factory.Topology import json_topology +from common.tools.timestamp.Converters import timestamp_datetime_to_int, timestamp_utcnow_to_float LOGGER = logging.getLogger(__name__) -def time_datetime_to_int(dt_time : datetime) -> int: - return int(calendar.timegm(dt_time.timetuple())) - -def time_datetime_to_float(dt_time : datetime) -> float: - return time_datetime_to_int(dt_time) + (dt_time.microsecond / 1.e6) - -def time_utc_now_to_datetime() -> datetime: - return datetime.now(tz=timezone.utc) - -def time_utc_now_to_float() -> float: - return time_datetime_to_float(time_utc_now_to_datetime()) - def read_csv(csv_file : str) -> pandas.DataFrame: LOGGER.info('Using Data File "{:s}"...'.format(csv_file)) @@ -57,8 +45,8 @@ def read_csv(csv_file : str) -> pandas.DataFrame: LOGGER.info('Updating timestamps...') df['timestamp'] = pandas.to_datetime(df['timestamp']) - max_timestamp = time_datetime_to_int(df['timestamp'].max()) - now_timestamp = time_datetime_to_int(datetime.now(tz=timezone.utc)) + max_timestamp = timestamp_datetime_to_int(df['timestamp'].max()) + now_timestamp = timestamp_utcnow_to_float() df['timestamp'] = df['timestamp'] + pandas.offsets.Second(now_timestamp - max_timestamp) LOGGER.info(' DONE') diff --git a/src/forecaster/tests/test_unitary.py b/src/forecaster/tests/test_unitary.py index 8e86fc9131907cb6dc31a9757eeaf966e6d5dbc0..a7dbeb2eda41d7ace8edbc83ad12a6efc3352609 100644 --- a/src/forecaster/tests/test_unitary.py +++ b/src/forecaster/tests/test_unitary.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json, logging, pandas, pytest +import logging, pandas, pytest #, json from typing import Dict, Tuple from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME from common.proto.context_pb2 import ContextId, TopologyId