{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from EnergySystem import EnergySystem\n",
    "from config import pv_config, grid_config, ess_config\n",
    "\n",
    "\n",
    "data = pd.read_csv('combined_data.csv')\n",
    "time_interval = 15 / 60\n",
    "\n",
    "pv_loss = 0.98\n",
    "pv_cost_per_kW = 200\n",
    "pv_lifetime = 25\n",
    "\n",
    "ess_loss = 0.98\n",
    "ess_cost_per_kW = 300\n",
    "ess_lifetime = 25\n",
    "\n",
    "grid_loss = 0.98\n",
    "sell_price = 0.4 #kWh\n",
    "grid_capacity = 5000 #kWh\n",
    "\n",
    "pv_capacities = np.linspace(0, 28000, 29)\n",
    "ess_capacities = np.linspace(0, 28000, 29)\n",
    "results = pd.DataFrame(index=pv_capacities, columns = ess_capacities)\n",
    "for pv_capacity in pv_capacities:\n",
    "    print(f\"pv_capacity:{pv_capacity}\")\n",
    "    for ess_capacity in ess_capacities:\n",
    "        print(f\"ess_capacity:{ess_capacity}\")\n",
    "        pv = pv_config(capacity=pv_capacity, \n",
    "                        cost_per_kW=pv_cost_per_kW,\n",
    "                        lifetime=pv_lifetime, \n",
    "                        loss=pv_loss)\n",
    "        ess = ess_config(capacity=ess_capacity, \n",
    "                            cost_per_kW=ess_cost_per_kW, \n",
    "                            lifetime=ess_lifetime, \n",
    "                            loss=ess_loss,\n",
    "                            charge_power=ess_capacity,\n",
    "                            discharge_power=ess_capacity)\n",
    "        grid = grid_config(capacity=grid_capacity, \n",
    "                            grid_loss=grid_loss,\n",
    "                            sell_price= sell_price)\n",
    "        energySystem = EnergySystem(pv_type=pv, \n",
    "                                    ess_type=ess, \n",
    "                                    grid_type= grid)\n",
    "        benefit = energySystem.simulate(data, time_interval)\n",
    "        results.loc[pv_capacity,ess_capacity] = benefit\n",
    "        generated_list = energySystem.day_generated\n",
    "        plt.figure()\n",
    "        plt.plot(generated_list)\n",
    "        plt.xlabel('day #')\n",
    "        plt.ylabel('Electricity kWh')\n",
    "        plt.title(f'pv cap:{pv_capacity}, ess cap:{ess_capacity}')\n",
    "        plt.savefig(f'plots/{pv_capacity}-{ess_capacity}.png')\n",
    "        # plt.show()\n",
    "\n",
    "        \n",
    "\n",
    "# results = results.astype(float)\n",
    "\n",
    "\n",
    "# pv = pv_config(capacity=100000,cost_per_kW=200,lifetime=25,loss=0.95)\n",
    "# ess = ess_config(capacity=100000,cost_per_kW=300,lifetime=25,loss=0.95,charge_power=100000,discharge_power=100000)\n",
    "# grid = grid_config(price_schedule=price_schedule, capacity=5000, grid_loss=0.95, sell_price=0.4)\n",
    "# grid = grid_config(capacity=50000, grid_loss=0.95, sell_price=0.4)\n",
    "\n",
    "\n",
    "    # print(benefit)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=results\n",
    "df = df.astype(float)\n",
    "df.index = df.index / 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(220.72222222222223, 0.5, 'PV Capacity (MW)')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 754460 characters]",
      "text/plain": [
       "<Figure size 2000x1800 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(30, 28))  # 设置图形大小\n",
    "sns.heatmap(df/1000, annot=True, fmt=\".1f\", cmap='viridis')\n",
    "plt.title('Benefit Heatmap Based on PV and ESS Capacities')\n",
    "plt.gca().invert_yaxis()\n",
    "plt.xlabel('ESS Capacity (MWh)')\n",
    "plt.ylabel('PV Capacity (MW)')\n",
    "\n",
    "\n",
    "    # pv = pv_config(capacity=100000,cost_per_kW=200,lifetime=25,loss=0.95)\n",
    "    # ess = ess_config(capacity=100000,cost_per_kW=300,lifetime=25,loss=0.95,charge_power=100000,discharge_power=100000)\n",
    "    # grid = grid_config(price_schedule=price_schedule, capacity=5000, grid_loss=0.95, sell_price=0.4)\n",
    "    # grid = grid_config(capacity=50000, grid_loss=0.95, sell_price=0.4)\n",
    "\n",
    "\n",
    "    # print(benefit)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
