{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "vscode": {
          "languageId": "plaintext"
        }
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Scenario 1 Results:\n"
          ]
        },
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Scenario</th>\n",
              "      <th>Setup</th>\n",
              "      <th>Mode</th>\n",
              "      <th>Scaling Speed (mins)</th>\n",
              "      <th>CPU Utilization (%)</th>\n",
              "      <th>Memory Utilization (%)</th>\n",
              "      <th>Cost Efficiency</th>\n",
              "      <th>Resource Provisioning</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Scenario 1: IBM</td>\n",
              "      <td>Homogenous</td>\n",
              "      <td>Cas</td>\n",
              "      <td>30.0</td>\n",
              "      <td>6.0</td>\n",
              "      <td>6.0</td>\n",
              "      <td>$X per hour</td>\n",
              "      <td>Static</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Scenario 1: IBM</td>\n",
              "      <td>Homogenous</td>\n",
              "      <td>Karpenter</td>\n",
              "      <td>30.0</td>\n",
              "      <td>3.0</td>\n",
              "      <td>3.0</td>\n",
              "      <td>$X per hour</td>\n",
              "      <td>Dynamic</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          Scenario       Setup       Mode  Scaling Speed (mins)  \\\n",
              "0  Scenario 1: IBM  Homogenous        Cas                  30.0   \n",
              "1  Scenario 1: IBM  Homogenous  Karpenter                  30.0   \n",
              "\n",
              "   CPU Utilization (%)  Memory Utilization (%) Cost Efficiency  \\\n",
              "0                  6.0                     6.0     $X per hour   \n",
              "1                  3.0                     3.0     $X per hour   \n",
              "\n",
              "  Resource Provisioning  \n",
              "0                Static  \n",
              "1               Dynamic  "
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Scenario 2 Results:\n"
          ]
        },
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Scenario</th>\n",
              "      <th>Setup</th>\n",
              "      <th>Mode</th>\n",
              "      <th>Scaling Speed (mins)</th>\n",
              "      <th>CPU Utilization (%)</th>\n",
              "      <th>Memory Utilization (%)</th>\n",
              "      <th>Cost Efficiency</th>\n",
              "      <th>Resource Provisioning</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Scenario 2: IBM</td>\n",
              "      <td>Homogenous</td>\n",
              "      <td>Cas</td>\n",
              "      <td>30.0</td>\n",
              "      <td>6.0</td>\n",
              "      <td>6.0</td>\n",
              "      <td>$X per hour</td>\n",
              "      <td>Static</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Scenario 2: IBM</td>\n",
              "      <td>Homogenous</td>\n",
              "      <td>Karpenter</td>\n",
              "      <td>30.0</td>\n",
              "      <td>3.0</td>\n",
              "      <td>3.0</td>\n",
              "      <td>$X per hour</td>\n",
              "      <td>Dynamic</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          Scenario       Setup       Mode  Scaling Speed (mins)  \\\n",
              "0  Scenario 2: IBM  Homogenous        Cas                  30.0   \n",
              "1  Scenario 2: IBM  Homogenous  Karpenter                  30.0   \n",
              "\n",
              "   CPU Utilization (%)  Memory Utilization (%) Cost Efficiency  \\\n",
              "0                  6.0                     6.0     $X per hour   \n",
              "1                  3.0                     3.0     $X per hour   \n",
              "\n",
              "  Resource Provisioning  \n",
              "0                Static  \n",
              "1               Dynamic  "
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "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",
        "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(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)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.20"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}
