{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "# Import required libraries\n",
    "import os\n",
    "import json\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# Directories for analysis\n",
    "base_dir = \"artefact-directory/experiment-data\"\n",
    "providers = [\"aws\", \"ibm\"]\n",
    "setups = [\"heterogenous\", \"homogenous\"]\n",
    "modes = [\"cas\", \"karpenter\"]\n",
    "\n",
    "# Initialize results dictionary\n",
    "results = {}\n",
    "\n",
    "# Function to calculate scaling speed\n",
    "def calculate_scaling_speed(values):\n",
    "    timestamps = [val[0] for val in values]\n",
    "    deltas = np.diff(timestamps)\n",
    "    return np.mean(deltas)\n",
    "\n",
    "# Function to calculate average utilization\n",
    "def calculate_average_utilization(values):\n",
    "    utilizations = [float(val[1]) for val in values]\n",
    "    return np.mean(utilizations)\n",
    "\n",
    "# Traverse directories and process files\n",
    "for provider in providers:\n",
    "    results[provider] = {}\n",
    "    for setup in setups:\n",
    "        results[provider][setup] = {}\n",
    "        for mode in modes:\n",
    "            # Define the path to the JSON file\n",
    "            json_path = os.path.join(base_dir, provider, setup, mode, \"NodeCount.json\")\n",
    "            if os.path.exists(json_path):\n",
    "                with open(json_path, \"r\") as file:\n",
    "                    data = json.load(file)\n",
    "                    values = data[\"data\"][\"result\"][0][\"values\"]\n",
    "                    # Calculate metrics\n",
    "                    scaling_speed = calculate_scaling_speed(values)\n",
    "                    average_utilization = calculate_average_utilization(values)\n",
    "                    # Store results\n",
    "                    results[provider][setup][mode] = {\n",
    "                        \"Scaling Speed\": scaling_speed,\n",
    "                        \"CPU Utilization\": average_utilization,\n",
    "                        \"Memory Utilization\": average_utilization,  # Placeholder for memory\n",
    "                        \"Cost Efficiency\": \"$X per hour\",  # Placeholder for cost\n",
    "                        \"Resource Provisioning\": \"Dynamic\" if mode == \"karpenter\" else \"Static\"\n",
    "                    }\n",
    "\n",
    "# Convert results to DataFrame for display\n",
    "def format_results(results, scenario):\n",
    "    rows = []\n",
    "    for provider, setups in results.items():\n",
    "        for setup, modes in setups.items():\n",
    "            for mode, metrics in modes.items():\n",
    "                rows.append([\n",
    "                    f\"Scenario {scenario}: {provider.upper()}\",\n",
    "                    setup.capitalize(),\n",
    "                    mode.capitalize(),\n",
    "                    metrics[\"Scaling Speed\"],\n",
    "                    metrics[\"CPU Utilization\"],\n",
    "                    metrics[\"Memory Utilization\"],\n",
    "                    metrics[\"Cost Efficiency\"],\n",
    "                    metrics[\"Resource Provisioning\"]\n",
    "                ])\n",
    "    return pd.DataFrame(rows, columns=[\n",
    "        \"Scenario\", \"Setup\", \"Mode\", \"Scaling Speed (mins)\",\n",
    "        \"CPU Utilization (%)\", \"Memory Utilization (%)\",\n",
    "        \"Cost Efficiency\", \"Resource Provisioning\"\n",
    "    ])\n",
    "\n",
    "# Format results for Scenario 1 and Scenario 2\n",
    "scenario_1_results = format_results(results, 1)\n",
    "scenario_2_results = format_results(results, 2)\n",
    "\n",
    "# Display results as tables\n",
    "from IPython.display import display\n",
    "print(\"Scenario 1 Results:\")\n",
    "display(scenario_1_results)\n",
    "print(\"Scenario 2 Results:\")\n",
    "display(scenario_2_results)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
