{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "660798fa-cf08-4cfd-b553-c6d750d7e7ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "import algo_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ff42670b-301d-4ee1-8da2-6a658fc5f286",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'_id': ObjectId('66ebba82a3b7dbe82538e34a'), 'name': 'Alice', 'age': 25, 'city': 'Beijing'}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import subprocess\n",
    "\n",
    "# 使用 subprocess 执行 .py 文件\n",
    "result = subprocess.run(['python', 'algo_test.py'], capture_output=True, text=True)\n",
    "\n",
    "# 打印输出\n",
    "print(result.stdout)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b47d615a-5953-43c0-9289-387d5c823a7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip freeze > requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "752c3ab3-cdef-47b0-9d9a-805348d30d6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.9.19 (main, May  6 2024, 20:12:36) [MSC v.1916 64 bit (AMD64)]\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print(sys.version)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output:\n",
      "Program starts execution!\n",
      "args: Namespace(timeBegin='2024-05-01', timeEnd='2024-09-20', col_time='C_TIME', user='root', password='mysql_T7yN3E', host='192.168.12.10', port=19306, database='ipfcst_j00260_20240911093804', agc_avc_table='t_power_station_status_data', mongondb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongondb_database='algorithm_platform', mongondb_read_table='J00260NWP', mongondb_write_table='J00260NWP_agcavc')\n",
      "Index(['_id', 'C_TIME', '理论功率', '第1个设备轮毂风速', '实际功率', '实时环境数据', '预测功率',\n",
      "       'NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向',\n",
      "       'NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向',\n",
      "       'NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向',\n",
      "       'NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向',\n",
      "       'NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射',\n",
      "       'NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'],\n",
      "      dtype='object')\n",
      "Collection 'J00260NWP_agcavc already exist, deleted successfully!\n",
      "data inserted successfully!\n",
      "Program execution ends!\n",
      "\n",
      "Error:\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import subprocess\n",
    "\n",
    "# 构建命令\n",
    "command = [\n",
    "    \"python\", \"processing_limit_power_by_agcavc.py\",\n",
    "    \"--timeBegin\", \"2024-05-01\",\n",
    "    \"--timeEnd\", \"2024-09-20\",\n",
    "    \"--col_time\", \"C_TIME\",\n",
    "    \"--user\", \"root\",\n",
    "    \"--password\", \"mysql_T7yN3E\",\n",
    "    \"--host\", \"192.168.12.10\",\n",
    "    \"--port\", \"19306\",\n",
    "    \"--database\", \"ipfcst_j00260_20240911093804\",\n",
    "    \"--agc_avc_table\",\"t_power_station_status_data\",\n",
    "    \"--mongondb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
    "    \"--mongondb_database\", \"algorithm_platform\",\n",
    "    \"--mongondb_read_table\", \"J00260NWP\",\n",
    "    \"--mongondb_write_table\", \"J00260NWP_agcavc\"\n",
    "]\n",
    "\n",
    "# 使用 subprocess.run 来执行命令\n",
    "result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n",
    "\n",
    "# 输出结果和错误信息\n",
    "print(\"Output:\")\n",
    "print(result.stdout)\n",
    "print(\"Error:\")\n",
    "print(result.stderr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
   "metadata": {},
   "outputs": [
    {
     "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>C_TIME</th>\n",
       "      <th>agc_avc_limit</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [C_TIME, agc_avc_limit]\n",
       "Index: []"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sqlalchemy import create_engine\n",
    "import pandas as pd\n",
    "engine = create_engine(f\"mysql+pymysql://root:mysql_T7yN3E@192.168.12.10:19306/ipfcst_j00260_20240911093804\")\n",
    "df = pd.read_sql_query(\"select  C_TIME, 1 as agc_avc_limit from t_power_station_status_data where C_TIME>='2024-05-01 00:00:00' and C_TIME<='2024-09-20 23:59:59' and  (C_IS_RATIONING_BY_AUTO_CONTROL is True or C_IS_RATIONING_BY_MANUAL_CONTROL=1)\",engine)\n",
    "df['C_TIME'] = pd.to_datetime(df['C_TIME']).dt.strftime('%Y-%m-%d %H:%M:%S')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b7a7834-530b-4afa-88f8-b1e51bb7d45b",
   "metadata": {},
   "outputs": [],
   "source": [
    "docker run processing_limit_by_agcavc     --timeBegin \"2024-05-01\"     --timeEnd \"2024-09-20\"     --col_time \"C_TIME\"     --user \"root\"     --password \"mysql_T7yN3E\"     --host \"192.168.12.10\"     --port \"19306\"     --database \"ipfcst_j00260_20240911093804\"     --agc_avc_table \"t_power_station_status_data\"     --mongondb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP\"     --mongondb_write_table \"J00260NWP_agcavc\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (panddlets)",
   "language": "python",
   "name": "panddlets"
  },
  "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.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
