From c9109ba8eddf518666417ce14d256e8bcfb9c397 Mon Sep 17 00:00:00 2001
From: Andreas Tsagkaropoulos <atsagkaropoulos@mail.ntua.gr>
Date: Tue, 14 May 2024 18:45:11 +0300
Subject: [PATCH] Bug fixes

Fixed a regression involving the erroneous storage of the created datasets for the forecasting
Improved a diagnostic message during dataset creation
Change-Id: Ic8aaa0728a4b936cd4c6e1ed5a0e01ba8f0fb003

Change-Id: Ic3c8d0eeeeb7d908d5c866e33806db138b6b557f
---
 .../prediction_configuration.properties          |  2 +-
 .../src/runtime/Predictor.py                     | 16 +++++++++++-----
 .../operational_status/ApplicationState.py       |  2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/exponential-smoothing-predictor/src/r_predictors/prediction_configuration.properties b/exponential-smoothing-predictor/src/r_predictors/prediction_configuration.properties
index 4175ec9..9cb3f0d 100644
--- a/exponential-smoothing-predictor/src/r_predictors/prediction_configuration.properties
+++ b/exponential-smoothing-predictor/src/r_predictors/prediction_configuration.properties
@@ -1,4 +1,4 @@
-#Tue May 14 12:59:33 UTC 2024
+#Tue May 14 15:38:04 UTC 2024
 APP_NAME=default_application
 METHOD=exponential_smoothing
 INFLUXDB_HOSTNAME=nebulous-influxdb
diff --git a/exponential-smoothing-predictor/src/runtime/Predictor.py b/exponential-smoothing-predictor/src/runtime/Predictor.py
index 631ebaf..7eff47c 100644
--- a/exponential-smoothing-predictor/src/runtime/Predictor.py
+++ b/exponential-smoothing-predictor/src/runtime/Predictor.py
@@ -86,11 +86,9 @@ def predict_attribute(application_state, attribute, configuration_file_location,
 
         # Windows
         if platform == "win32":
-            os.chdir("exponential-smoothing-predictor/src/r_predictors")
             command = ['Rscript', 'forecasting_real_workload.R', application_state.prediction_data_filename, attribute]
         # linux
         elif platform == "linux" or platform == "linux2":
-            os.chdir("/home/r_predictions")
             command = ["Rscript forecasting_real_workload.R "+str(application_state.prediction_data_filename) + " "+ str(attribute)]
         #Choosing the solution of linux
         else:
@@ -101,15 +99,12 @@ def predict_attribute(application_state, attribute, configuration_file_location,
 
         # Windows
         if platform == "win32":
-            os.chdir("exponential-smoothing-predictor/src/r_predictors")
             command = ['Rscript', 'forecasting_real_workload.R', application_state.prediction_data_filename, attribute, next_prediction_time]
         # Linux
         elif platform == "linux" or platform == "linux2":
-            os.chdir("/home/r_predictions")
             command = ["Rscript forecasting_real_workload.R "+str(application_state.prediction_data_filename) + " "+ str(attribute)+" "+str(next_prediction_time) + " 2>&1"]
         #Choosing the solution of linux
         else:
-            os.chdir("/home/r_predictions")
             command = ["Rscript forecasting_real_workload.R "+str(application_state.prediction_data_filename) + " "+ str(attribute)+" "+str(next_prediction_time)]
 
     process_output = run(command, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
@@ -456,6 +451,17 @@ def get_dataset_file(attribute):
     pass
 
 def main():
+
+    #Change to the appropriate directory in order i) To invoke the forecasting script appropriately and ii) To store the monitoring data necessary for predictions
+    from sys import platform
+    if platform == "win32":
+        os.chdir("exponential-smoothing-predictor/src/r_predictors")
+        # linux
+    elif platform == "linux" or platform == "linux2":
+        os.chdir("/home/r_predictions")
+    else:
+        os.chdir("/home/r_predictions")
+
     EsPredictorState.configuration_file_location = sys.argv[1]
     Utilities.load_configuration()
     Utilities.update_influxdb_organization_id()
diff --git a/exponential-smoothing-predictor/src/runtime/operational_status/ApplicationState.py b/exponential-smoothing-predictor/src/runtime/operational_status/ApplicationState.py
index c9e85bf..8075704 100644
--- a/exponential-smoothing-predictor/src/runtime/operational_status/ApplicationState.py
+++ b/exponential-smoothing-predictor/src/runtime/operational_status/ApplicationState.py
@@ -92,7 +92,7 @@ class ApplicationState:
                 print_data_from_db = True
                 query_string = 'from(bucket: "'+self.influxdb_bucket+'")  |> range(start:-'+time_interval_to_get_data_for+')  |> filter(fn: (r) => r["_measurement"] == "'+metric_name+'")'
                 influx_connector = InfluxDBConnector()
-                print("performing query")
+                print("performing query for application with bucket "+str(self.influxdb_bucket))
                 current_time = time.time()
                 result = influx_connector.client.query_api().query(query_string, EsPredictorState.influxdb_organization)
                 elapsed_time = time.time()-current_time