Commit 45a39702 authored by Anna Warno's avatar Anna Warno
Browse files

logs added

parent 08af8a14
......@@ -4,6 +4,7 @@ import stomp
import json
from amq_message_python_library import * # python amq-message-python-library
import logging
import time
AMQ_USER = os.environ.get("AMQ_USER", "admin")
AMQ_PASSWORD = os.environ.get("AMQ_PASSWORD", "admin")
......@@ -97,12 +98,11 @@ def main():
# msg1 = Msg()
# msg1.body = '[{"metric": "cpu_usage", "level": 3, "publish_rate": 60000}]'
# msg2 = Msg()
# msg2.body = """{
# "metrics": ["cpu_usage"],
# "timestamp": 0,
# "epoch_start": 0,
# "number_of_forward_predictions": 8,
# "prediction_horizon": 60}"""
# msg2.body = (
# "{"
# + f'"metrics": ["cpu_usage"],"timestamp": {int(time.time())}, "epoch_start": {int(time.time()) + 30}, "number_of_forward_predictions": 8,"prediction_horizon": 60'
# + "}"
# )
# StartListener(start_conn.conn, START_APP_TOPIC).on_message(msg1)
# StartForecastingListener(start_conn.conn, START_APP_TOPIC).on_message(msg2)
......
......@@ -112,9 +112,7 @@ def main():
logging.debug("prediction")
dataset_preprocessor.prepare_csv()
global time_0
time_1 = time_0
print("time 00000000 ", time_0)
time_0 = time_0 + prediction_cycle
for metric in predicted_metrics:
predictions = None
for i in range(number_of_forward_predictions[metric]):
......@@ -128,7 +126,7 @@ def main():
)
if i == (number_of_forward_predictions[metric] - 1):
print(
f"time_0 difference seconds {start_time + (i + 1) *prediction_horizon // 1000 - int(time.time())}"
f"time_0 difference seconds {start_time + (i + 1) * prediction_horizon // 1000 - int(time.time())}"
)
if predictions is not None:
predictions = pd.concat(
......@@ -139,11 +137,18 @@ def main():
if prediction_msgs:
dest = f"{PRED_TOPIC_PREF}.{metric}"
print(
f'{int(prediction_msgs[metric]["predictionTime"]) - int(prediction_msgs[metric]["timestamp"])} difference between timestamp and predicted in secnds'
)
print(
f'{int(prediction_msgs[metric]["predictionTime"]) - int(time.time())} difference between current time and predicted in secnds'
)
start_conn.send_to_topic(dest, prediction_msgs[metric])
influxdb_conn.send_to_influxdb(metric, prediction_msgs)
end_time = int(time.time())
print(f"sleeping {prediction_cycle - (end_time - start_time)} seconds")
time_0 = time_0 + prediction_cycle
time.sleep(prediction_cycle - (end_time - start_time))
......
......@@ -113,7 +113,6 @@ def main():
dataset_preprocessor.prepare_csv()
global time_0
print("time 00000000 ", time_0)
time_0 = time_0 + prediction_cycle
for metric in predicted_metrics:
predictions = None
for i in range(number_of_forward_predictions[metric]):
......@@ -127,7 +126,7 @@ def main():
)
if i == (number_of_forward_predictions[metric] - 1):
print(
f"time_0 difference seconds {start_time + (i + 1) *prediction_horizon // 1000 - int(time.time())}"
f"time_0 difference seconds {start_time + (i + 1) * prediction_horizon // 1000 - int(time.time())}"
)
if predictions is not None:
predictions = pd.concat(
......@@ -139,13 +138,17 @@ def main():
if prediction_msgs:
dest = f"{PRED_TOPIC_PREF}.{metric}"
print(
f'{int(prediction_msgs[metric]["predictionTime"]) - int(prediction_msgs[metric]["timestamp"])} difference between current and predicted in secnds'
f'{int(prediction_msgs[metric]["predictionTime"]) - int(prediction_msgs[metric]["timestamp"])} difference between timestamp and predicted in secnds'
)
print(
f'{int(prediction_msgs[metric]["predictionTime"]) - int(time.time())} difference between current time and predicted in secnds'
)
start_conn.send_to_topic(dest, prediction_msgs[metric])
influxdb_conn.send_to_influxdb(metric, prediction_msgs)
end_time = int(time.time())
print(f"sleeping {prediction_cycle - (end_time - start_time)} seconds")
time_0 = time_0 + prediction_cycle
time.sleep(prediction_cycle - (end_time - start_time))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment