{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "752c3ab3-cdef-47b0-9d9a-805348d30d6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-11-21 09:07:30,205 - waitress - INFO - Serving on http://0.0.0.0:10086\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Program starts execution!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-11-21 09:07:33,171 - processing_limit_power_by_agcavc - INFO - {'timeBegin': '2024-03-05', 'timeEnd': '2024-09-04', 'col_time': 'dateTime', 'mysql_connection': 'mysql+pymysql://root:mysql_T7yN3E@192.168.12.10:19306/ipfcst_j00260_20240911093804', 'mongodb_database': 'db2', 'mongodb_read_table': 'j00629_copy', 'mongodb_write_table': 'j00629_copy_agcavc', 'agc_avc_table': 't_power_station_status_data'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Program starts execution!\n",
      "args {'timeBegin': '2024-03-05', 'timeEnd': '2024-09-04', 'col_time': 'dateTime', 'mysql_connection': 'mysql+pymysql://root:mysql_T7yN3E@192.168.12.10:19306/ipfcst_j00260_20240911093804', 'mongodb_database': 'db2', 'mongodb_read_table': 'j00629_copy', 'mongodb_write_table': 'j00629_copy_agcavc', 'agc_avc_table': 't_power_station_status_data'}\n",
      "Index(['_id', 'temperature10', 'temperature190', 'direction160', 'direction40',\n",
      "       'temperature110', 'direction80', 'speed60', 'globalr-1', 'mcc', 'dq',\n",
      "       'temperature150', 'speed20', 'speed110', 'direction120', 'speed190',\n",
      "       'solarZenith', 'temperature90', 'direction200', 'speed150',\n",
      "       'temperature50', 'direction30', 'temperature160', 'direction170',\n",
      "       'temperature20', 'direction70', 'direction130', 'temperature200',\n",
      "       'speed70', 'temperature120', 'speed30', 'speed100', 'speed80',\n",
      "       'speed180', 'dniCalcd', 'speed140', 'temperature60', 'dateTime',\n",
      "       'temperature30', 'temperature170', 'direction20', 'humidity2',\n",
      "       'reportCdq-0', 'direction180', 'realPowerAvg', 'direction60',\n",
      "       'direction140', 'speed40', 'hcc', 'clearskyGhi', 'temperature130',\n",
      "       'lcc', 'updater', 'speed90', 'temperature2', 'tcc', 'direction100',\n",
      "       'speed170', 'temperature70', 'speed130', 'direction190', 'openCapacity',\n",
      "       'temperature40', 'creator', 'direction10', 'temperature180',\n",
      "       'direction150', 'direction50', 'speed50', 'updateTime', 'direction90',\n",
      "       'farmId', 'temperature100', 'speed10', 'temperature140', 'speed120',\n",
      "       'reportDq-avg', 'deleted', 'speed200', 'realPower', 'createTime',\n",
      "       'radiation', 'surfacePressure', 'tpr', 'direction110', 'time',\n",
      "       'speed160', 'temperature80', 'reportMid-E395', 'reportDq-E1',\n",
      "       'reportCdq-16'],\n",
      "      dtype='object')\n",
      "data inserted successfully!\n",
      "Program execution ends!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-11-21 09:14:41,418 - processing_limit_power_by_agcavc - INFO - {'timeBegin': '2024-03-05', 'timeEnd': '2024-09-04', 'col_time': 'dateTime', 'mysql_connection': 'mysql+pymysql://root:mysql_T7yN3E@192.168.12.10:19306/ipfcst_j00629_20240820091235', 'mongodb_database': 'db2', 'mongodb_read_table': 'j00629_copy', 'mongodb_write_table': 'j00629_copy_agcavc', 'agc_avc_table': 't_power_station_status_data'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Program starts execution!\n",
      "args {'timeBegin': '2024-03-05', 'timeEnd': '2024-09-04', 'col_time': 'dateTime', 'mysql_connection': 'mysql+pymysql://root:mysql_T7yN3E@192.168.12.10:19306/ipfcst_j00629_20240820091235', 'mongodb_database': 'db2', 'mongodb_read_table': 'j00629_copy', 'mongodb_write_table': 'j00629_copy_agcavc', 'agc_avc_table': 't_power_station_status_data'}\n",
      "根据限电记录清洗，2024-03-05至2024-09-04，限电时长共计143.62小时\n",
      "Index(['_id', 'temperature10', 'temperature190', 'direction160', 'direction40',\n",
      "       'temperature110', 'direction80', 'speed60', 'globalr-1', 'mcc', 'dq',\n",
      "       'temperature150', 'speed20', 'speed110', 'direction120', 'speed190',\n",
      "       'solarZenith', 'temperature90', 'direction200', 'speed150',\n",
      "       'temperature50', 'direction30', 'temperature160', 'direction170',\n",
      "       'temperature20', 'direction70', 'direction130', 'temperature200',\n",
      "       'speed70', 'temperature120', 'speed30', 'speed100', 'speed80',\n",
      "       'speed180', 'dniCalcd', 'speed140', 'temperature60', 'dateTime',\n",
      "       'temperature30', 'temperature170', 'direction20', 'humidity2',\n",
      "       'reportCdq-0', 'direction180', 'realPowerAvg', 'direction60',\n",
      "       'direction140', 'speed40', 'hcc', 'clearskyGhi', 'temperature130',\n",
      "       'lcc', 'updater', 'speed90', 'temperature2', 'tcc', 'direction100',\n",
      "       'speed170', 'temperature70', 'speed130', 'direction190', 'openCapacity',\n",
      "       'temperature40', 'creator', 'direction10', 'temperature180',\n",
      "       'direction150', 'direction50', 'speed50', 'updateTime', 'direction90',\n",
      "       'farmId', 'temperature100', 'speed10', 'temperature140', 'speed120',\n",
      "       'reportDq-avg', 'deleted', 'speed200', 'realPower', 'createTime',\n",
      "       'radiation', 'surfacePressure', 'tpr', 'direction110', 'time',\n",
      "       'speed160', 'temperature80', 'reportMid-E395', 'reportDq-E1',\n",
      "       'reportCdq-16'],\n",
      "      dtype='object')\n",
      "Collection 'j00629_copy_agcavc already exist, deleted successfully!\n",
      "data inserted successfully!\n",
      "Program execution ends!\n"
     ]
    }
   ],
   "source": [
    "%run processing_limit_power_by_agcavc.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3537b980-9596-4204-967c-28122d03cb0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "程序开始时间: 2024-09-26 08:52:23\n",
      "程序结束时间: 2024-09-26 08:52:28\n",
      "程序运行时间: 5.01秒\n"
     ]
    }
   ],
   "source": [
    "import time  \n",
    "  \n",
    "# 获取程序开始时间  \n",
    "start_time = time.time()  \n",
    "  \n",
    "# 这里是你的程序主体  \n",
    "# 例如，我们可以简单地让程序等待一段时间来模拟一些工作  \n",
    "time.sleep(5)  # 让程序暂停5秒  \n",
    "  \n",
    "# 获取程序结束时间  \n",
    "end_time = time.time()  \n",
    "  \n",
    "# 计算程序运行时间  \n",
    "elapsed_time = end_time - start_time  \n",
    "  \n",
    "# 打印程序开始时间、结束时间和运行时间  \n",
    "print(f\"程序开始时间: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))}\")  \n",
    "print(f\"程序结束时间: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))}\")  \n",
    "print(f\"程序运行时间: {elapsed_time:.2f}秒\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "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', mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP', mongodb_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",
    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
    "    \"--mongodb_database\", \"algorithm_platform\",\n",
    "    \"--mongodb_read_table\", \"J00260NWP\",\n",
    "    \"--mongodb_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\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3e295203-bc38-464e-923c-29149e558c1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2024-05-01'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_data = {\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",
    "    \"mongodb_connection\":\"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
    "    \"mongodb_database\":\"algorithm_platform\",\n",
    "    \"mongodb_read_table\":\"J00260NWP\",\n",
    "    \"mongodb_write_table\":\"J00260NWP_agcavc\"\n",
    "}\n",
    "json_data['timeBegin']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cc57105c-df3c-4884-876e-8547bff4c98a",
   "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>_id</th>\n",
       "      <th>temperature10</th>\n",
       "      <th>temperature190</th>\n",
       "      <th>direction160</th>\n",
       "      <th>direction40</th>\n",
       "      <th>temperature110</th>\n",
       "      <th>direction80</th>\n",
       "      <th>speed60</th>\n",
       "      <th>globalr-1</th>\n",
       "      <th>mcc</th>\n",
       "      <th>...</th>\n",
       "      <th>radiation</th>\n",
       "      <th>surfacePressure</th>\n",
       "      <th>tpr</th>\n",
       "      <th>direction110</th>\n",
       "      <th>time</th>\n",
       "      <th>speed160</th>\n",
       "      <th>temperature80</th>\n",
       "      <th>reportMid-E395</th>\n",
       "      <th>reportDq-E1</th>\n",
       "      <th>reportCdq-16</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>673db4f849572921ef42cba8</td>\n",
       "      <td>27.7109</td>\n",
       "      <td>27.2327</td>\n",
       "      <td>83.8900</td>\n",
       "      <td>83.1655</td>\n",
       "      <td>27.2327</td>\n",
       "      <td>83.4782</td>\n",
       "      <td>7.1173</td>\n",
       "      <td>424.13</td>\n",
       "      <td>21.9464</td>\n",
       "      <td>...</td>\n",
       "      <td>817.38</td>\n",
       "      <td>1011.2582</td>\n",
       "      <td>3.6418</td>\n",
       "      <td>83.8900</td>\n",
       "      <td>1.715230e+12</td>\n",
       "      <td>7.6555</td>\n",
       "      <td>27.2327</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>673db4f849572921ef42cba9</td>\n",
       "      <td>24.8673</td>\n",
       "      <td>24.5118</td>\n",
       "      <td>159.0355</td>\n",
       "      <td>156.4900</td>\n",
       "      <td>24.5118</td>\n",
       "      <td>157.9882</td>\n",
       "      <td>7.2227</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.4409</td>\n",
       "      <td>...</td>\n",
       "      <td>343.47</td>\n",
       "      <td>1011.1018</td>\n",
       "      <td>0.0227</td>\n",
       "      <td>159.0355</td>\n",
       "      <td>1.710492e+12</td>\n",
       "      <td>8.0836</td>\n",
       "      <td>24.5118</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>673db4f849572921ef42cbaa</td>\n",
       "      <td>27.8864</td>\n",
       "      <td>27.5400</td>\n",
       "      <td>193.5809</td>\n",
       "      <td>191.0036</td>\n",
       "      <td>27.5400</td>\n",
       "      <td>192.5145</td>\n",
       "      <td>5.6836</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.3218</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1004.3500</td>\n",
       "      <td>0.3109</td>\n",
       "      <td>193.5809</td>\n",
       "      <td>1.720649e+12</td>\n",
       "      <td>6.4600</td>\n",
       "      <td>27.5400</td>\n",
       "      <td>-0.99</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>673db4f849572921ef42cbab</td>\n",
       "      <td>26.2082</td>\n",
       "      <td>25.8855</td>\n",
       "      <td>172.3518</td>\n",
       "      <td>170.0482</td>\n",
       "      <td>25.8855</td>\n",
       "      <td>171.3245</td>\n",
       "      <td>9.5318</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.6045</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1006.1800</td>\n",
       "      <td>0.0100</td>\n",
       "      <td>172.3518</td>\n",
       "      <td>1.712316e+12</td>\n",
       "      <td>10.7827</td>\n",
       "      <td>25.8855</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>673db4f849572921ef42cbac</td>\n",
       "      <td>29.5800</td>\n",
       "      <td>28.7800</td>\n",
       "      <td>53.7400</td>\n",
       "      <td>54.8200</td>\n",
       "      <td>29.1400</td>\n",
       "      <td>54.3100</td>\n",
       "      <td>2.7700</td>\n",
       "      <td>477.2</td>\n",
       "      <td>2.1000</td>\n",
       "      <td>...</td>\n",
       "      <td>408.00</td>\n",
       "      <td>1003.1300</td>\n",
       "      <td>4.6700</td>\n",
       "      <td>54.3700</td>\n",
       "      <td>1.725352e+12</td>\n",
       "      <td>3.0900</td>\n",
       "      <td>29.2100</td>\n",
       "      <td>-0.99</td>\n",
       "      <td>29.67</td>\n",
       "      <td>50.64</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 91 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        _id  temperature10  temperature190  direction160  \\\n",
       "0  673db4f849572921ef42cba8        27.7109         27.2327       83.8900   \n",
       "1  673db4f849572921ef42cba9        24.8673         24.5118      159.0355   \n",
       "2  673db4f849572921ef42cbaa        27.8864         27.5400      193.5809   \n",
       "3  673db4f849572921ef42cbab        26.2082         25.8855      172.3518   \n",
       "4  673db4f849572921ef42cbac        29.5800         28.7800       53.7400   \n",
       "\n",
       "   direction40  temperature110  direction80  speed60 globalr-1      mcc  ...  \\\n",
       "0      83.1655         27.2327      83.4782   7.1173    424.13  21.9464  ...   \n",
       "1     156.4900         24.5118     157.9882   7.2227       NaN   5.4409  ...   \n",
       "2     191.0036         27.5400     192.5145   5.6836       0.0   3.3218  ...   \n",
       "3     170.0482         25.8855     171.3245   9.5318       NaN   0.6045  ...   \n",
       "4      54.8200         29.1400      54.3100   2.7700     477.2   2.1000  ...   \n",
       "\n",
       "  radiation  surfacePressure     tpr  direction110          time  speed160  \\\n",
       "0    817.38        1011.2582  3.6418       83.8900  1.715230e+12    7.6555   \n",
       "1    343.47        1011.1018  0.0227      159.0355  1.710492e+12    8.0836   \n",
       "2      0.00        1004.3500  0.3109      193.5809  1.720649e+12    6.4600   \n",
       "3      0.00        1006.1800  0.0100      172.3518  1.712316e+12   10.7827   \n",
       "4    408.00        1003.1300  4.6700       54.3700  1.725352e+12    3.0900   \n",
       "\n",
       "   temperature80  reportMid-E395  reportDq-E1  reportCdq-16  \n",
       "0        27.2327             NaN          NaN           NaN  \n",
       "1        24.5118             NaN          NaN           NaN  \n",
       "2        27.5400           -0.99          0.0           NaN  \n",
       "3        25.8855             NaN          NaN           NaN  \n",
       "4        29.2100           -0.99        29.67         50.64  \n",
       "\n",
       "[5 rows x 91 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pymongo\n",
    "import pandas as pd\n",
    "\n",
    "# 连接 MongoDB\n",
    "client = pymongo.MongoClient(\"mongodb://root:sdhjfREWFWEF23e@192.168.1.43:30000/\")  # 替换为你的连接信息\n",
    "db = client['db2']  # 替换为你的数据库名\n",
    "collection = db['j00629_copy']  # 替换为你的集合名\n",
    "\n",
    "# 查询数据\n",
    "query = {}  # 空字典表示查询所有数据\n",
    "cursor = collection.find(query)\n",
    "\n",
    "# 将数据转换为 DataFrame\n",
    "df = pd.DataFrame(list(cursor))\n",
    "\n",
    "# 如果有 `_id` 字段，可能需要处理为字符串或删除\n",
    "if '_id' in df.columns:\n",
    "    df['_id'] = df['_id'].astype(str)  # 将 ObjectId 转为字符串\n",
    "    # df.drop('_id', axis=1, inplace=True)  # 或者删除 `_id` 字段\n",
    "client.close()\n",
    "df.head()# 查看数据\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7865455a-cbd4-4e55-bf63-b32b3a75a808",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['_id', 'temperature10', 'temperature190', 'direction160', 'direction40',\n",
       "       'temperature110', 'direction80', 'speed60', 'globalr-1', 'mcc', 'dq',\n",
       "       'temperature150', 'speed20', 'speed110', 'direction120', 'speed190',\n",
       "       'solarZenith', 'temperature90', 'direction200', 'speed150',\n",
       "       'temperature50', 'direction30', 'temperature160', 'direction170',\n",
       "       'temperature20', 'direction70', 'direction130', 'temperature200',\n",
       "       'speed70', 'temperature120', 'speed30', 'speed100', 'speed80',\n",
       "       'speed180', 'dniCalcd', 'speed140', 'temperature60', 'dateTime',\n",
       "       'temperature30', 'temperature170', 'direction20', 'humidity2',\n",
       "       'reportCdq-0', 'direction180', 'realPowerAvg', 'direction60',\n",
       "       'direction140', 'speed40', 'hcc', 'clearskyGhi', 'temperature130',\n",
       "       'lcc', 'updater', 'speed90', 'temperature2', 'tcc', 'direction100',\n",
       "       'speed170', 'temperature70', 'speed130', 'direction190', 'openCapacity',\n",
       "       'temperature40', 'creator', 'direction10', 'temperature180',\n",
       "       'direction150', 'direction50', 'speed50', 'updateTime', 'direction90',\n",
       "       'farmId', 'temperature100', 'speed10', 'temperature140', 'speed120',\n",
       "       'reportDq-avg', 'deleted', 'speed200', 'realPower', 'createTime',\n",
       "       'radiation', 'surfacePressure', 'tpr', 'direction110', 'time',\n",
       "       'speed160', 'temperature80', 'reportMid-E395', 'reportDq-E1',\n",
       "       'reportCdq-16'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  }
 ],
 "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
}
