From 15056f056a49b5829ccac742c84dc235f8248ba8 Mon Sep 17 00:00:00 2001 From: Gregory Koronakos Date: Fri, 5 Apr 2024 20:13:25 +0300 Subject: [PATCH] Convert data_table Change-Id: Ie7df9bfb5950f8b1f4a8623cdb272faaa63d8c82 --- cfsb-backend/.env | 9 +++++++++ cfsb-backend/.env.prod | 2 +- cfsb-backend/Evaluation.py | 2 +- cfsb-backend/User_Functions.py | 14 ++++++++++++++ cfsb-backend/activemq.py | 4 ++++ cfsb-backend/routes.py | 2 ++ 6 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 cfsb-backend/.env diff --git a/cfsb-backend/.env b/cfsb-backend/.env new file mode 100644 index 0000000..ba8ab57 --- /dev/null +++ b/cfsb-backend/.env @@ -0,0 +1,9 @@ +NEBULOUS_BROKER_URL=localhost +NEBULOUS_BROKER_PORT=5672 +NEBULOUS_BROKER_USERNAME=admin +NEBULOUS_BROKER_PASSWORD=admin +POSTGRES_DB_HOST=127.0.0.1 +POSTGRES_DB_NAME=fog_broker +POSTGRES_DB_PORT=5432 +POSTGRES_DB_USER=dbuser +POSTGRES_DB_PASS=pass123 \ No newline at end of file diff --git a/cfsb-backend/.env.prod b/cfsb-backend/.env.prod index f3c9994..ce02585 100644 --- a/cfsb-backend/.env.prod +++ b/cfsb-backend/.env.prod @@ -1,5 +1,5 @@ NEBULOUS_BROKER_URL=158.37.63.86 -NEBULOUS_BROKER_PORT=31609 +NEBULOUS_BROKER_PORT=32754 NEBULOUS_BROKER_USERNAME=admin NEBULOUS_BROKER_PASSWORD=admin POSTGRES_DB_HOST=db diff --git a/cfsb-backend/Evaluation.py b/cfsb-backend/Evaluation.py index 8600faa..ede41f3 100644 --- a/cfsb-backend/Evaluation.py +++ b/cfsb-backend/Evaluation.py @@ -34,7 +34,7 @@ def perform_evaluation(data_table, relative_wr_data, immediate_wr_data, node_nam sorted_categories = sorted(fog_node_categories, reverse=True) # Create constraint matrices A_boolean = [] # This is the inequality constraint matrix - b_boolean = [] # This is be the inequality constraint vector + b_boolean = [] # This is the inequality constraint vector # Create constraints for each category having higher scores than the next lower category for higher_cat in range(len(sorted_categories) - 1): diff --git a/cfsb-backend/User_Functions.py b/cfsb-backend/User_Functions.py index 946f9ca..b6f55b7 100644 --- a/cfsb-backend/User_Functions.py +++ b/cfsb-backend/User_Functions.py @@ -287,6 +287,20 @@ def create_data_table(selected_criteria, extracted_data, field_mapping): return data_table + +# Used to convert RAM and # of Cores +def convert_data_table(created_data_table): + # Check if 'Number of CPU Cores' exists in the dictionary and convert its values + if 'Number of CPU Cores' in created_data_table: + created_data_table['Number of CPU Cores'] = [1/x for x in created_data_table['Number of CPU Cores']] + + # Check if 'Memory Size' exists in the dictionary and convert its values + if 'Memory Size' in created_data_table: + created_data_table['Memory Size'] = [1/x for x in created_data_table['Memory Size']] + + return created_data_table + + # Used to Append "Score" and "Rank" for each node in SAL's response JSON def append_evaluation_results(sal_reply_body, scores_and_ranks): # Check if sal_reply_body is a string and convert it to a Python object diff --git a/cfsb-backend/activemq.py b/cfsb-backend/activemq.py index be45ff9..2607f16 100644 --- a/cfsb-backend/activemq.py +++ b/cfsb-backend/activemq.py @@ -160,6 +160,10 @@ class SyncedHandler(Handler): # Check the number of nodes before Evaluation print("There are " + str(len(node_ids)) + " nodes for Evaluation") + print("Original created_data_table:", data_table) + # Convert RAM and Cores + data_table = convert_data_table(data_table) + print("Converted created_data_table:", data_table) ## Run evaluation evaluation_results = perform_evaluation(data_table, relative_wr_data, immediate_wr_data, node_names, node_ids) # print("Evaluation Results:", evaluation_results) diff --git a/cfsb-backend/routes.py b/cfsb-backend/routes.py index b91ecb9..33f313c 100644 --- a/cfsb-backend/routes.py +++ b/cfsb-backend/routes.py @@ -323,6 +323,8 @@ def process_evaluation_data(): # print("# node_names:", len(node_names)) # print("# node_ids:", len(node_ids)) + # Convert RAM and Cores + data_table = convert_data_table(data_table) # Run Optimization - Perform evaluation results = perform_evaluation(data_table, relative_wr_data, immediate_wr_data, node_names, node_ids) # print(results)