anweiguo 9 mesi fa
commit
2ec873a00b
54 ha cambiato i file con 7224 aggiunte e 0 eliminazioni
  1. 0 0
      README.md
  2. BIN
      __pycache__/algo_test.cpython-39.pyc
  3. 16 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/Dockerfile-checkpoint
  4. 108 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/processing_limit_power_by_agcavc-checkpoint.py
  5. 6 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/requirements-checkpoint.txt
  6. 206 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/test-checkpoint.ipynb
  7. 16 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/Dockerfile
  8. 108 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/processing_limit_power_by_agcavc.py
  9. 6 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/requirements.txt
  10. 298 0
      data_processing/processing_limit_power/processing_limit_power_by_agcavc/test.ipynb
  11. 16 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/Dockerfile-checkpoint
  12. 96 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/processing_limit_power_by_machines-checkpoint.py
  13. 6 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/requirements-checkpoint.txt
  14. 216 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/test-checkpoint.ipynb
  15. 16 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/Dockerfile
  16. 96 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/processing_limit_power_by_machines.py
  17. 6 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/requirements.txt
  18. 290 0
      data_processing/processing_limit_power/processing_limit_power_by_machines/test.ipynb
  19. 16 0
      data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/Dockerfile-checkpoint
  20. 94 0
      data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/processing_limit_power_by_records-checkpoint.py
  21. 5 0
      data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/requirements-checkpoint.txt
  22. 295 0
      data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/test-checkpoint.ipynb
  23. 16 0
      data_processing/processing_limit_power/processing_limit_power_by_records/Dockerfile
  24. 94 0
      data_processing/processing_limit_power/processing_limit_power_by_records/processing_limit_power_by_records.py
  25. 5 0
      data_processing/processing_limit_power/processing_limit_power_by_records/requirements.txt
  26. 340 0
      data_processing/processing_limit_power/processing_limit_power_by_records/test.ipynb
  27. 47 0
      docker_bulid/J00260/.ipynb_checkpoints/docker-compose-checkpoint.yml
  28. 12 0
      docker_bulid/J00260/.ipynb_checkpoints/public-checkpoint.env
  29. 47 0
      docker_bulid/J00260/docker-compose.yml
  30. 12 0
      docker_bulid/J00260/public.env
  31. 16 0
      evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/Dockerfile-checkpoint
  32. 192 0
      evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/evaluation_accuracy-checkpoint.py
  33. 6 0
      evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/requirements-checkpoint.txt
  34. 1506 0
      evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/test-checkpoint.ipynb
  35. 16 0
      evaluation_processing/evaluation_accuracy/Dockerfile
  36. 192 0
      evaluation_processing/evaluation_accuracy/evaluation_accuracy.py
  37. 6 0
      evaluation_processing/evaluation_accuracy/requirements.txt
  38. 811 0
      evaluation_processing/evaluation_accuracy/test.ipynb
  39. 16 0
      models_processing/model_prediction_lightgbm/.ipynb_checkpoints/Dockerfile-checkpoint
  40. 96 0
      models_processing/model_prediction_lightgbm/.ipynb_checkpoints/model_prediction_lightgbm-checkpoint.py
  41. 7 0
      models_processing/model_prediction_lightgbm/.ipynb_checkpoints/requirements-checkpoint.txt
  42. 490 0
      models_processing/model_prediction_lightgbm/.ipynb_checkpoints/test-checkpoint.ipynb
  43. 16 0
      models_processing/model_prediction_lightgbm/Dockerfile
  44. 96 0
      models_processing/model_prediction_lightgbm/model_prediction_lightgbm.py
  45. 7 0
      models_processing/model_prediction_lightgbm/requirements.txt
  46. 522 0
      models_processing/model_prediction_lightgbm/test.ipynb
  47. 16 0
      models_processing/model_training_lighgbm/.ipynb_checkpoints/Dockerfile-checkpoint
  48. 118 0
      models_processing/model_training_lighgbm/.ipynb_checkpoints/model_training_lightgbm-checkpoint.py
  49. 7 0
      models_processing/model_training_lighgbm/.ipynb_checkpoints/requirements-checkpoint.txt
  50. 179 0
      models_processing/model_training_lighgbm/.ipynb_checkpoints/test-checkpoint.ipynb
  51. 16 0
      models_processing/model_training_lighgbm/Dockerfile
  52. 118 0
      models_processing/model_training_lighgbm/model_training_lightgbm.py
  53. 7 0
      models_processing/model_training_lighgbm/requirements.txt
  54. 279 0
      models_processing/model_training_lighgbm/test.ipynb

+ 0 - 0
README.md


BIN
__pycache__/algo_test.cpython-39.pyc


+ 16 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/Dockerfile-checkpoint

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "processing_limit_power_by_agcavc.py"]
+# 执行 Python 脚本
+CMD []

+ 108 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/processing_limit_power_by_agcavc-checkpoint.py

@@ -0,0 +1,108 @@
+import argparse
+import pandas as pd 
+from pymongo import MongoClient
+from sqlalchemy import create_engine
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+app = Flask('processing_limit_power_by_agcavc——service')
+@app.route('/hello', methods=['GET'])
+def hello():
+    return jsonify(message='Hello, World!')
+
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+
+#1.AGC/AVC信号判断限电(有的场站准 有的不准) 1种方法  数据库数据有问题 暂时用不了
+def  agc_avc_judgement(power_df,args):
+    timeBegin,timeEnd,col_time,user,password,host,port,database,avc_table = args['timeBegin'], args['timeEnd'],args['col_time'],args['user'],args['password'],args['host'],args['port'],args['database'],args['agc_avc_table']
+    #限电记录
+    clean_record = []
+    # 创建连接  
+    # cnx = mysql.connector.connect(user=user,password=password,host=host,port=port,database=database)  
+    # # 创建一个游标对象  
+    # cursor = cnx.cursor()
+    str_sql = f"mysql+pymysql://{user}:{password}@{host}:{port}/{database}"
+  
+    engine = create_engine(str_sql)
+    # 定义SQL查询  
+    df = pd.read_sql_query(f"select C_TIME, 1 as agc_avc_limit from {avc_table} where C_TIME>='{timeBegin} 00:00:00' and C_TIME<='{timeEnd} 23:59:59' and  (C_IS_RATIONING_BY_AUTO_CONTROL is True or C_IS_RATIONING_BY_MANUAL_CONTROL=1)", engine)
+    df['C_TIME'] = pd.to_datetime(df['C_TIME']).dt.strftime('%Y-%m-%d %H:%M:%S')
+    if df.shape[0]>0:
+        print(f"根据限电记录清洗,{timeBegin}至{timeEnd},限电时长共计{round(df.shape[0]/60,2)}小时")
+        clean_record = df[col_time].tolist()
+    # 关闭游标和连接  
+    # cursor.close()  
+    # cnx.close()
+    print(power_df.columns)
+    power_df = pd.merge(power_df,df,on=col_time,how='left')
+    return power_df[power_df['agc_avc_limit']!=1].drop('agc_avc_limit',axis=1)
+
+
+@app.route('/processing_limit_power_by_agcavc', methods=['POST','GET'])
+def processing_limit_power_by_agcavc():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        res_df = agc_avc_judgement(power_df,args)
+        insert_data_into_mongo(res_df,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+
+
+
+    
+if __name__=="__main__":
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("new_leads_classification")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10086)
+    print("server start!")
+    
+   
+    

+ 6 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/requirements-checkpoint.txt

@@ -0,0 +1,6 @@
+pymongo==4.9.1
+pandas==2.1.4
+SQLAlchemy==2.0.30
+PyMySQL==1.1.1
+Flask==3.0.3
+waitress==3.0.0

+ 206 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/.ipynb_checkpoints/test-checkpoint.ipynb

@@ -0,0 +1,206 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "752c3ab3-cdef-47b0-9d9a-805348d30d6e",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "%run processing_limit_power_by_agcavc.py"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "3537b980-9596-4204-967c-28122d03cb0d",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "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']"
+   ]
+  }
+ ],
+ "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
+}

+ 16 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/Dockerfile

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "processing_limit_power_by_agcavc.py"]
+# 执行 Python 脚本
+CMD []

+ 108 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/processing_limit_power_by_agcavc.py

@@ -0,0 +1,108 @@
+import argparse
+import pandas as pd 
+from pymongo import MongoClient
+from sqlalchemy import create_engine
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+app = Flask('processing_limit_power_by_agcavc——service')
+@app.route('/hello', methods=['GET'])
+def hello():
+    return jsonify(message='Hello, World!')
+
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+
+#1.AGC/AVC信号判断限电(有的场站准 有的不准) 1种方法  数据库数据有问题 暂时用不了
+def  agc_avc_judgement(power_df,args):
+    timeBegin,timeEnd,col_time,user,password,host,port,database,avc_table = args['timeBegin'], args['timeEnd'],args['col_time'],args['user'],args['password'],args['host'],args['port'],args['database'],args['agc_avc_table']
+    #限电记录
+    clean_record = []
+    # 创建连接  
+    # cnx = mysql.connector.connect(user=user,password=password,host=host,port=port,database=database)  
+    # # 创建一个游标对象  
+    # cursor = cnx.cursor()
+    str_sql = f"mysql+pymysql://{user}:{password}@{host}:{port}/{database}"
+  
+    engine = create_engine(str_sql)
+    # 定义SQL查询  
+    df = pd.read_sql_query(f"select C_TIME, 1 as agc_avc_limit from {avc_table} where C_TIME>='{timeBegin} 00:00:00' and C_TIME<='{timeEnd} 23:59:59' and  (C_IS_RATIONING_BY_AUTO_CONTROL is True or C_IS_RATIONING_BY_MANUAL_CONTROL=1)", engine)
+    df['C_TIME'] = pd.to_datetime(df['C_TIME']).dt.strftime('%Y-%m-%d %H:%M:%S')
+    if df.shape[0]>0:
+        print(f"根据限电记录清洗,{timeBegin}至{timeEnd},限电时长共计{round(df.shape[0]/60,2)}小时")
+        clean_record = df[col_time].tolist()
+    # 关闭游标和连接  
+    # cursor.close()  
+    # cnx.close()
+    print(power_df.columns)
+    power_df = pd.merge(power_df,df,on=col_time,how='left')
+    return power_df[power_df['agc_avc_limit']!=1].drop('agc_avc_limit',axis=1)
+
+
+@app.route('/processing_limit_power_by_agcavc', methods=['POST','GET'])
+def processing_limit_power_by_agcavc():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        res_df = agc_avc_judgement(power_df,args)
+        insert_data_into_mongo(res_df,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+
+
+
+    
+if __name__=="__main__":
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("new_leads_classification")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10086)
+    print("server start!")
+    
+   
+    

+ 6 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/requirements.txt

@@ -0,0 +1,6 @@
+pymongo==4.9.1
+pandas==2.1.4
+SQLAlchemy==2.0.30
+PyMySQL==1.1.1
+Flask==3.0.3
+waitress==3.0.0

+ 298 - 0
data_processing/processing_limit_power/processing_limit_power_by_agcavc/test.ipynb

@@ -0,0 +1,298 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "752c3ab3-cdef-47b0-9d9a-805348d30d6e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 11:00:17,560 - 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-09-26 11:00:24,004 - new_leads_classification - INFO - {'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"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'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"
+     ]
+    }
+   ],
+   "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": 20,
+   "id": "cc57105c-df3c-4884-876e-8547bff4c98a",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "71"
+      ]
+     },
+     "execution_count": 20,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "16+15+17+23"
+   ]
+  }
+ ],
+ "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
+}

+ 16 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/Dockerfile-checkpoint

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "processing_limit_power_by_machines.py"]
+# 执行 Python 脚本
+CMD []

+ 96 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/processing_limit_power_by_machines-checkpoint.py

@@ -0,0 +1,96 @@
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import matplotlib.pyplot as plt
+
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+
+app = Flask('processing_limit_power_by_machines——service')
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+#样板机法
+def windLight_machine_judgment(power,args):
+    col_rp,col_tp = args['col_rp'],args['col_tp']
+    power['diff'] = power[col_tp]-power[col_rp]
+    power['is_limit_machine'] = False
+    diff_mean,diff_std = power['diff'].mean(),power['diff'].std()
+    threshold = diff_mean-1.96*(diff_std/np.sqrt(power.shape[0]))
+    print("threshold",threshold)
+    power.loc[abs(power['diff']) > threshold ,'is_limit_machine'] = True
+    is_limit = power['is_limit_machine']
+    # 可视化结果
+    plt.figure(figsize=(300, 6))
+    plt.plot(power[col_rp], label=col_rp)
+    plt.plot(power[col_tp], label=col_tp)
+    plt.scatter(power.index[is_limit], power[col_rp][is_limit], color='red', label='限电点')
+    plt.legend()
+    plt.title(f' 95%置信水平计算置信区间 ---限电 threshold={threshold}')
+    plt.show()
+    return power[power['is_limit_machine']!=True].drop(['diff','is_limit_machine'],axis=1)
+
+
+@app.route('/processing_limit_power_by_machines', methods=['POST'])
+def processing_limit_power_by_machines():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        power_df = get_data_from_mongo(args)
+        res_df = windLight_machine_judgment(power_df,args)
+        insert_data_into_mongo(res_df,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+    
+
+if __name__=="__main__":
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("processing_limit_power_by_machines log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10087)
+    print("server start!")

+ 6 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/requirements-checkpoint.txt

@@ -0,0 +1,6 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+matplotlib==3.7.5
+Flask==3.0.3
+waitress==3.0.0

+ 216 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/.ipynb_checkpoints/test-checkpoint.ipynb

@@ -0,0 +1,216 @@
+{
+ "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
+}

+ 16 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/Dockerfile

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "processing_limit_power_by_machines.py"]
+# 执行 Python 脚本
+CMD []

+ 96 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/processing_limit_power_by_machines.py

@@ -0,0 +1,96 @@
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import matplotlib.pyplot as plt
+
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+
+app = Flask('processing_limit_power_by_machines——service')
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+#样板机法
+def windLight_machine_judgment(power,args):
+    col_rp,col_tp = args['col_rp'],args['col_tp']
+    power['diff'] = power[col_tp]-power[col_rp]
+    power['is_limit_machine'] = False
+    diff_mean,diff_std = power['diff'].mean(),power['diff'].std()
+    threshold = diff_mean-1.96*(diff_std/np.sqrt(power.shape[0]))
+    print("threshold",threshold)
+    power.loc[abs(power['diff']) > threshold ,'is_limit_machine'] = True
+    is_limit = power['is_limit_machine']
+    # 可视化结果
+    plt.figure(figsize=(300, 6))
+    plt.plot(power[col_rp], label=col_rp)
+    plt.plot(power[col_tp], label=col_tp)
+    plt.scatter(power.index[is_limit], power[col_rp][is_limit], color='red', label='限电点')
+    plt.legend()
+    plt.title(f' 95%置信水平计算置信区间 ---限电 threshold={threshold}')
+    plt.show()
+    return power[power['is_limit_machine']!=True].drop(['diff','is_limit_machine'],axis=1)
+
+
+@app.route('/processing_limit_power_by_machines', methods=['POST'])
+def processing_limit_power_by_machines():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        power_df = get_data_from_mongo(args)
+        res_df = windLight_machine_judgment(power_df,args)
+        insert_data_into_mongo(res_df,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+    
+
+if __name__=="__main__":
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("processing_limit_power_by_machines log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10087)
+    print("server start!")

+ 6 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/requirements.txt

@@ -0,0 +1,6 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+matplotlib==3.7.5
+Flask==3.0.3
+waitress==3.0.0

File diff suppressed because it is too large
+ 290 - 0
data_processing/processing_limit_power/processing_limit_power_by_machines/test.ipynb


+ 16 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/Dockerfile-checkpoint

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "processing_limit_power_by_records.py"]
+# 执行 Python 脚本
+CMD []

+ 94 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/processing_limit_power_by_records-checkpoint.py

@@ -0,0 +1,94 @@
+import argparse
+import pandas as pd 
+from pymongo import MongoClient
+import requests
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+app = Flask('processing_limit_power_by_records——service')
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+
+def limit_record_judgement(power,args):
+    timeBegin,timeEnd,station_code,col_time = args['timeBegin'], args['timeEnd'], args['station_code'], args['col_time']
+    url = f'http://itil.jiayuepowertech.com:9958/itil/api/power-limitation?timeBegin={timeBegin}&timeEnd={timeEnd}'
+    try:
+        res = requests.get(url).json()
+    except requests.RequestException as e:
+        print(f"请求失败: {e}")
+        return []
+    ele_info = [item for item in res.get('data', []) if item['stationCode'] == station_code]
+    initial_count = len(power)
+    clean_record = []
+    for ele in ele_info:
+        begin,end = ele['timeBegin'], ele['timeEnd']
+        ele_limits = pd.date_range(start=begin, end=end, freq='min').strftime("%Y-%m-%d %H:%M:%S").tolist()
+        if len(ele_limits) > 0:
+            clean_record = clean_record + ele_limits
+    print(f"根据限电记录清洗,{timeBegin}至{timeEnd},限电时长共计{round(len(clean_record)/60,2)}小时")
+    return power[~power[col_time].isin(clean_record)]
+
+@app.route('/processing_limit_power_by_records', methods=['POST'])
+def processing_limit_power_by_records():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        res_df = limit_record_judgement(power_df,args)
+        insert_data_into_mongo(res_df,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+    
+if __name__=="__main__":
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("processing_limit_power_by_records log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10088)
+    print("server start!")

+ 5 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/requirements-checkpoint.txt

@@ -0,0 +1,5 @@
+pymongo==4.9.1
+pandas==2.1.4
+requests==2.32.3
+Flask==3.0.3
+waitress==3.0.0

+ 295 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/.ipynb_checkpoints/test-checkpoint.ipynb

@@ -0,0 +1,295 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "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', station_code='J00260', col_time='C_TIME', mongondb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongondb_database='algorithm_platform', mongondb_read_table='J00260NWP_machines', mongondb_write_table='J00260NWP_records')\n",
+      "根据限电记录清洗,2024-05-01至2024-09-20,限电时长共计0.0小时\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_records.py\",\n",
+    "    \"--timeBegin\", \"2024-05-01\",\n",
+    "    \"--timeEnd\", \"2024-09-20\",\n",
+    "    \"--station_code\", \"J00260\",\n",
+    "    \"--col_time\", \"C_TIME\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_machines\",\n",
+    "    \"--mongodb_write_table\", \"J00260NWP_records\"\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": null,
+   "id": "49a380e4-db57-4596-ae39-55ed62d92f64",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    " "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "id": "ba8d36c7-cae7-427b-9980-ad8dadc442b2",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-低云量</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>66ecc86f1075358d129a1d56</td>\n",
+       "      <td>2024-05-02 22:30:00</td>\n",
+       "      <td>130.05</td>\n",
+       "      <td>9.63</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.52</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6477</td>\n",
+       "      <td>202.7945</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0173</td>\n",
+       "      <td>20.2918</td>\n",
+       "      <td>20.3927</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>14.0818</td>\n",
+       "      <td>23.4918</td>\n",
+       "      <td>892.3327</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>1</th>\n",
+       "      <td>66ecc86f1075358d129a1d57</td>\n",
+       "      <td>2024-05-02 22:45:00</td>\n",
+       "      <td>130.51</td>\n",
+       "      <td>9.72</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.24</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.9228</td>\n",
+       "      <td>202.6482</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0191</td>\n",
+       "      <td>20.3009</td>\n",
+       "      <td>20.3864</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>13.8264</td>\n",
+       "      <td>24.0436</td>\n",
+       "      <td>892.3809</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>2 rows × 34 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                        _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  130.05       9.63  104.76   \n",
+       "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  130.51       9.72  104.76   \n",
+       "\n",
+       "   实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-低云量  NWP-中云量  \\\n",
+       "0   -0.99  92.52       0.0       3.6477     202.7945  ...      0.0   0.0173   \n",
+       "1   -0.99  93.24       0.0       3.9228     202.6482  ...      0.0   0.0191   \n",
+       "\n",
+       "   NWP-高云量  NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度  \\\n",
+       "0  20.2918  20.3927        0.0        0.0        0.0  14.0818  23.4918   \n",
+       "1  20.3009  20.3864        0.0        0.0        0.0  13.8264  24.0436   \n",
+       "\n",
+       "     NWP-气压  \n",
+       "0  892.3327  \n",
+       "1  892.3809  \n",
+       "\n",
+       "[2 rows x 34 columns]"
+      ]
+     },
+     "execution_count": 3,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "from pymongo import MongoClient\n",
+    "import pandas as pd\n",
+    "client = MongoClient(\"mongodb://root:Jydl3377@192.168.1.33:27017\")\n",
+    "# 选择数据库(如果数据库不存在,MongoDB 会自动创建)\n",
+    "db = client[\"algorithm_platform\"]\n",
+    "collection = db['J00260NWP_records']\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df_from_db = pd.DataFrame(list(data_from_db))\n",
+    "client.close()\n",
+    "# 打印读取到的数据\n",
+    "df_from_db.head(2)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "0bb0ca05-9437-4001-b4a3-0f2462688eee",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(9713, 34)"
+      ]
+     },
+     "execution_count": 4,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df_from_db.shape"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "03343b25-0d46-4353-8ae5-4a2278513473",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run processing_limit_power_by_records   --timeBegin \"2024-05-01\"     --timeEnd \"2024-09-20\"   --station_code \"J00260\"     --col_time \"C_TIME\"    --mongondb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP_machines\"     --mongondb_write_table \"J00260NWP_records\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "id": "ab08e3db-a4dc-464c-a461-2797544b453f",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import optuna.integration.lightgbm as lgb_tuner  # 修正导入语句\n",
+    "# from optuna.integration import LightGBMTunerCV  # 正确的导入方式\n",
+    "from sklearn.datasets import load_diabetes  # 使用糖尿病数据集\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "823ec3b1-00db-4bcd-b7ca-c0ba60196d7e",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "f1607a99-475e-47a7-9f3d-3be98efa413c",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "41f23573-05d7-4686-843b-0b3c3f7678e0",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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
+}

+ 16 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/Dockerfile

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "processing_limit_power_by_records.py"]
+# 执行 Python 脚本
+CMD []

+ 94 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/processing_limit_power_by_records.py

@@ -0,0 +1,94 @@
+import argparse
+import pandas as pd 
+from pymongo import MongoClient
+import requests
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+app = Flask('processing_limit_power_by_records——service')
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+
+def limit_record_judgement(power,args):
+    timeBegin,timeEnd,station_code,col_time = args['timeBegin'], args['timeEnd'], args['station_code'], args['col_time']
+    url = f'http://itil.jiayuepowertech.com:9958/itil/api/power-limitation?timeBegin={timeBegin}&timeEnd={timeEnd}'
+    try:
+        res = requests.get(url).json()
+    except requests.RequestException as e:
+        print(f"请求失败: {e}")
+        return []
+    ele_info = [item for item in res.get('data', []) if item['stationCode'] == station_code]
+    initial_count = len(power)
+    clean_record = []
+    for ele in ele_info:
+        begin,end = ele['timeBegin'], ele['timeEnd']
+        ele_limits = pd.date_range(start=begin, end=end, freq='min').strftime("%Y-%m-%d %H:%M:%S").tolist()
+        if len(ele_limits) > 0:
+            clean_record = clean_record + ele_limits
+    print(f"根据限电记录清洗,{timeBegin}至{timeEnd},限电时长共计{round(len(clean_record)/60,2)}小时")
+    return power[~power[col_time].isin(clean_record)]
+
+@app.route('/processing_limit_power_by_records', methods=['POST'])
+def processing_limit_power_by_records():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        res_df = limit_record_judgement(power_df,args)
+        insert_data_into_mongo(res_df,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+    
+if __name__=="__main__":
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("processing_limit_power_by_records log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10088)
+    print("server start!")

+ 5 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/requirements.txt

@@ -0,0 +1,5 @@
+pymongo==4.9.1
+pandas==2.1.4
+requests==2.32.3
+Flask==3.0.3
+waitress==3.0.0

+ 340 - 0
data_processing/processing_limit_power/processing_limit_power_by_records/test.ipynb

@@ -0,0 +1,340 @@
+{
+ "cells": [
+  {
+   "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', station_code='J00260', col_time='C_TIME', mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_machines', mongodb_write_table='J00260NWP_records')\n",
+      "根据限电记录清洗,2024-05-01至2024-09-20,限电时长共计0.0小时\n",
+      "Collection 'J00260NWP_records 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_records.py\",\n",
+    "    \"--timeBegin\", \"2024-05-01\",\n",
+    "    \"--timeEnd\", \"2024-09-20\",\n",
+    "    \"--station_code\", \"J00260\",\n",
+    "    \"--col_time\", \"C_TIME\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_machines\",\n",
+    "    \"--mongodb_write_table\", \"J00260NWP_records\"\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": null,
+   "id": "d409818f-c17f-4a80-9d5e-0def3503ae81",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run processing_limit_power_by_records   --timeBegin \"2024-05-01\"     --timeEnd \"2024-09-20\"   --station_code \"J00260\"     --col_time \"C_TIME\"    --mongondb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP_machines\"     --mongondb_write_table \"J00260NWP_records\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "49a380e4-db57-4596-ae39-55ed62d92f64",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 11:45:04,387 - waitress - INFO - Serving on http://0.0.0.0:10088\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 11:45:09,115 - processing_limit_power_by_machines log - INFO - {'timeBegin': '2024-05-01', 'timeEnd': '2024-09-20', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_machines', 'mongodb_write_table': 'J00260NWP_records', 'station_code': 'J00260', 'col_time': 'C_TIME'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'timeBegin': '2024-05-01', 'timeEnd': '2024-09-20', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_machines', 'mongodb_write_table': 'J00260NWP_records', 'station_code': 'J00260', 'col_time': 'C_TIME'}\n",
+      "根据限电记录清洗,2024-05-01至2024-09-20,限电时长共计0.0小时\n",
+      "Collection 'J00260NWP_records already exist, deleted successfully!\n",
+      "data inserted successfully!\n",
+      "Program execution ends!\n"
+     ]
+    }
+   ],
+   "source": [
+    " %run processing_limit_power_by_records.py"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "id": "ba8d36c7-cae7-427b-9980-ad8dadc442b2",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-低云量</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>66ecc86f1075358d129a1d56</td>\n",
+       "      <td>2024-05-02 22:30:00</td>\n",
+       "      <td>130.05</td>\n",
+       "      <td>9.63</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.52</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6477</td>\n",
+       "      <td>202.7945</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0173</td>\n",
+       "      <td>20.2918</td>\n",
+       "      <td>20.3927</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>14.0818</td>\n",
+       "      <td>23.4918</td>\n",
+       "      <td>892.3327</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>1</th>\n",
+       "      <td>66ecc86f1075358d129a1d57</td>\n",
+       "      <td>2024-05-02 22:45:00</td>\n",
+       "      <td>130.51</td>\n",
+       "      <td>9.72</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.24</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.9228</td>\n",
+       "      <td>202.6482</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0191</td>\n",
+       "      <td>20.3009</td>\n",
+       "      <td>20.3864</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>13.8264</td>\n",
+       "      <td>24.0436</td>\n",
+       "      <td>892.3809</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>2 rows × 34 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                        _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  130.05       9.63  104.76   \n",
+       "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  130.51       9.72  104.76   \n",
+       "\n",
+       "   实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-低云量  NWP-中云量  \\\n",
+       "0   -0.99  92.52       0.0       3.6477     202.7945  ...      0.0   0.0173   \n",
+       "1   -0.99  93.24       0.0       3.9228     202.6482  ...      0.0   0.0191   \n",
+       "\n",
+       "   NWP-高云量  NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度  \\\n",
+       "0  20.2918  20.3927        0.0        0.0        0.0  14.0818  23.4918   \n",
+       "1  20.3009  20.3864        0.0        0.0        0.0  13.8264  24.0436   \n",
+       "\n",
+       "     NWP-气压  \n",
+       "0  892.3327  \n",
+       "1  892.3809  \n",
+       "\n",
+       "[2 rows x 34 columns]"
+      ]
+     },
+     "execution_count": 3,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "from pymongo import MongoClient\n",
+    "import pandas as pd\n",
+    "client = MongoClient(\"mongodb://root:Jydl3377@192.168.1.33:27017\")\n",
+    "# 选择数据库(如果数据库不存在,MongoDB 会自动创建)\n",
+    "db = client[\"algorithm_platform\"]\n",
+    "collection = db['J00260NWP_records']\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df_from_db = pd.DataFrame(list(data_from_db))\n",
+    "client.close()\n",
+    "# 打印读取到的数据\n",
+    "df_from_db.head(2)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "0bb0ca05-9437-4001-b4a3-0f2462688eee",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(9713, 34)"
+      ]
+     },
+     "execution_count": 4,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df_from_db.shape"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "03343b25-0d46-4353-8ae5-4a2278513473",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run processing_limit_power_by_records   --timeBegin \"2024-05-01\"     --timeEnd \"2024-09-20\"   --station_code \"J00260\"     --col_time \"C_TIME\"    --mongondb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP_machines\"     --mongondb_write_table \"J00260NWP_records\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "id": "ab08e3db-a4dc-464c-a461-2797544b453f",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import optuna.integration.lightgbm as lgb_tuner  # 修正导入语句\n",
+    "# from optuna.integration import LightGBMTunerCV  # 正确的导入方式\n",
+    "from sklearn.datasets import load_diabetes  # 使用糖尿病数据集\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "823ec3b1-00db-4bcd-b7ca-c0ba60196d7e",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "f1607a99-475e-47a7-9f3d-3be98efa413c",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "41f23573-05d7-4686-843b-0b3c3f7678e0",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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
+}

+ 47 - 0
docker_bulid/J00260/.ipynb_checkpoints/docker-compose-checkpoint.yml

@@ -0,0 +1,47 @@
+version: '3.8'
+services:
+  processing_limit_power_by_agcavc:
+    build:
+      context: ././data_processing/processing_limit_power/processing_limit_power_by_agcavc
+    command: >
+      --timeBegin=${timeBegin}
+      --timeEnd=${timeEnd}
+      --col_time=${col_time}
+      --user=${user}
+      --password=${password}
+      --host=${host}
+      --port=${port}
+      --database="ipfcst_j00260_20240911093804"
+      --agc_avc_table=${agc_avc_table}
+      --mongodb_connection=${mongodb_connection}
+      --mongodb_database=${mongodb_database}
+      --mongodb_read_table="J00260NWP"
+      --mongodb_write_table="J00260NWP_agcavc"
+
+  processing_limit_power_by_machines:
+    build:
+      context: ././data_processing/processing_limit_power/processing_limit_power_by_machines
+    command: >
+      --col_rp=${col_rp} 
+      --col_tp=${col_tp}
+      --mongodb_connection=${mongodb_connection}   
+      --mongodb_database=${mongodb_database}    
+      --mongodb_read_table="J00260NWP_agcavc"     
+      --mongodb_write_table="J00260NWP_machines"
+    depends_on:
+      - processing_limit_power_by_agcavc
+      
+  processing_limit_power_by_records:
+    build:
+      context: ././data_processing/processing_limit_power/processing_limit_power_by_records
+    command: >
+      --timeBegin=${timeBegin}    
+      --timeEnd=${timeEnd}  
+      --station_code="J00260"     
+      --col_time=${col_time}    
+      --mongodb_connection=${mongodb_connection}    
+      --mongodb_database=${mongodb_database} 
+      --mongodb_read_table="J00260NWP_machines"     
+      --mongodb_write_table="J00260NWP_records"
+    depends_on:
+      - processing_limit_power_by_machines

+ 12 - 0
docker_bulid/J00260/.ipynb_checkpoints/public-checkpoint.env

@@ -0,0 +1,12 @@
+user="root"
+password="mysql_T7yN3E"
+host="192.168.12.10"
+port="19306"
+agc_avc_table="t_power_station_status_data"
+mongodb_connection="mongodb://root:Jydl3377@192.168.1.33:27017"
+mongodb_database="algorithm_platform"
+timeBegin="2024-05-01"
+timeEnd="2024-09-20" 
+col_time="C_TIME"
+col_rp="实际功率" 
+col_tp="理论功率"

+ 47 - 0
docker_bulid/J00260/docker-compose.yml

@@ -0,0 +1,47 @@
+version: '3.8'
+services:
+  processing_limit_power_by_agcavc:
+    build:
+      context: ././data_processing/processing_limit_power/processing_limit_power_by_agcavc
+    command: >
+      --timeBegin=${timeBegin}
+      --timeEnd=${timeEnd}
+      --col_time=${col_time}
+      --user=${user}
+      --password=${password}
+      --host=${host}
+      --port=${port}
+      --database="ipfcst_j00260_20240911093804"
+      --agc_avc_table=${agc_avc_table}
+      --mongodb_connection=${mongodb_connection}
+      --mongodb_database=${mongodb_database}
+      --mongodb_read_table="J00260NWP"
+      --mongodb_write_table="J00260NWP_agcavc"
+
+  processing_limit_power_by_machines:
+    build:
+      context: ././data_processing/processing_limit_power/processing_limit_power_by_machines
+    command: >
+      --col_rp=${col_rp} 
+      --col_tp=${col_tp}
+      --mongodb_connection=${mongodb_connection}   
+      --mongodb_database=${mongodb_database}    
+      --mongodb_read_table="J00260NWP_agcavc"     
+      --mongodb_write_table="J00260NWP_machines"
+    depends_on:
+      - processing_limit_power_by_agcavc
+      
+  processing_limit_power_by_records:
+    build:
+      context: ././data_processing/processing_limit_power/processing_limit_power_by_records
+    command: >
+      --timeBegin=${timeBegin}    
+      --timeEnd=${timeEnd}  
+      --station_code="J00260"     
+      --col_time=${col_time}    
+      --mongodb_connection=${mongodb_connection}    
+      --mongodb_database=${mongodb_database} 
+      --mongodb_read_table="J00260NWP_machines"     
+      --mongodb_write_table="J00260NWP_records"
+    depends_on:
+      - processing_limit_power_by_machines

+ 12 - 0
docker_bulid/J00260/public.env

@@ -0,0 +1,12 @@
+user="root"
+password="mysql_T7yN3E"
+host="192.168.12.10"
+port="19306"
+agc_avc_table="t_power_station_status_data"
+mongodb_connection="mongodb://root:Jydl3377@192.168.1.33:27017"
+mongodb_database="algorithm_platform"
+timeBegin="2024-05-01"
+timeEnd="2024-09-20" 
+col_time="C_TIME"
+col_rp="实际功率" 
+col_tp="理论功率"

+ 16 - 0
evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/Dockerfile-checkpoint

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "evaluation_accuracy.py"]
+# 执行 Python 脚本
+CMD []

+ 192 - 0
evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/evaluation_accuracy-checkpoint.py

@@ -0,0 +1,192 @@
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import requests
+import json, time
+from datetime import datetime
+
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+app = Flask('evaluation_accuracy——service')
+url = 'http://49.4.78.194:17160/apiCalculate/calculate'
+'''
+准确率接口使用手顺:
+①入口方法为 calculate_acc
+② 按照参数传传值
+data含有C_TIME时间、realValue实际功率、ableValue可用功率(没有数值用实际功率替代)、forecastAbleValue预测功率
+opt为包含场站必要信息的字典,字段为:cap装机容量 province省份 formulaType公式类型 electricType电站类型 stationCode场站编码
+具体介绍参考接口文档
+③公式计算分为按天和按点两种,指定好opt.formulaType,即可设置公式类型,再在求取的每天或每个点的结果上进行平均,结果返回
+'''
+
+
+def wrap_json(df, opt):
+    """
+    包装json
+    :param df: 列名为 C_TIME realValue ableValue forecastAbleValue的DataFrame
+    :param opt: 参数字典
+    :return: json列表
+    """
+    d = opt['formulaType'].split('_')[0]
+    jata, dfs = [], []
+    if d == 'POINT':
+        df['time'] = df['C_TIME'].apply(datetime_to_timestamp)
+        for i, row in df.iterrows():
+            dfs.append(row.to_frame().T)
+    elif d == 'DAY':
+        df = df.copy()
+        # df['time'] = df['C_TIME'].apply(datetime_to_timestamp) int(round(time.mktime(df['C_TIME'].timetuple()))*1000)
+        # df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)
+        df['time'] = df['C_TIME'].apply(lambda x: datetime_to_timestamp(x))
+        # df['time'] = df.apply(lambda row: datetime_to_timestamp(row['C_TIME']), axis=1)
+
+        # df['C_TIME'] = df['C_TIME'].dt.strftime('%y%m%d')   # 转换成年月日
+        df.loc[:, 'C_TIME'] = df['C_TIME'].dt.strftime('%y%m%d')
+        for i, group in df.groupby('C_TIME'):
+            dfs.append(group)
+    outter_dict = {"electricCapacity": str(opt['cap']), "province": opt['province'], "formulaType": opt['formulaType'], "electricType":opt['electricType'], "stationCode": opt['stationCode']}
+    timestamp = int(time.mktime(datetime.now().timetuple()) * 1000 + datetime.now().microsecond / 1000.0)
+    inner_dict = {"genTime": str(timestamp)+"L", "capacity": str(opt['cap']), "openCapacity": str(opt['cap'])}
+    for df in dfs:
+        calculationInfoList = df.iloc[:, 1:].to_json(orient='records')
+        outter_dict['calculationInfoList'] = [dict(calculation, **inner_dict) for calculation in eval(calculationInfoList)]
+        jata.append(json.dumps(outter_dict))
+    return jata
+
+
+def send_reqest(url, jata):
+    """
+    发送请求
+    :param url: 请求地址
+    :param jata: Json数据
+    :return: 准确率
+    """
+    headers = {
+        'content-type': 'application/json;charset=UTF-8',
+        "Authorization": "dXNlcjoxMjM0NTY="
+    }
+    acc, number = 0, 0
+    for i in range(len(jata)):
+        res = requests.post(url, headers=headers, data=jata[i])
+        if res.json()['code'] == '500':
+            print("没通过考核标准", end=' ')
+            continue
+        number += 1
+        acc += float(res.json()['data'][:-1])
+    if number != 0:
+        acc /= number
+    else:
+        print("无法迭代计算准确率平均值,分母为0")
+    return acc
+
+
+def calculate_acc(data, opt):
+    """
+    准确率调用接口计算
+    :param data: 列名为 C_TIME realValue ableValue forecastAbleValue的DataFrame
+    :param opt: 参数字段
+    :return: 计算结果
+    """
+    jata = wrap_json(data, opt)
+    acc = send_reqest(url=url, jata=jata)
+    return acc
+
+
+def datetime_to_timestamp(dt):
+    return int(round(time.mktime(dt.timetuple()))*1000)
+
+
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+def compute_accuracy(df,args):
+    col_time,col_rp,col_pp,formulaType = args['col_time'],args['col_rp'],args['col_pp'],args['formulaType'].split('_')[0]
+    dates = []
+    accuracy = []
+    df = df[(~np.isnan(df[col_rp]))&(~np.isnan(df[col_pp]))]
+    df = df[[col_time,col_rp,col_pp]].rename(columns={col_time:'C_TIME',col_rp:'realValue',col_pp:'forecastAbleValue'})
+    df['ableValue'] = df['realValue']
+    df['C_TIME'] = df['C_TIME'].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S"))
+    if formulaType=='DAY':
+        df['C_DATE'] = df['C_TIME'].apply(lambda x: x.strftime("%Y-%m-%d"))
+        days_list = df['C_DATE'].unique().tolist()
+        for day in days_list:
+            df_tmp = df[df['C_DATE'] == day]
+            dates.append(day)
+            accuracy.append(calculate_acc(df_tmp, args))
+    else:
+        points = df['C_TIME'].unique().tolist()
+        for point in points:
+            df_tmp = df[df['C_TIME'] == point]
+            dates.append(point)
+            accuracy.append(calculate_acc(df_tmp, args))
+    print("accuray compute successfully!")
+    return pd.DataFrame({'date':dates,'accuracy':accuracy})
+
+
+@app.route('/evaluation_accuracy', methods=['POST'])
+def evaluation_accuracy():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        acc_result = compute_accuracy(power_df,args)
+        insert_data_into_mongo(acc_result,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+    
+
+if __name__=="__main__":  
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("evaluation_accuracy log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10091)
+    print("server start!")

+ 6 - 0
evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/requirements-checkpoint.txt

@@ -0,0 +1,6 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+requests==2.32.3
+Flask==3.0.3
+waitress==3.0.0

+ 1506 - 0
evaluation_processing/evaluation_accuracy/.ipynb_checkpoints/test-checkpoint.ipynb

@@ -0,0 +1,1506 @@
+{
+ "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": [
+    "'formulaType': 'DAY_SHORT_ACCURACY',\n",
+    "    'cap': '225',\n",
+    "    'province': 'E15',\n",
+    "    'electricType': 'E2',\n",
+    "    'stationCode': 'J00260'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 61,
+   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Output:\n",
+      "Program starts execution!\n",
+      "args: Namespace(formulaType='DAY_SHORT_ACCURACY', cap='225', province='E15', electricType='E2', stationCode='J00260', col_time='C_TIME', col_rp='实际功率', col_pp='predict', mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_records_predict', mongodb_write_table='J00260NWP_records_accuracy')\n",
+      "accuray compute successfully!\n",
+      "Collection 'J00260NWP_records_accuracy already exist, deleted successfully!\n",
+      "data inserted successfully!\n",
+      "Program execution ends!\n",
+      "\n",
+      "Error:\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "D:\\jupyterProject\\jyProject\\algorithm_platform\\ evaluation\\accuracy.py:39: SettingWithCopyWarning: \n",
+      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
+      "Try using .loc[row_indexer,col_indexer] = value instead\n",
+      "\n",
+      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
+      "  df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "import subprocess\n",
+    "\n",
+    "# 构建命令\n",
+    "command = [\n",
+    "    \"python\", \"accuracy.py\",\n",
+    "    \"--formulaType\", \"DAY_SHORT_ACCURACY\",\n",
+    "    \"--cap\",\"225\",\n",
+    "    \"--province\",\"E15\",\n",
+    "    \"--electricType\",\"E2\",\n",
+    "    \"--stationCode\",\"J00260\",\n",
+    "    \"--col_time\",\"C_TIME\",\n",
+    "    \"--col_rp\",\"实际功率\",\n",
+    "    \"--col_pp\",\"predict\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_records_predict\",\n",
+    "    \"--mongodb_write_table\", \"J00260NWP_records_accuracy\",\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)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "14a9feb4-5625-45d7-8e0f-6a8dea8c9f24",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run model_prediction_lightgbm  --mongodb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongodb_database \"algorithm_platform\"   --mongodb_read_table \"J00260NWP_records\"     --mongodb_model_table \"models\"    --model_name \"lightgbm_model\"     --mongodb_database \"algorithm_platform\"     --mongodb_write_table \"J00260NWP_records_predict\"      "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run lightgbm_model.py --numerical_features ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'])  --categorical_features  ','.join([])  --label  \"实际功率\" --learning_rate  \"0.01\" --num_leaves \"31\"  --min_data_in_leaf  \"21\"  --mongodb_connection  \"mongodb://root:Jydl3377@192.168.1.33:27017\" --mongodb_database  \"algorithm_platform\" --mongodb_read_table  \"J00260NWP_records\" --mongodb_write_table  \"models\" --model_name \"lightgbm_model\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 33,
+   "id": "9ca17599-e453-479c-a9b3-b1d15f2d54de",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import lightgbm as lgb\n",
+    "import argparse\n",
+    "import pandas as pd \n",
+    "import numpy as np\n",
+    "from pymongo import MongoClient\n",
+    "import pickle\n",
+    "client = MongoClient(\"mongodb://root:Jydl3377@192.168.1.33:27017\")\n",
+    "db = client[\"algorithm_platform\"]\n",
+    "# collection = db[\"models\"]\n",
+    "# model_data = collection.find_one({\"model_name\": \"lightgbm_model\"})\n",
+    "# if model_data is not None:\n",
+    "#     # 假设模型存储在字段 'model' 中\n",
+    "#     model_binary = model_data['model']  # 确保这个字段是存储模型的二进制数据\n",
+    "\n",
+    "#     # 反序列化模型\n",
+    "#     model = pickle.loads(model_binary)\n",
+    "# model"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 62,
+   "id": "ff940fec-55fd-4cbd-99ef-5564c6632efb",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "90.50265625"
+      ]
+     },
+     "execution_count": 62,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "collection = db[\"J00260NWP_records_accuracy\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "df['accuracy'].mean()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 42,
+   "id": "8c55f915-4db7-4859-b449-07b2891635bc",
+   "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>date</th>\n",
+       "      <th>accuracy</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>3</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270c</td>\n",
+       "      <td>2024-05-05</td>\n",
+       "      <td>92.48</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>4</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270d</td>\n",
+       "      <td>2024-05-06</td>\n",
+       "      <td>92.05</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>5</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270e</td>\n",
+       "      <td>2024-05-07</td>\n",
+       "      <td>90.81</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>6</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270f</td>\n",
+       "      <td>2024-05-08</td>\n",
+       "      <td>94.91</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>7</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2710</td>\n",
+       "      <td>2024-05-09</td>\n",
+       "      <td>84.49</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>...</th>\n",
+       "      <td>...</td>\n",
+       "      <td>...</td>\n",
+       "      <td>...</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>123</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2784</td>\n",
+       "      <td>2024-09-07</td>\n",
+       "      <td>91.89</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>124</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2785</td>\n",
+       "      <td>2024-09-08</td>\n",
+       "      <td>83.68</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>125</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2786</td>\n",
+       "      <td>2024-09-10</td>\n",
+       "      <td>91.89</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>126</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2787</td>\n",
+       "      <td>2024-09-11</td>\n",
+       "      <td>88.76</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>127</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2788</td>\n",
+       "      <td>2024-09-12</td>\n",
+       "      <td>86.05</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>125 rows × 3 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                          _id        date  accuracy\n",
+       "3    66f24cdb7783ad7f1a7a270c  2024-05-05     92.48\n",
+       "4    66f24cdb7783ad7f1a7a270d  2024-05-06     92.05\n",
+       "5    66f24cdb7783ad7f1a7a270e  2024-05-07     90.81\n",
+       "6    66f24cdb7783ad7f1a7a270f  2024-05-08     94.91\n",
+       "7    66f24cdb7783ad7f1a7a2710  2024-05-09     84.49\n",
+       "..                        ...         ...       ...\n",
+       "123  66f24cdb7783ad7f1a7a2784  2024-09-07     91.89\n",
+       "124  66f24cdb7783ad7f1a7a2785  2024-09-08     83.68\n",
+       "125  66f24cdb7783ad7f1a7a2786  2024-09-10     91.89\n",
+       "126  66f24cdb7783ad7f1a7a2787  2024-09-11     88.76\n",
+       "127  66f24cdb7783ad7f1a7a2788  2024-09-12     86.05\n",
+       "\n",
+       "[125 rows x 3 columns]"
+      ]
+     },
+     "execution_count": 42,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df[df['date']>='2024-05-05']"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 39,
+   "id": "7feaff6d-e41a-4bd7-b6fb-a63fc6900cca",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import argparse\n",
+    "import importlib\n",
+    "import acc\n",
+    "from datetime import datetime, timedelta\n",
+    "\n",
+    "collection = db[\"J00260NWP_records_predict\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "df.to_csv('J00260_predict.csv',encoding='gbk')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 64,
+   "id": "8a22f3e9-feff-438e-81e2-b5ceaa15ac48",
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "90.50265625000002"
+      ]
+     },
+     "execution_count": 64,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "import argparse\n",
+    "import importlib\n",
+    "import acc\n",
+    "from datetime import datetime, timedelta\n",
+    "\n",
+    "collection = db[\"J00260NWP_records_predict\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "\n",
+    "# 重新加载模块\n",
+    "importlib.reload(acc)\n",
+    "from acc import calculate_acc\n",
+    "\n",
+    "df_tmp = df[['C_TIME','实际功率','predict']].rename(columns={'实际功率':'realValue','predict':'forecastAbleValue'})\n",
+    "df_tmp = df_tmp[~np.isnan(df_tmp['realValue'])]\n",
+    "df_tmp['ableValue'] = df_tmp['realValue']\n",
+    "df_tmp['C_TIME'] = df_tmp['C_TIME'].apply(lambda x: datetime.strptime(x, \"%Y-%m-%d %H:%M:%S\"))\n",
+    "\n",
+    "cc = {\n",
+    "    'formulaType': 'DAY_SHORT_ACCURACY',\n",
+    "    'cap': '225',\n",
+    "    'province': 'E15',\n",
+    "    'electricType': 'E2',\n",
+    "    'stationCode': 'J00260' }\n",
+    "            \n",
+    "opt = argparse.Namespace(**cc)\n",
+    "\n",
+    "calculate_acc(df_tmp, opt)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 57,
+   "id": "abccb68a-cc63-4474-8167-ab1e01363ad2",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>51</th>\n",
+       "      <td>66ecc86f1075358d129a1e72</td>\n",
+       "      <td>2024-05-05 21:30:00</td>\n",
+       "      <td>128.71</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.10</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.61</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6149</td>\n",
+       "      <td>58.2727</td>\n",
+       "      <td>...</td>\n",
+       "      <td>9.0536</td>\n",
+       "      <td>44.5345</td>\n",
+       "      <td>46.8773</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0082</td>\n",
+       "      <td>14.4073</td>\n",
+       "      <td>22.4573</td>\n",
+       "      <td>890.2109</td>\n",
+       "      <td>76.442233</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>52</th>\n",
+       "      <td>66ecc86f1075358d129a1e73</td>\n",
+       "      <td>2024-05-05 21:45:00</td>\n",
+       "      <td>129.84</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.34</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.70</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5280</td>\n",
+       "      <td>56.5700</td>\n",
+       "      <td>...</td>\n",
+       "      <td>8.3291</td>\n",
+       "      <td>43.2064</td>\n",
+       "      <td>45.5273</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0091</td>\n",
+       "      <td>14.1027</td>\n",
+       "      <td>23.0645</td>\n",
+       "      <td>890.3364</td>\n",
+       "      <td>75.284865</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>53</th>\n",
+       "      <td>66ecc86f1075358d129a1e74</td>\n",
+       "      <td>2024-05-05 22:00:00</td>\n",
+       "      <td>136.81</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>111.86</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>91.75</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5088</td>\n",
+       "      <td>55.0418</td>\n",
+       "      <td>...</td>\n",
+       "      <td>7.3591</td>\n",
+       "      <td>41.9909</td>\n",
+       "      <td>44.1800</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0100</td>\n",
+       "      <td>13.8064</td>\n",
+       "      <td>23.6636</td>\n",
+       "      <td>890.4555</td>\n",
+       "      <td>75.199564</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>3 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                         _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "51  66ecc86f1075358d129a1e72  2024-05-05 21:30:00  128.71       8.98  108.10   \n",
+       "52  66ecc86f1075358d129a1e73  2024-05-05 21:45:00  129.84       8.98  108.34   \n",
+       "53  66ecc86f1075358d129a1e74  2024-05-05 22:00:00  136.81       8.98  111.86   \n",
+       "\n",
+       "    实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "51   -0.99  93.61       0.0       3.6149      58.2727  ...   9.0536  44.5345   \n",
+       "52   -0.99  92.70       0.0       3.5280      56.5700  ...   8.3291  43.2064   \n",
+       "53   -0.99  91.75       0.0       3.5088      55.0418  ...   7.3591  41.9909   \n",
+       "\n",
+       "    NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "51  46.8773        0.0        0.0     0.0082  14.4073  22.4573  890.2109   \n",
+       "52  45.5273        0.0        0.0     0.0091  14.1027  23.0645  890.3364   \n",
+       "53  44.1800        0.0        0.0     0.0100  13.8064  23.6636  890.4555   \n",
+       "\n",
+       "      predict  \n",
+       "51  76.442233  \n",
+       "52  75.284865  \n",
+       "53  75.199564  \n",
+       "\n",
+       "[3 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 57,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df[df['C_TIME'].str.contains('2024-05-05')]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 56,
+   "id": "abf7687b-faf2-4b78-a9f2-44a2fea9daaa",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>51</th>\n",
+       "      <td>66ecc86f1075358d129a1e72</td>\n",
+       "      <td>2024-05-05 21:30:00</td>\n",
+       "      <td>128.71</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.10</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.61</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6149</td>\n",
+       "      <td>58.2727</td>\n",
+       "      <td>...</td>\n",
+       "      <td>9.0536</td>\n",
+       "      <td>44.5345</td>\n",
+       "      <td>46.8773</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0082</td>\n",
+       "      <td>14.4073</td>\n",
+       "      <td>22.4573</td>\n",
+       "      <td>890.2109</td>\n",
+       "      <td>76.442233</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>52</th>\n",
+       "      <td>66ecc86f1075358d129a1e73</td>\n",
+       "      <td>2024-05-05 21:45:00</td>\n",
+       "      <td>129.84</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.34</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.70</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5280</td>\n",
+       "      <td>56.5700</td>\n",
+       "      <td>...</td>\n",
+       "      <td>8.3291</td>\n",
+       "      <td>43.2064</td>\n",
+       "      <td>45.5273</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0091</td>\n",
+       "      <td>14.1027</td>\n",
+       "      <td>23.0645</td>\n",
+       "      <td>890.3364</td>\n",
+       "      <td>75.284865</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>53</th>\n",
+       "      <td>66ecc86f1075358d129a1e74</td>\n",
+       "      <td>2024-05-05 22:00:00</td>\n",
+       "      <td>136.81</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>111.86</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>91.75</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5088</td>\n",
+       "      <td>55.0418</td>\n",
+       "      <td>...</td>\n",
+       "      <td>7.3591</td>\n",
+       "      <td>41.9909</td>\n",
+       "      <td>44.1800</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0100</td>\n",
+       "      <td>13.8064</td>\n",
+       "      <td>23.6636</td>\n",
+       "      <td>890.4555</td>\n",
+       "      <td>75.199564</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>3 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                         _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "51  66ecc86f1075358d129a1e72  2024-05-05 21:30:00  128.71       8.98  108.10   \n",
+       "52  66ecc86f1075358d129a1e73  2024-05-05 21:45:00  129.84       8.98  108.34   \n",
+       "53  66ecc86f1075358d129a1e74  2024-05-05 22:00:00  136.81       8.98  111.86   \n",
+       "\n",
+       "    实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "51   -0.99  93.61       0.0       3.6149      58.2727  ...   9.0536  44.5345   \n",
+       "52   -0.99  92.70       0.0       3.5280      56.5700  ...   8.3291  43.2064   \n",
+       "53   -0.99  91.75       0.0       3.5088      55.0418  ...   7.3591  41.9909   \n",
+       "\n",
+       "    NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "51  46.8773        0.0        0.0     0.0082  14.4073  22.4573  890.2109   \n",
+       "52  45.5273        0.0        0.0     0.0091  14.1027  23.0645  890.3364   \n",
+       "53  44.1800        0.0        0.0     0.0100  13.8064  23.6636  890.4555   \n",
+       "\n",
+       "      predict  \n",
+       "51  76.442233  \n",
+       "52  75.284865  \n",
+       "53  75.199564  \n",
+       "\n",
+       "[3 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 56,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df[df['C_TIME'].str.contains('2024-05-05')]"
+   ]
+  }
+ ],
+ "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
+}

+ 16 - 0
evaluation_processing/evaluation_accuracy/Dockerfile

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "evaluation_accuracy.py"]
+# 执行 Python 脚本
+CMD []

+ 192 - 0
evaluation_processing/evaluation_accuracy/evaluation_accuracy.py

@@ -0,0 +1,192 @@
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import requests
+import json, time
+from datetime import datetime
+
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+app = Flask('evaluation_accuracy——service')
+url = 'http://49.4.78.194:17160/apiCalculate/calculate'
+'''
+准确率接口使用手顺:
+①入口方法为 calculate_acc
+② 按照参数传传值
+data含有C_TIME时间、realValue实际功率、ableValue可用功率(没有数值用实际功率替代)、forecastAbleValue预测功率
+opt为包含场站必要信息的字典,字段为:cap装机容量 province省份 formulaType公式类型 electricType电站类型 stationCode场站编码
+具体介绍参考接口文档
+③公式计算分为按天和按点两种,指定好opt.formulaType,即可设置公式类型,再在求取的每天或每个点的结果上进行平均,结果返回
+'''
+
+
+def wrap_json(df, opt):
+    """
+    包装json
+    :param df: 列名为 C_TIME realValue ableValue forecastAbleValue的DataFrame
+    :param opt: 参数字典
+    :return: json列表
+    """
+    d = opt['formulaType'].split('_')[0]
+    jata, dfs = [], []
+    if d == 'POINT':
+        df['time'] = df['C_TIME'].apply(datetime_to_timestamp)
+        for i, row in df.iterrows():
+            dfs.append(row.to_frame().T)
+    elif d == 'DAY':
+        df = df.copy()
+        # df['time'] = df['C_TIME'].apply(datetime_to_timestamp) int(round(time.mktime(df['C_TIME'].timetuple()))*1000)
+        # df.loc[:, 'time'] = df['C_TIME'].apply(datetime_to_timestamp)
+        df['time'] = df['C_TIME'].apply(lambda x: datetime_to_timestamp(x))
+        # df['time'] = df.apply(lambda row: datetime_to_timestamp(row['C_TIME']), axis=1)
+
+        # df['C_TIME'] = df['C_TIME'].dt.strftime('%y%m%d')   # 转换成年月日
+        df.loc[:, 'C_TIME'] = df['C_TIME'].dt.strftime('%y%m%d')
+        for i, group in df.groupby('C_TIME'):
+            dfs.append(group)
+    outter_dict = {"electricCapacity": str(opt['cap']), "province": opt['province'], "formulaType": opt['formulaType'], "electricType":opt['electricType'], "stationCode": opt['stationCode']}
+    timestamp = int(time.mktime(datetime.now().timetuple()) * 1000 + datetime.now().microsecond / 1000.0)
+    inner_dict = {"genTime": str(timestamp)+"L", "capacity": str(opt['cap']), "openCapacity": str(opt['cap'])}
+    for df in dfs:
+        calculationInfoList = df.iloc[:, 1:].to_json(orient='records')
+        outter_dict['calculationInfoList'] = [dict(calculation, **inner_dict) for calculation in eval(calculationInfoList)]
+        jata.append(json.dumps(outter_dict))
+    return jata
+
+
+def send_reqest(url, jata):
+    """
+    发送请求
+    :param url: 请求地址
+    :param jata: Json数据
+    :return: 准确率
+    """
+    headers = {
+        'content-type': 'application/json;charset=UTF-8',
+        "Authorization": "dXNlcjoxMjM0NTY="
+    }
+    acc, number = 0, 0
+    for i in range(len(jata)):
+        res = requests.post(url, headers=headers, data=jata[i])
+        if res.json()['code'] == '500':
+            print("没通过考核标准", end=' ')
+            continue
+        number += 1
+        acc += float(res.json()['data'][:-1])
+    if number != 0:
+        acc /= number
+    else:
+        print("无法迭代计算准确率平均值,分母为0")
+    return acc
+
+
+def calculate_acc(data, opt):
+    """
+    准确率调用接口计算
+    :param data: 列名为 C_TIME realValue ableValue forecastAbleValue的DataFrame
+    :param opt: 参数字段
+    :return: 计算结果
+    """
+    jata = wrap_json(data, opt)
+    acc = send_reqest(url=url, jata=jata)
+    return acc
+
+
+def datetime_to_timestamp(dt):
+    return int(round(time.mktime(dt.timetuple()))*1000)
+
+
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+def compute_accuracy(df,args):
+    col_time,col_rp,col_pp,formulaType = args['col_time'],args['col_rp'],args['col_pp'],args['formulaType'].split('_')[0]
+    dates = []
+    accuracy = []
+    df = df[(~np.isnan(df[col_rp]))&(~np.isnan(df[col_pp]))]
+    df = df[[col_time,col_rp,col_pp]].rename(columns={col_time:'C_TIME',col_rp:'realValue',col_pp:'forecastAbleValue'})
+    df['ableValue'] = df['realValue']
+    df['C_TIME'] = df['C_TIME'].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S"))
+    if formulaType=='DAY':
+        df['C_DATE'] = df['C_TIME'].apply(lambda x: x.strftime("%Y-%m-%d"))
+        days_list = df['C_DATE'].unique().tolist()
+        for day in days_list:
+            df_tmp = df[df['C_DATE'] == day]
+            dates.append(day)
+            accuracy.append(calculate_acc(df_tmp, args))
+    else:
+        points = df['C_TIME'].unique().tolist()
+        for point in points:
+            df_tmp = df[df['C_TIME'] == point]
+            dates.append(point)
+            accuracy.append(calculate_acc(df_tmp, args))
+    print("accuray compute successfully!")
+    return pd.DataFrame({'date':dates,'accuracy':accuracy})
+
+
+@app.route('/evaluation_accuracy', methods=['POST'])
+def evaluation_accuracy():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        acc_result = compute_accuracy(power_df,args)
+        insert_data_into_mongo(acc_result,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+    
+
+if __name__=="__main__":  
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("evaluation_accuracy log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10091)
+    print("server start!")

+ 6 - 0
evaluation_processing/evaluation_accuracy/requirements.txt

@@ -0,0 +1,6 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+requests==2.32.3
+Flask==3.0.3
+waitress==3.0.0

+ 811 - 0
evaluation_processing/evaluation_accuracy/test.ipynb

@@ -0,0 +1,811 @@
+{
+ "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": null,
+   "id": "b47d615a-5953-43c0-9289-387d5c823a7a",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 14:20:47,541 - waitress - INFO - Serving on http://0.0.0.0:10091\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 14:21:19,377 - evaluation_accuracy log - INFO - {'formulaType': 'DAY_SHORT_ACCURACY', 'cap': '225', 'province': 'E15', 'electricType': 'E2', 'stationCode': 'J00260', 'col_time': 'C_TIME', 'col_rp': '实际功率', 'col_pp': 'predict', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records_predict', 'mongodb_write_table': 'J00260NWP_records_accuracy'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'formulaType': 'DAY_SHORT_ACCURACY', 'cap': '225', 'province': 'E15', 'electricType': 'E2', 'stationCode': 'J00260', 'col_time': 'C_TIME', 'col_rp': '实际功率', 'col_pp': 'predict', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records_predict', 'mongodb_write_table': 'J00260NWP_records_accuracy'}\n",
+      "accuray compute successfully!\n",
+      "Collection 'J00260NWP_records_accuracy already exist, deleted successfully!\n",
+      "data inserted successfully!\n",
+      "Program execution ends!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 14:25:11,738 - evaluation_accuracy log - INFO - {'formulaType': 'DAY_SHORT_ACCURACY', 'cap': '225', 'province': 'E15', 'electricType': 'E2', 'stationCode': 'J00260', 'col_time': 'C_TIME', 'col_rp': '实际功率', 'col_pp': 'predict', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records_predict', 'mongodb_write_table': 'J00260NWP_records_accuracy'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'formulaType': 'DAY_SHORT_ACCURACY', 'cap': '225', 'province': 'E15', 'electricType': 'E2', 'stationCode': 'J00260', 'col_time': 'C_TIME', 'col_rp': '实际功率', 'col_pp': 'predict', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records_predict', 'mongodb_write_table': 'J00260NWP_records_accuracy'}\n",
+      "accuray compute successfully!\n",
+      "Collection 'J00260NWP_records_accuracy already exist, deleted successfully!\n",
+      "data inserted successfully!\n",
+      "Program execution ends!\n"
+     ]
+    }
+   ],
+   "source": [
+    "%run evaluation_accuracy.py"
+   ]
+  },
+  {
+   "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": [
+    "'formulaType': 'DAY_SHORT_ACCURACY',\n",
+    "    'cap': '225',\n",
+    "    'province': 'E15',\n",
+    "    'electricType': 'E2',\n",
+    "    'stationCode': 'J00260'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Output:\n",
+      "Program starts execution!\n",
+      "args: Namespace(formulaType='DAY_SHORT_ACCURACY', cap='225', province='E15', electricType='E2', stationCode='J00260', col_time='C_TIME', col_rp='实际功率', col_pp='predict', mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_records_predict', mongodb_write_table='J00260NWP_records_accuracy')\n",
+      "accuray compute successfully!\n",
+      "Collection 'J00260NWP_records_accuracy 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\", \"accuracy.py\",\n",
+    "    \"--formulaType\", \"DAY_SHORT_ACCURACY\",\n",
+    "    \"--cap\",\"225\",\n",
+    "    \"--province\",\"E15\",\n",
+    "    \"--electricType\",\"E2\",\n",
+    "    \"--stationCode\",\"J00260\",\n",
+    "    \"--col_time\",\"C_TIME\",\n",
+    "    \"--col_rp\",\"实际功率\",\n",
+    "    \"--col_pp\",\"predict\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_records_predict\",\n",
+    "    \"--mongodb_write_table\", \"J00260NWP_records_accuracy\",\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)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "1cb1c745-0673-4dfa-968f-8985e788852a",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "\"--electricType\",\"E2\",\n",
+    "\"--stationCode\",\"J00260\",\n",
+    "\"--col_time\",\"C_TIME\",\n",
+    "\"--col_rp\",\"实际功率\",\n",
+    "\"--col_pp\",\"predict\",\n",
+    "\"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "\"--mongodb_database\", \"algorithm_platform\",\n",
+    "\"--mongodb_read_table\", \"J00260NWP_records_predict\",\n",
+    "\"--mongodb_write_table\", \"J00260NWP_records_accuracy\","
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "14a9feb4-5625-45d7-8e0f-6a8dea8c9f24",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run evaluation_accuracy  --formulaType \"DAY_SHORT_ACCURACY\"     --cap \"225\"   --province \"E15\"     --electricType \"E2\"    --stationCode \"J00260\"     --col_time \"C_TIME\"     --col_rp \"实际功率\"   --col_pp \"predict\"  --mongodb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"   --mongodb_database \"algorithm_platform\"   --mongodb_read_table \"J00260NWP_records_predict\"  --mongodb_write_table \"J00260NWP_records_accuracy\"        "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run evaluation_accuracy.py --numerical_features ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'])  --categorical_features  ','.join([])  --label  \"实际功率\" --learning_rate  \"0.01\" --num_leaves \"31\"  --min_data_in_leaf  \"21\"  --mongodb_connection  \"mongodb://root:Jydl3377@192.168.1.33:27017\" --mongodb_database  \"algorithm_platform\" --mongodb_read_table  \"J00260NWP_records\" --mongodb_write_table  \"models\" --model_name \"lightgbm_model\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "id": "9ca17599-e453-479c-a9b3-b1d15f2d54de",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import lightgbm as lgb\n",
+    "import argparse\n",
+    "import pandas as pd \n",
+    "import numpy as np\n",
+    "from pymongo import MongoClient\n",
+    "import pickle\n",
+    "client = MongoClient(\"mongodb://root:Jydl3377@192.168.1.33:27017\")\n",
+    "db = client[\"algorithm_platform\"]\n",
+    "# collection = db[\"models\"]\n",
+    "# model_data = collection.find_one({\"model_name\": \"lightgbm_model\"})\n",
+    "# if model_data is not None:\n",
+    "#     # 假设模型存储在字段 'model' 中\n",
+    "#     model_binary = model_data['model']  # 确保这个字段是存储模型的二进制数据\n",
+    "\n",
+    "#     # 反序列化模型\n",
+    "#     model = pickle.loads(model_binary)\n",
+    "# model"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "id": "ff940fec-55fd-4cbd-99ef-5564c6632efb",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "90.50265625"
+      ]
+     },
+     "execution_count": 8,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "collection = db[\"J00260NWP_records_accuracy\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "df['accuracy'].mean()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 42,
+   "id": "8c55f915-4db7-4859-b449-07b2891635bc",
+   "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>date</th>\n",
+       "      <th>accuracy</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>3</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270c</td>\n",
+       "      <td>2024-05-05</td>\n",
+       "      <td>92.48</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>4</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270d</td>\n",
+       "      <td>2024-05-06</td>\n",
+       "      <td>92.05</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>5</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270e</td>\n",
+       "      <td>2024-05-07</td>\n",
+       "      <td>90.81</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>6</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a270f</td>\n",
+       "      <td>2024-05-08</td>\n",
+       "      <td>94.91</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>7</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2710</td>\n",
+       "      <td>2024-05-09</td>\n",
+       "      <td>84.49</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>...</th>\n",
+       "      <td>...</td>\n",
+       "      <td>...</td>\n",
+       "      <td>...</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>123</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2784</td>\n",
+       "      <td>2024-09-07</td>\n",
+       "      <td>91.89</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>124</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2785</td>\n",
+       "      <td>2024-09-08</td>\n",
+       "      <td>83.68</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>125</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2786</td>\n",
+       "      <td>2024-09-10</td>\n",
+       "      <td>91.89</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>126</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2787</td>\n",
+       "      <td>2024-09-11</td>\n",
+       "      <td>88.76</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>127</th>\n",
+       "      <td>66f24cdb7783ad7f1a7a2788</td>\n",
+       "      <td>2024-09-12</td>\n",
+       "      <td>86.05</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>125 rows × 3 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                          _id        date  accuracy\n",
+       "3    66f24cdb7783ad7f1a7a270c  2024-05-05     92.48\n",
+       "4    66f24cdb7783ad7f1a7a270d  2024-05-06     92.05\n",
+       "5    66f24cdb7783ad7f1a7a270e  2024-05-07     90.81\n",
+       "6    66f24cdb7783ad7f1a7a270f  2024-05-08     94.91\n",
+       "7    66f24cdb7783ad7f1a7a2710  2024-05-09     84.49\n",
+       "..                        ...         ...       ...\n",
+       "123  66f24cdb7783ad7f1a7a2784  2024-09-07     91.89\n",
+       "124  66f24cdb7783ad7f1a7a2785  2024-09-08     83.68\n",
+       "125  66f24cdb7783ad7f1a7a2786  2024-09-10     91.89\n",
+       "126  66f24cdb7783ad7f1a7a2787  2024-09-11     88.76\n",
+       "127  66f24cdb7783ad7f1a7a2788  2024-09-12     86.05\n",
+       "\n",
+       "[125 rows x 3 columns]"
+      ]
+     },
+     "execution_count": 42,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df[df['date']>='2024-05-05']"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 39,
+   "id": "7feaff6d-e41a-4bd7-b6fb-a63fc6900cca",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import argparse\n",
+    "import importlib\n",
+    "import acc\n",
+    "from datetime import datetime, timedelta\n",
+    "\n",
+    "collection = db[\"J00260NWP_records_predict\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "df.to_csv('J00260_predict.csv',encoding='gbk')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 64,
+   "id": "8a22f3e9-feff-438e-81e2-b5ceaa15ac48",
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "90.50265625000002"
+      ]
+     },
+     "execution_count": 64,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "import argparse\n",
+    "import importlib\n",
+    "import acc\n",
+    "from datetime import datetime, timedelta\n",
+    "\n",
+    "collection = db[\"J00260NWP_records_predict\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "\n",
+    "# 重新加载模块\n",
+    "importlib.reload(acc)\n",
+    "from acc import calculate_acc\n",
+    "\n",
+    "df_tmp = df[['C_TIME','实际功率','predict']].rename(columns={'实际功率':'realValue','predict':'forecastAbleValue'})\n",
+    "df_tmp = df_tmp[~np.isnan(df_tmp['realValue'])]\n",
+    "df_tmp['ableValue'] = df_tmp['realValue']\n",
+    "df_tmp['C_TIME'] = df_tmp['C_TIME'].apply(lambda x: datetime.strptime(x, \"%Y-%m-%d %H:%M:%S\"))\n",
+    "\n",
+    "cc = {\n",
+    "    'formulaType': 'DAY_SHORT_ACCURACY',\n",
+    "    'cap': '225',\n",
+    "    'province': 'E15',\n",
+    "    'electricType': 'E2',\n",
+    "    'stationCode': 'J00260' }\n",
+    "            \n",
+    "opt = argparse.Namespace(**cc)\n",
+    "\n",
+    "calculate_acc(df_tmp, opt)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 57,
+   "id": "abccb68a-cc63-4474-8167-ab1e01363ad2",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>51</th>\n",
+       "      <td>66ecc86f1075358d129a1e72</td>\n",
+       "      <td>2024-05-05 21:30:00</td>\n",
+       "      <td>128.71</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.10</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.61</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6149</td>\n",
+       "      <td>58.2727</td>\n",
+       "      <td>...</td>\n",
+       "      <td>9.0536</td>\n",
+       "      <td>44.5345</td>\n",
+       "      <td>46.8773</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0082</td>\n",
+       "      <td>14.4073</td>\n",
+       "      <td>22.4573</td>\n",
+       "      <td>890.2109</td>\n",
+       "      <td>76.442233</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>52</th>\n",
+       "      <td>66ecc86f1075358d129a1e73</td>\n",
+       "      <td>2024-05-05 21:45:00</td>\n",
+       "      <td>129.84</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.34</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.70</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5280</td>\n",
+       "      <td>56.5700</td>\n",
+       "      <td>...</td>\n",
+       "      <td>8.3291</td>\n",
+       "      <td>43.2064</td>\n",
+       "      <td>45.5273</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0091</td>\n",
+       "      <td>14.1027</td>\n",
+       "      <td>23.0645</td>\n",
+       "      <td>890.3364</td>\n",
+       "      <td>75.284865</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>53</th>\n",
+       "      <td>66ecc86f1075358d129a1e74</td>\n",
+       "      <td>2024-05-05 22:00:00</td>\n",
+       "      <td>136.81</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>111.86</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>91.75</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5088</td>\n",
+       "      <td>55.0418</td>\n",
+       "      <td>...</td>\n",
+       "      <td>7.3591</td>\n",
+       "      <td>41.9909</td>\n",
+       "      <td>44.1800</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0100</td>\n",
+       "      <td>13.8064</td>\n",
+       "      <td>23.6636</td>\n",
+       "      <td>890.4555</td>\n",
+       "      <td>75.199564</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>3 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                         _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "51  66ecc86f1075358d129a1e72  2024-05-05 21:30:00  128.71       8.98  108.10   \n",
+       "52  66ecc86f1075358d129a1e73  2024-05-05 21:45:00  129.84       8.98  108.34   \n",
+       "53  66ecc86f1075358d129a1e74  2024-05-05 22:00:00  136.81       8.98  111.86   \n",
+       "\n",
+       "    实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "51   -0.99  93.61       0.0       3.6149      58.2727  ...   9.0536  44.5345   \n",
+       "52   -0.99  92.70       0.0       3.5280      56.5700  ...   8.3291  43.2064   \n",
+       "53   -0.99  91.75       0.0       3.5088      55.0418  ...   7.3591  41.9909   \n",
+       "\n",
+       "    NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "51  46.8773        0.0        0.0     0.0082  14.4073  22.4573  890.2109   \n",
+       "52  45.5273        0.0        0.0     0.0091  14.1027  23.0645  890.3364   \n",
+       "53  44.1800        0.0        0.0     0.0100  13.8064  23.6636  890.4555   \n",
+       "\n",
+       "      predict  \n",
+       "51  76.442233  \n",
+       "52  75.284865  \n",
+       "53  75.199564  \n",
+       "\n",
+       "[3 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 57,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df[df['C_TIME'].str.contains('2024-05-05')]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 56,
+   "id": "abf7687b-faf2-4b78-a9f2-44a2fea9daaa",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>51</th>\n",
+       "      <td>66ecc86f1075358d129a1e72</td>\n",
+       "      <td>2024-05-05 21:30:00</td>\n",
+       "      <td>128.71</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.10</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.61</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6149</td>\n",
+       "      <td>58.2727</td>\n",
+       "      <td>...</td>\n",
+       "      <td>9.0536</td>\n",
+       "      <td>44.5345</td>\n",
+       "      <td>46.8773</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0082</td>\n",
+       "      <td>14.4073</td>\n",
+       "      <td>22.4573</td>\n",
+       "      <td>890.2109</td>\n",
+       "      <td>76.442233</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>52</th>\n",
+       "      <td>66ecc86f1075358d129a1e73</td>\n",
+       "      <td>2024-05-05 21:45:00</td>\n",
+       "      <td>129.84</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>108.34</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.70</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5280</td>\n",
+       "      <td>56.5700</td>\n",
+       "      <td>...</td>\n",
+       "      <td>8.3291</td>\n",
+       "      <td>43.2064</td>\n",
+       "      <td>45.5273</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0091</td>\n",
+       "      <td>14.1027</td>\n",
+       "      <td>23.0645</td>\n",
+       "      <td>890.3364</td>\n",
+       "      <td>75.284865</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>53</th>\n",
+       "      <td>66ecc86f1075358d129a1e74</td>\n",
+       "      <td>2024-05-05 22:00:00</td>\n",
+       "      <td>136.81</td>\n",
+       "      <td>8.98</td>\n",
+       "      <td>111.86</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>91.75</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.5088</td>\n",
+       "      <td>55.0418</td>\n",
+       "      <td>...</td>\n",
+       "      <td>7.3591</td>\n",
+       "      <td>41.9909</td>\n",
+       "      <td>44.1800</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0100</td>\n",
+       "      <td>13.8064</td>\n",
+       "      <td>23.6636</td>\n",
+       "      <td>890.4555</td>\n",
+       "      <td>75.199564</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>3 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                         _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "51  66ecc86f1075358d129a1e72  2024-05-05 21:30:00  128.71       8.98  108.10   \n",
+       "52  66ecc86f1075358d129a1e73  2024-05-05 21:45:00  129.84       8.98  108.34   \n",
+       "53  66ecc86f1075358d129a1e74  2024-05-05 22:00:00  136.81       8.98  111.86   \n",
+       "\n",
+       "    实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "51   -0.99  93.61       0.0       3.6149      58.2727  ...   9.0536  44.5345   \n",
+       "52   -0.99  92.70       0.0       3.5280      56.5700  ...   8.3291  43.2064   \n",
+       "53   -0.99  91.75       0.0       3.5088      55.0418  ...   7.3591  41.9909   \n",
+       "\n",
+       "    NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "51  46.8773        0.0        0.0     0.0082  14.4073  22.4573  890.2109   \n",
+       "52  45.5273        0.0        0.0     0.0091  14.1027  23.0645  890.3364   \n",
+       "53  44.1800        0.0        0.0     0.0100  13.8064  23.6636  890.4555   \n",
+       "\n",
+       "      predict  \n",
+       "51  76.442233  \n",
+       "52  75.284865  \n",
+       "53  75.199564  \n",
+       "\n",
+       "[3 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 56,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df[df['C_TIME'].str.contains('2024-05-05')]"
+   ]
+  }
+ ],
+ "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
+}

+ 16 - 0
models_processing/model_prediction_lightgbm/.ipynb_checkpoints/Dockerfile-checkpoint

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "model_prediction_lightgbm.py"]
+# 执行 Python 脚本
+CMD []

+ 96 - 0
models_processing/model_prediction_lightgbm/.ipynb_checkpoints/model_prediction_lightgbm-checkpoint.py

@@ -0,0 +1,96 @@
+import lightgbm as lgb
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import pickle
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+
+app = Flask('model_prediction_lightgbm——service')
+
+
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+def model_prediction(df,args):
+    mongodb_connection,mongodb_database,mongodb_model_table,model_name = args['mongodb_connection'],args['mongodb_database'],args['mongodb_model_table'],args['model_name']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    collection = db[mongodb_model_table]
+    model_data = collection.find_one({"model_name": model_name})
+    if model_data is not None:
+        model_binary = model_data['model']  # 确保这个字段是存储模型的二进制数据
+        # 反序列化模型 
+        model = pickle.loads(model_binary)
+        df['predict'] = model.predict(df[model.feature_name()])
+        print("model predict result  successfully!")
+    return df
+
+
+@app.route('/model_prediction_lightgbm', methods=['POST'])
+def model_prediction_lightgbm():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        model = model_prediction(power_df,args)
+        insert_data_into_mongo(model,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+
+
+if __name__=="__main__":  
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("model_prediction_lightgbm log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10089)
+    print("server start!")
+    

+ 7 - 0
models_processing/model_prediction_lightgbm/.ipynb_checkpoints/requirements-checkpoint.txt

@@ -0,0 +1,7 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+lightgbm==4.3.0
+scikit-learn==1.4.2
+Flask==3.0.3
+waitress==3.0.0

+ 490 - 0
models_processing/model_prediction_lightgbm/.ipynb_checkpoints/test-checkpoint.ipynb

@@ -0,0 +1,490 @@
+{
+ "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": [
+    "parser.add_argument('--mongodb_connection', type=str, required=True, help=\"mongodb连接\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_database', type=str, required=True, help=\"mongodb数据库名\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_read_table', type=str, required=True, help=\"mongodb数据库读取表\")# tmp_one\n",
+    "parser.add_argument('--mongodb_model_table', type=str, required=True, help=\"mongodb读取模型集合\")# tmp_one\n",
+    "parser.add_argument('--model_name', type=str, required=True, help=\"保存模型名\")# tmp_one\n",
+    "#出参\n",
+    "parser.add_argument('--mongodb_write_table', type=str, required=True, help=\"mongodb数据库存储集合\")# tmp_one"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 62,
+   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Output:\n",
+      "Program starts execution!\n",
+      "args: Namespace(numerical_features=['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向', 'NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向', 'NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向', 'NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向', 'NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射', 'NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'], categorical_features=[], label='实际功率', learning_rate=0.01, num_leaves=31, min_data_in_leaf=21, mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_records', mongodb_write_table='models', model_name='lightgbm_model')\n",
+      "df:************                         _id               C_TIME  ...   NWP-湿度    NWP-气压\n",
+      "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  ...  23.4918  892.3327\n",
+      "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  ...  24.0436  892.3809\n",
+      "\n",
+      "[2 rows x 34 columns]\n",
+      "Starting training...\n",
+      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000981 seconds.\n",
+      "You can set `force_col_wise=true` to remove the overhead.\n",
+      "[LightGBM] [Info] Total Bins 6885\n",
+      "[LightGBM] [Info] Number of data points in the train set: 7770, number of used features: 27\n",
+      "[LightGBM] [Info] Start training from score 47.616663\n",
+      "Training completed!\n",
+      "Collection 'models already exist, deleted successfully!\n",
+      "model inserted successfully!\n",
+      "Program execution ends!\n",
+      "\n",
+      "Error:\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "import subprocess\n",
+    "\n",
+    "# 构建命令\n",
+    "command = [\n",
+    "    \"python\", \"model_prediction.py\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_records\",\n",
+    "    \"--mongodb_model_table\", \"models\",\n",
+    "    \"--model_name\",\"lightgbm_model\",\n",
+    "    \"--mongodb_write_table\", \"J00260NWP_records_predict\",\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": null,
+   "id": "14a9feb4-5625-45d7-8e0f-6a8dea8c9f24",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run lightgbm_model.py   --numerical_features \"2024-05-01\"     --categorical_features \"2024-09-20\"   --label \"J00260\"     --learning_rate \"C_TIME\"    --num_leaves \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP_machines\"     --mongondb_write_table \"J00260NWP_records\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run lightgbm_model.py --numerical_features ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'])  --categorical_features  ','.join([])  --label  \"实际功率\" --learning_rate  \"0.01\" --num_leaves \"31\"  --min_data_in_leaf  \"21\"  --mongodb_connection  \"mongodb://root:Jydl3377@192.168.1.33:27017\" --mongodb_database  \"algorithm_platform\" --mongodb_read_table  \"J00260NWP_records\" --mongodb_write_table  \"models\" --model_name \"lightgbm_model\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "9ca17599-e453-479c-a9b3-b1d15f2d54de",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "<lightgbm.basic.Booster at 0x16ab35646d0>"
+      ]
+     },
+     "execution_count": 2,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "import lightgbm as lgb\n",
+    "import argparse\n",
+    "import pandas as pd \n",
+    "import numpy as np\n",
+    "from pymongo import MongoClient\n",
+    "import pickle\n",
+    "client = MongoClient(\"mongodb://root:Jydl3377@192.168.1.33:27017\")\n",
+    "db = client[\"algorithm_platform\"]\n",
+    "collection = db[\"models\"]\n",
+    "model_data = collection.find_one({\"model_name\": \"lightgbm_model\"})\n",
+    "if model_data is not None:\n",
+    "    # 假设模型存储在字段 'model' 中\n",
+    "    model_binary = model_data['model']  # 确保这个字段是存储模型的二进制数据\n",
+    "\n",
+    "    # 反序列化模型\n",
+    "    model = pickle.loads(model_binary)\n",
+    "model"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "id": "ff940fec-55fd-4cbd-99ef-5564c6632efb",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-低云量</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>66ecc86f1075358d129a1d56</td>\n",
+       "      <td>2024-05-02 22:30:00</td>\n",
+       "      <td>130.05</td>\n",
+       "      <td>9.63</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.52</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6477</td>\n",
+       "      <td>202.7945</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0173</td>\n",
+       "      <td>20.2918</td>\n",
+       "      <td>20.3927</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>14.0818</td>\n",
+       "      <td>23.4918</td>\n",
+       "      <td>892.3327</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>1</th>\n",
+       "      <td>66ecc86f1075358d129a1d57</td>\n",
+       "      <td>2024-05-02 22:45:00</td>\n",
+       "      <td>130.51</td>\n",
+       "      <td>9.72</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.24</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.9228</td>\n",
+       "      <td>202.6482</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0191</td>\n",
+       "      <td>20.3009</td>\n",
+       "      <td>20.3864</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>13.8264</td>\n",
+       "      <td>24.0436</td>\n",
+       "      <td>892.3809</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>2 rows × 34 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                        _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  130.05       9.63  104.76   \n",
+       "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  130.51       9.72  104.76   \n",
+       "\n",
+       "   实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-低云量  NWP-中云量  \\\n",
+       "0   -0.99  92.52       0.0       3.6477     202.7945  ...      0.0   0.0173   \n",
+       "1   -0.99  93.24       0.0       3.9228     202.6482  ...      0.0   0.0191   \n",
+       "\n",
+       "   NWP-高云量  NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度  \\\n",
+       "0  20.2918  20.3927        0.0        0.0        0.0  14.0818  23.4918   \n",
+       "1  20.3009  20.3864        0.0        0.0        0.0  13.8264  24.0436   \n",
+       "\n",
+       "     NWP-气压  \n",
+       "0  892.3327  \n",
+       "1  892.3809  \n",
+       "\n",
+       "[2 rows x 34 columns]"
+      ]
+     },
+     "execution_count": 3,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "\n",
+    "collection = db[\"J00260NWP_records\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "df.head(2)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "7feaff6d-e41a-4bd7-b6fb-a63fc6900cca",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "df['predict'] = model.predict(df[model.feature_name()])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "id": "8a22f3e9-feff-438e-81e2-b5ceaa15ac48",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>66ecc86f1075358d129a1d56</td>\n",
+       "      <td>2024-05-02 22:30:00</td>\n",
+       "      <td>130.05</td>\n",
+       "      <td>9.63</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.52</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6477</td>\n",
+       "      <td>202.7945</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0173</td>\n",
+       "      <td>20.2918</td>\n",
+       "      <td>20.3927</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>14.0818</td>\n",
+       "      <td>23.4918</td>\n",
+       "      <td>892.3327</td>\n",
+       "      <td>77.728147</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>1</th>\n",
+       "      <td>66ecc86f1075358d129a1d57</td>\n",
+       "      <td>2024-05-02 22:45:00</td>\n",
+       "      <td>130.51</td>\n",
+       "      <td>9.72</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.24</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.9228</td>\n",
+       "      <td>202.6482</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0191</td>\n",
+       "      <td>20.3009</td>\n",
+       "      <td>20.3864</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>13.8264</td>\n",
+       "      <td>24.0436</td>\n",
+       "      <td>892.3809</td>\n",
+       "      <td>84.568199</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>2 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                        _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  130.05       9.63  104.76   \n",
+       "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  130.51       9.72  104.76   \n",
+       "\n",
+       "   实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "0   -0.99  92.52       0.0       3.6477     202.7945  ...   0.0173  20.2918   \n",
+       "1   -0.99  93.24       0.0       3.9228     202.6482  ...   0.0191  20.3009   \n",
+       "\n",
+       "   NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "0  20.3927        0.0        0.0        0.0  14.0818  23.4918  892.3327   \n",
+       "1  20.3864        0.0        0.0        0.0  13.8264  24.0436  892.3809   \n",
+       "\n",
+       "     predict  \n",
+       "0  77.728147  \n",
+       "1  84.568199  \n",
+       "\n",
+       "[2 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df.head(2)"
+   ]
+  }
+ ],
+ "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
+}

+ 16 - 0
models_processing/model_prediction_lightgbm/Dockerfile

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "model_prediction_lightgbm.py"]
+# 执行 Python 脚本
+CMD []

+ 96 - 0
models_processing/model_prediction_lightgbm/model_prediction_lightgbm.py

@@ -0,0 +1,96 @@
+import lightgbm as lgb
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import pickle
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+
+app = Flask('model_prediction_lightgbm——service')
+
+
+
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_data_into_mongo(res_df,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    # 将 DataFrame 转为字典格式
+    data_dict = res_df.to_dict("records")  # 每一行作为一个字典
+    # 插入到 MongoDB
+    collection.insert_many(data_dict)
+    print("data inserted successfully!")
+    
+
+def model_prediction(df,args):
+    mongodb_connection,mongodb_database,mongodb_model_table,model_name = args['mongodb_connection'],args['mongodb_database'],args['mongodb_model_table'],args['model_name']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    collection = db[mongodb_model_table]
+    model_data = collection.find_one({"model_name": model_name})
+    if model_data is not None:
+        model_binary = model_data['model']  # 确保这个字段是存储模型的二进制数据
+        # 反序列化模型 
+        model = pickle.loads(model_binary)
+        df['predict'] = model.predict(df[model.feature_name()])
+        print("model predict result  successfully!")
+    return df
+
+
+@app.route('/model_prediction_lightgbm', methods=['POST'])
+def model_prediction_lightgbm():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        model = model_prediction(power_df,args)
+        insert_data_into_mongo(model,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+
+
+if __name__=="__main__":  
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("model_prediction_lightgbm log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10089)
+    print("server start!")
+    

+ 7 - 0
models_processing/model_prediction_lightgbm/requirements.txt

@@ -0,0 +1,7 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+lightgbm==4.3.0
+scikit-learn==1.4.2
+Flask==3.0.3
+waitress==3.0.0

+ 522 - 0
models_processing/model_prediction_lightgbm/test.ipynb

@@ -0,0 +1,522 @@
+{
+ "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": [
+    "parser.add_argument('--mongodb_connection', type=str, required=True, help=\"mongodb连接\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_database', type=str, required=True, help=\"mongodb数据库名\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_read_table', type=str, required=True, help=\"mongodb数据库读取表\")# tmp_one\n",
+    "parser.add_argument('--mongodb_model_table', type=str, required=True, help=\"mongodb读取模型集合\")# tmp_one\n",
+    "parser.add_argument('--model_name', type=str, required=True, help=\"保存模型名\")# tmp_one\n",
+    "#出参\n",
+    "parser.add_argument('--mongodb_write_table', type=str, required=True, help=\"mongodb数据库存储集合\")# tmp_one"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Output:\n",
+      "Program starts execution!\n",
+      "args: Namespace(mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_records', mongodb_model_table='models', model_name='lightgbm_model', mongodb_write_table='J00260NWP_records_predict')\n",
+      "model predict result  successfully!\n",
+      "data inserted successfully!\n",
+      "Program execution ends!\n",
+      "\n",
+      "Error:\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "import subprocess\n",
+    "\n",
+    "# 构建命令\n",
+    "command = [\n",
+    "    \"python\", \"model_prediction.py\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_records\",\n",
+    "    \"--mongodb_model_table\", \"models\",\n",
+    "    \"--model_name\",\"lightgbm_model\",\n",
+    "    \"--mongodb_write_table\", \"J00260NWP_records_predict\",\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": null,
+   "id": "14a9feb4-5625-45d7-8e0f-6a8dea8c9f24",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run model_prediction_lightgbm  --mongodb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongodb_database \"algorithm_platform\"   --mongodb_read_table \"J00260NWP_records\"     --mongodb_model_table \"models\"    --model_name \"lightgbm_model\"     --mongodb_database \"algorithm_platform\"     --mongodb_write_table \"J00260NWP_records_predict\"      "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run lightgbm_model.py --numerical_features ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'])  --categorical_features  ','.join([])  --label  \"实际功率\" --learning_rate  \"0.01\" --num_leaves \"31\"  --min_data_in_leaf  \"21\"  --mongodb_connection  \"mongodb://root:Jydl3377@192.168.1.33:27017\" --mongodb_database  \"algorithm_platform\" --mongodb_read_table  \"J00260NWP_records\" --mongodb_write_table  \"models\" --model_name \"lightgbm_model\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "6d13761d-3ba7-441c-903d-db293ab23223",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 11:55:37,911 - waitress - INFO - Serving on http://0.0.0.0:10089\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 11:57:14,162 - model_prediction_lightgbm log - INFO - {'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'J00260NWP_records_predict', 'mongodb_model_table': 'models', 'model_name': 'lightgbm_model'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'J00260NWP_records_predict', 'mongodb_model_table': 'models', 'model_name': 'lightgbm_model'}\n",
+      "model predict result  successfully!\n",
+      "Collection 'J00260NWP_records_predict already exist, deleted successfully!\n",
+      "data inserted successfully!\n",
+      "Program execution ends!\n"
+     ]
+    }
+   ],
+   "source": [
+    " %run model_prediction_lightgbm.py"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "9ca17599-e453-479c-a9b3-b1d15f2d54de",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "<lightgbm.basic.Booster at 0x16ab35646d0>"
+      ]
+     },
+     "execution_count": 2,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "import lightgbm as lgb\n",
+    "import argparse\n",
+    "import pandas as pd \n",
+    "import numpy as np\n",
+    "from pymongo import MongoClient\n",
+    "import pickle\n",
+    "client = MongoClient(\"mongodb://root:Jydl3377@192.168.1.33:27017\")\n",
+    "db = client[\"algorithm_platform\"]\n",
+    "collection = db[\"models\"]\n",
+    "model_data = collection.find_one({\"model_name\": \"lightgbm_model\"})\n",
+    "if model_data is not None:\n",
+    "    # 假设模型存储在字段 'model' 中\n",
+    "    model_binary = model_data['model']  # 确保这个字段是存储模型的二进制数据\n",
+    "\n",
+    "    # 反序列化模型\n",
+    "    model = pickle.loads(model_binary)\n",
+    "model"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "id": "ff940fec-55fd-4cbd-99ef-5564c6632efb",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>66ecc86f1075358d129a1d56</td>\n",
+       "      <td>2024-05-02 22:30:00</td>\n",
+       "      <td>130.05</td>\n",
+       "      <td>9.63</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.52</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6477</td>\n",
+       "      <td>202.7945</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0173</td>\n",
+       "      <td>20.2918</td>\n",
+       "      <td>20.3927</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>14.0818</td>\n",
+       "      <td>23.4918</td>\n",
+       "      <td>892.3327</td>\n",
+       "      <td>77.728147</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>1</th>\n",
+       "      <td>66ecc86f1075358d129a1d57</td>\n",
+       "      <td>2024-05-02 22:45:00</td>\n",
+       "      <td>130.51</td>\n",
+       "      <td>9.72</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.24</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.9228</td>\n",
+       "      <td>202.6482</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0191</td>\n",
+       "      <td>20.3009</td>\n",
+       "      <td>20.3864</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>13.8264</td>\n",
+       "      <td>24.0436</td>\n",
+       "      <td>892.3809</td>\n",
+       "      <td>84.568199</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>2 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                        _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  130.05       9.63  104.76   \n",
+       "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  130.51       9.72  104.76   \n",
+       "\n",
+       "   实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "0   -0.99  92.52       0.0       3.6477     202.7945  ...   0.0173  20.2918   \n",
+       "1   -0.99  93.24       0.0       3.9228     202.6482  ...   0.0191  20.3009   \n",
+       "\n",
+       "   NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "0  20.3927        0.0        0.0        0.0  14.0818  23.4918  892.3327   \n",
+       "1  20.3864        0.0        0.0        0.0  13.8264  24.0436  892.3809   \n",
+       "\n",
+       "     predict  \n",
+       "0  77.728147  \n",
+       "1  84.568199  \n",
+       "\n",
+       "[2 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 10,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "\n",
+    "collection = db[\"J00260NWP_records_predict\"]  # 集合名称\n",
+    "data_from_db = collection.find()  # 这会返回一个游标(cursor)\n",
+    "# 将游标转换为列表,并创建 pandas DataFrame\n",
+    "df = pd.DataFrame(list(data_from_db))\n",
+    "df.head(2)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "7feaff6d-e41a-4bd7-b6fb-a63fc6900cca",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "df['predict'] = model.predict(df[model.feature_name()])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "id": "8a22f3e9-feff-438e-81e2-b5ceaa15ac48",
+   "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>C_TIME</th>\n",
+       "      <th>理论功率</th>\n",
+       "      <th>第1个设备轮毂风速</th>\n",
+       "      <th>实际功率</th>\n",
+       "      <th>实时环境数据</th>\n",
+       "      <th>预测功率</th>\n",
+       "      <th>NWP预测总辐射</th>\n",
+       "      <th>NWP-10米预测风速</th>\n",
+       "      <th>NWP-10米预测风向</th>\n",
+       "      <th>...</th>\n",
+       "      <th>NWP-中云量</th>\n",
+       "      <th>NWP-高云量</th>\n",
+       "      <th>NWP-总云量</th>\n",
+       "      <th>NWP-晴空总辐射</th>\n",
+       "      <th>NWP-法相直辐射</th>\n",
+       "      <th>NWP-总降水强度</th>\n",
+       "      <th>NWP-温度</th>\n",
+       "      <th>NWP-湿度</th>\n",
+       "      <th>NWP-气压</th>\n",
+       "      <th>predict</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>66ecc86f1075358d129a1d56</td>\n",
+       "      <td>2024-05-02 22:30:00</td>\n",
+       "      <td>130.05</td>\n",
+       "      <td>9.63</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>92.52</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.6477</td>\n",
+       "      <td>202.7945</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0173</td>\n",
+       "      <td>20.2918</td>\n",
+       "      <td>20.3927</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>14.0818</td>\n",
+       "      <td>23.4918</td>\n",
+       "      <td>892.3327</td>\n",
+       "      <td>77.728147</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>1</th>\n",
+       "      <td>66ecc86f1075358d129a1d57</td>\n",
+       "      <td>2024-05-02 22:45:00</td>\n",
+       "      <td>130.51</td>\n",
+       "      <td>9.72</td>\n",
+       "      <td>104.76</td>\n",
+       "      <td>-0.99</td>\n",
+       "      <td>93.24</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>3.9228</td>\n",
+       "      <td>202.6482</td>\n",
+       "      <td>...</td>\n",
+       "      <td>0.0191</td>\n",
+       "      <td>20.3009</td>\n",
+       "      <td>20.3864</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>0.0</td>\n",
+       "      <td>13.8264</td>\n",
+       "      <td>24.0436</td>\n",
+       "      <td>892.3809</td>\n",
+       "      <td>84.568199</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "<p>2 rows × 35 columns</p>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                        _id               C_TIME    理论功率  第1个设备轮毂风速    实际功率  \\\n",
+       "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  130.05       9.63  104.76   \n",
+       "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  130.51       9.72  104.76   \n",
+       "\n",
+       "   实时环境数据   预测功率  NWP预测总辐射  NWP-10米预测风速  NWP-10米预测风向  ...  NWP-中云量  NWP-高云量  \\\n",
+       "0   -0.99  92.52       0.0       3.6477     202.7945  ...   0.0173  20.2918   \n",
+       "1   -0.99  93.24       0.0       3.9228     202.6482  ...   0.0191  20.3009   \n",
+       "\n",
+       "   NWP-总云量  NWP-晴空总辐射  NWP-法相直辐射  NWP-总降水强度   NWP-温度   NWP-湿度    NWP-气压  \\\n",
+       "0  20.3927        0.0        0.0        0.0  14.0818  23.4918  892.3327   \n",
+       "1  20.3864        0.0        0.0        0.0  13.8264  24.0436  892.3809   \n",
+       "\n",
+       "     predict  \n",
+       "0  77.728147  \n",
+       "1  84.568199  \n",
+       "\n",
+       "[2 rows x 35 columns]"
+      ]
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df.head(2)"
+   ]
+  }
+ ],
+ "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
+}

+ 16 - 0
models_processing/model_training_lighgbm/.ipynb_checkpoints/Dockerfile-checkpoint

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "model_training_lightgbm.py"]
+# 执行 Python 脚本
+CMD []

+ 118 - 0
models_processing/model_training_lighgbm/.ipynb_checkpoints/model_training_lightgbm-checkpoint.py

@@ -0,0 +1,118 @@
+import lightgbm as lgb
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import pickle
+from sklearn.model_selection import train_test_split
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+
+app = Flask('model_training_lightgbm——service')
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_model_into_mongo(model_data,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    collection.insert_one(model_data)
+    print("model inserted successfully!")
+
+
+def build_model(df,args):
+    np.random.seed(42)
+    #lightgbm预测下
+    numerical_features,categorical_features,label,model_name,learning_rate,num_leaves,min_data_in_leaf = str_to_list(args['numerical_features']),str_to_list(args['categorical_features']),args['label'],args['model_name'],args['learning_rate'],args['num_leaves'],args['min_data_in_leaf']
+    features = numerical_features+categorical_features
+    print("features:************",features)
+    # 拆分数据为训练集和测试集
+    X_train, X_test, y_train, y_test = train_test_split(df[features], df[label], test_size=0.2, random_state=42)
+    # 创建LightGBM数据集
+    lgb_train = lgb.Dataset(X_train, y_train,categorical_feature=categorical_features)
+    lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
+    # 设置参数
+    params = {
+        'objective': 'regression',
+        'metric': 'rmse',
+        'boosting_type': 'gbdt',
+        'num_leaves': num_leaves,
+        'learning_rate': learning_rate,
+        'min_data_in_leaf': min_data_in_leaf,  # 叶子节点最小数据量
+    }
+    # 训练模型
+    print('Starting training...')
+    gbm = lgb.train(params,
+                    lgb_train,
+                    num_boost_round=500,
+                    valid_sets=[lgb_train, lgb_eval],
+                    )
+    
+    # 序列化模型
+    model_bytes = pickle.dumps(gbm)
+    model_data = {
+                'model_name': model_name,
+                'model': model_bytes,     #将模型字节流存入数据库
+        }
+    print('Training completed!')
+    return model_data
+
+def str_to_list(arg):
+    if arg == '':
+        return []
+    else:
+        return arg.split(',')
+
+@app.route('/model_training_lightgbm', methods=['POST'])
+def model_training_lightgbm():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        model = build_model(power_df,args)
+        insert_model_into_mongo(model,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+
+
+if __name__=="__main__":  
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("model_training_lightgbm log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10090)
+    print("server start!")

+ 7 - 0
models_processing/model_training_lighgbm/.ipynb_checkpoints/requirements-checkpoint.txt

@@ -0,0 +1,7 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+lightgbm==4.3.0
+scikit-learn==1.4.2
+Flask==3.0.3
+waitress==3.0.0

+ 179 - 0
models_processing/model_training_lighgbm/.ipynb_checkpoints/test-checkpoint.ipynb

@@ -0,0 +1,179 @@
+{
+ "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": [
+    "parser.add_argument('--numerical_features', type=str, required=True, help=\"数值型特征\") \n",
+    "parser.add_argument('--categorical_features', type=str, required=True, help=\"类别型特征\")\n",
+    "parser.add_argument('--learning_rate', type=float, required=True, help=\"学习率\")\n",
+    "parser.add_argument('--num_leaves', type=int, required=True, help=\"叶子节点数\")\n",
+    "parser.add_argument('--min_data_in_leaf', type=int, required=True, help=\"叶子节点最小数据量\")# mongodb://root:Jydl3377@192.168.1.33:27017\n",
+    "parser.add_argument('--mongodb_connection', type=str, required=True, help=\"mongodb连接\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_database', type=str, required=True, help=\"mongodb数据库名\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_read_table', type=str, required=True, help=\"mongodb数据库读取表\")# tmp_one"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 62,
+   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Output:\n",
+      "Program starts execution!\n",
+      "args: Namespace(numerical_features=['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向', 'NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向', 'NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向', 'NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向', 'NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射', 'NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'], categorical_features=[], label='实际功率', learning_rate=0.01, num_leaves=31, min_data_in_leaf=21, mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_records', mongodb_write_table='models', model_name='lightgbm_model')\n",
+      "df:************                         _id               C_TIME  ...   NWP-湿度    NWP-气压\n",
+      "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  ...  23.4918  892.3327\n",
+      "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  ...  24.0436  892.3809\n",
+      "\n",
+      "[2 rows x 34 columns]\n",
+      "Starting training...\n",
+      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000981 seconds.\n",
+      "You can set `force_col_wise=true` to remove the overhead.\n",
+      "[LightGBM] [Info] Total Bins 6885\n",
+      "[LightGBM] [Info] Number of data points in the train set: 7770, number of used features: 27\n",
+      "[LightGBM] [Info] Start training from score 47.616663\n",
+      "Training completed!\n",
+      "Collection 'models already exist, deleted successfully!\n",
+      "model inserted successfully!\n",
+      "Program execution ends!\n",
+      "\n",
+      "Error:\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "import subprocess\n",
+    "\n",
+    "# 构建命令\n",
+    "command = [\n",
+    "    \"python\", \"lightgbm_model.py\",\n",
+    "    \"--numerical_features\", ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', \n",
+    "                             'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', \n",
+    "                             'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', \n",
+    "                             'NWP-温度', 'NWP-湿度', 'NWP-气压']),\n",
+    "    \"--categorical_features\", ','.join([]),\n",
+    "    \"--label\", \"实际功率\",\n",
+    "    \"--learning_rate\", \"0.01\",\n",
+    "    \"--num_leaves\", \"31\",\n",
+    "    \"--min_data_in_leaf\", \"21\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_records\",\n",
+    "    \"--mongodb_write_table\", \"models\",\n",
+    "    \"--model_name\",\"lightgbm_model\"\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": null,
+   "id": "14a9feb4-5625-45d7-8e0f-6a8dea8c9f24",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run processing_limit_power_by_records   --timeBegin \"2024-05-01\"     --timeEnd \"2024-09-20\"   --station_code \"J00260\"     --col_time \"C_TIME\"    --mongondb_connection \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP_machines\"     --mongondb_write_table \"J00260NWP_records\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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
+}

+ 16 - 0
models_processing/model_training_lighgbm/Dockerfile

@@ -0,0 +1,16 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.9
+ENV LANG=en_US.UTF-8
+# 设置工作目录
+WORKDIR /app
+
+# 复制当前目录内容到工作目录
+COPY . /app
+
+# 安装依赖项(如果有)
+RUN set -ex \
+    && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
+# 设置 ENTRYPOINT 为 Python 脚本
+ENTRYPOINT ["python", "model_training_lightgbm.py"]
+# 执行 Python 脚本
+CMD []

+ 118 - 0
models_processing/model_training_lighgbm/model_training_lightgbm.py

@@ -0,0 +1,118 @@
+import lightgbm as lgb
+import argparse
+import pandas as pd 
+import numpy as np
+from pymongo import MongoClient
+import pickle
+from sklearn.model_selection import train_test_split
+from flask import Flask,request,jsonify
+from waitress import serve
+import time
+import logging
+import traceback
+
+app = Flask('model_training_lightgbm——service')
+def get_data_from_mongo(args):
+    mongodb_connection,mongodb_database,mongodb_read_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_read_table']
+    client = MongoClient(mongodb_connection)
+    # 选择数据库(如果数据库不存在,MongoDB 会自动创建)
+    db = client[mongodb_database]
+    collection = db[mongodb_read_table]  # 集合名称
+    data_from_db = collection.find()  # 这会返回一个游标(cursor)
+    # 将游标转换为列表,并创建 pandas DataFrame
+    df = pd.DataFrame(list(data_from_db))
+    client.close()
+    return df
+    
+
+def insert_model_into_mongo(model_data,args):
+    mongodb_connection,mongodb_database,mongodb_write_table = args['mongodb_connection'],args['mongodb_database'],args['mongodb_write_table']
+    client = MongoClient(mongodb_connection)
+    db = client[mongodb_database]
+    if mongodb_write_table in db.list_collection_names():
+        db[mongodb_write_table].drop()
+        print(f"Collection '{mongodb_write_table} already exist, deleted successfully!")
+    collection = db[mongodb_write_table]  # 集合名称
+    collection.insert_one(model_data)
+    print("model inserted successfully!")
+
+
+def build_model(df,args):
+    np.random.seed(42)
+    #lightgbm预测下
+    numerical_features,categorical_features,label,model_name,learning_rate,num_leaves,min_data_in_leaf = str_to_list(args['numerical_features']),str_to_list(args['categorical_features']),args['label'],args['model_name'],args['learning_rate'],args['num_leaves'],args['min_data_in_leaf']
+    features = numerical_features+categorical_features
+    print("features:************",features)
+    # 拆分数据为训练集和测试集
+    X_train, X_test, y_train, y_test = train_test_split(df[features], df[label], test_size=0.2, random_state=42)
+    # 创建LightGBM数据集
+    lgb_train = lgb.Dataset(X_train, y_train,categorical_feature=categorical_features)
+    lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
+    # 设置参数
+    params = {
+        'objective': 'regression',
+        'metric': 'rmse',
+        'boosting_type': 'gbdt',
+        'num_leaves': num_leaves,
+        'learning_rate': learning_rate,
+        'min_data_in_leaf': min_data_in_leaf,  # 叶子节点最小数据量
+    }
+    # 训练模型
+    print('Starting training...')
+    gbm = lgb.train(params,
+                    lgb_train,
+                    num_boost_round=500,
+                    valid_sets=[lgb_train, lgb_eval],
+                    )
+    
+    # 序列化模型
+    model_bytes = pickle.dumps(gbm)
+    model_data = {
+                'model_name': model_name,
+                'model': model_bytes,     #将模型字节流存入数据库
+        }
+    print('Training completed!')
+    return model_data
+
+def str_to_list(arg):
+    if arg == '':
+        return []
+    else:
+        return arg.split(',')
+
+@app.route('/model_training_lightgbm', methods=['POST'])
+def model_training_lightgbm():
+    # 获取程序开始时间  
+    start_time = time.time()  
+    result = {}
+    success = 0
+    print("Program starts execution!")
+    try:
+        args = request.values.to_dict()
+        print('args',args)
+        logger.info(args)
+        power_df = get_data_from_mongo(args)
+        model = build_model(power_df,args)
+        insert_model_into_mongo(model,args)
+        success = 1
+    except Exception as e:
+        my_exception = traceback.format_exc()
+        my_exception.replace("\n","\t")
+        result['msg'] = my_exception
+    end_time = time.time() 
+   
+    result['success'] = success
+    result['args'] = args
+    result['start_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
+    result['end_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
+    print("Program execution ends!")
+    return result
+
+
+if __name__=="__main__":  
+    print("Program starts execution!")
+    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+    logger = logging.getLogger("model_training_lightgbm log")
+    from waitress import serve
+    serve(app, host="0.0.0.0", port=10090)
+    print("server start!")

+ 7 - 0
models_processing/model_training_lighgbm/requirements.txt

@@ -0,0 +1,7 @@
+pymongo==4.9.1
+pandas==2.1.4
+numpy==1.26.4
+lightgbm==4.3.0
+scikit-learn==1.4.2
+Flask==3.0.3
+waitress==3.0.0

+ 279 - 0
models_processing/model_training_lighgbm/test.ipynb

@@ -0,0 +1,279 @@
+{
+ "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": [
+    " %run model_training_lightgbm.py"
+   ]
+  },
+  {
+   "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": [
+    "parser.add_argument('--numerical_features', type=str, required=True, help=\"数值型特征\") \n",
+    "parser.add_argument('--categorical_features', type=str, required=True, help=\"类别型特征\")\n",
+    "parser.add_argument('--learning_rate', type=float, required=True, help=\"学习率\")\n",
+    "parser.add_argument('--num_leaves', type=int, required=True, help=\"叶子节点数\")\n",
+    "parser.add_argument('--min_data_in_leaf', type=int, required=True, help=\"叶子节点最小数据量\")# mongodb://root:Jydl3377@192.168.1.33:27017\n",
+    "parser.add_argument('--mongodb_connection', type=str, required=True, help=\"mongodb连接\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_database', type=str, required=True, help=\"mongodb数据库名\")# algorithm_platform\n",
+    "parser.add_argument('--mongodb_read_table', type=str, required=True, help=\"mongodb数据库读取表\")# tmp_one"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 62,
+   "id": "acc6aa2a-0f1d-43f3-985d-cd37c4a5ac6e",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Output:\n",
+      "Program starts execution!\n",
+      "args: Namespace(numerical_features=['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向', 'NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向', 'NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向', 'NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向', 'NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射', 'NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'], categorical_features=[], label='实际功率', learning_rate=0.01, num_leaves=31, min_data_in_leaf=21, mongodb_connection='mongodb://root:Jydl3377@192.168.1.33:27017', mongodb_database='algorithm_platform', mongodb_read_table='J00260NWP_records', mongodb_write_table='models', model_name='lightgbm_model')\n",
+      "df:************                         _id               C_TIME  ...   NWP-湿度    NWP-气压\n",
+      "0  66ecc86f1075358d129a1d56  2024-05-02 22:30:00  ...  23.4918  892.3327\n",
+      "1  66ecc86f1075358d129a1d57  2024-05-02 22:45:00  ...  24.0436  892.3809\n",
+      "\n",
+      "[2 rows x 34 columns]\n",
+      "Starting training...\n",
+      "[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000981 seconds.\n",
+      "You can set `force_col_wise=true` to remove the overhead.\n",
+      "[LightGBM] [Info] Total Bins 6885\n",
+      "[LightGBM] [Info] Number of data points in the train set: 7770, number of used features: 27\n",
+      "[LightGBM] [Info] Start training from score 47.616663\n",
+      "Training completed!\n",
+      "Collection 'models already exist, deleted successfully!\n",
+      "model inserted successfully!\n",
+      "Program execution ends!\n",
+      "\n",
+      "Error:\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "import subprocess\n",
+    "\n",
+    "# 构建命令\n",
+    "command = [\n",
+    "    \"python\", \"lightgbm_model.py\",\n",
+    "    \"--numerical_features\", ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', \n",
+    "                             'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', \n",
+    "                             'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', \n",
+    "                             'NWP-温度', 'NWP-湿度', 'NWP-气压']),\n",
+    "    \"--categorical_features\", ','.join([]),\n",
+    "    \"--label\", \"实际功率\",\n",
+    "    \"--learning_rate\", \"0.01\",\n",
+    "    \"--num_leaves\", \"31\",\n",
+    "    \"--min_data_in_leaf\", \"21\",\n",
+    "    \"--mongodb_connection\", \"mongodb://root:Jydl3377@192.168.1.33:27017\",\n",
+    "    \"--mongodb_database\", \"algorithm_platform\",\n",
+    "    \"--mongodb_read_table\", \"J00260NWP_records\",\n",
+    "    \"--mongodb_write_table\", \"models\",\n",
+    "    \"--model_name\",\"lightgbm_model\"\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": null,
+   "id": "14a9feb4-5625-45d7-8e0f-6a8dea8c9f24",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run lightgbm_model.py   --numerical_features \"2024-05-01\"     --categorical_features \"2024-09-20\"   --label \"J00260\"     --learning_rate \"C_TIME\"    --num_leaves \"mongodb://root:Jydl3377@192.168.1.33:27017\"     --mongondb_database \"algorithm_platform\"     --mongondb_read_table \"J00260NWP_machines\"     --mongondb_write_table \"J00260NWP_records\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "c0d791f8-12d8-4ab9-b561-b474e2a739f0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "docker run lightgbm_model.py --numerical_features ','.join(['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'])  --categorical_features  ','.join([])  --label  \"实际功率\" --learning_rate  \"0.01\" --num_leaves \"31\"  --min_data_in_leaf  \"21\"  --mongodb_connection  \"mongodb://root:Jydl3377@192.168.1.33:27017\" --mongodb_database  \"algorithm_platform\" --mongodb_read_table  \"J00260NWP_records\" --mongodb_write_table  \"models\" --model_name \"lightgbm_model\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "id": "8bdd9bd2-4373-4465-b20a-de574fb29436",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 13:52:11,278 - waitress - INFO - Serving on http://0.0.0.0:10090\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 13:52:13,894 - model_training_lightgbm log - INFO - {'numerical_features': \"'NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'\", 'categorical_features': \"''\", 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'numerical_features': \"'NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向','NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向','NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向','NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向','NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射','NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压'\", 'categorical_features': \"''\", 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n",
+      "features:************ [\"'NWP预测总辐射'\", \" 'NWP-10米预测风速'\", \" 'NWP-10米预测风向'\", \" 'NWP-30米预测风速'\", \" 'NWP-30米预测风向'\", \"'NWP-50米预测风速'\", \" 'NWP-50米预测风向'\", \" 'NWP-70米预测风速'\", \" 'NWP-70米预测风向'\", \"'NWP-90米预测风速'\", \" 'NWP-90米预测风向'\", \" 'NWP-110米预测风速'\", \" 'NWP-110米预测风向'\", \"'NWP-150米预测风速'\", \" 'NWP-150米预测风向'\", \" 'NWP-170米预测风速'\", \" 'NWP-170米预测风向'\", \"'NWP-低云量'\", \" 'NWP-中云量'\", \" 'NWP-高云量'\", \" 'NWP-总云量'\", \" 'NWP-晴空总辐射'\", \" 'NWP-法相直辐射'\", \"'NWP-总降水强度'\", \" 'NWP-温度'\", \" 'NWP-湿度'\", \" 'NWP-气压'\", \"''\"]\n",
+      "Program execution ends!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 13:52:57,749 - model_training_lightgbm log - INFO - {'numerical_features': 'NWP预测总辐射, NWP-10米预测风速, NWP-10米预测风向, NWP-30米预测风速, NWP-30米预测风向,NWP-50米预测风速, NWP-50米预测风向, NWP-70米预测风速, NWP-70米预测风向,NWP-90米预测风速, NWP-90米预测风向, NWP-110米预测风速, NWP-110米预测风向,NWP-150米预测风速, NWP-150米预测风向, NWP-170米预测风速, NWP-170米预测风向,NWP-低云量, NWP-中云量, NWP-高云量, NWP-总云量, NWP-晴空总辐射, NWP-法相直辐射,NWP-总降水强度, NWP-温度, NWP-湿度, NWP-气压', 'categorical_features': \"''\", 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'numerical_features': 'NWP预测总辐射, NWP-10米预测风速, NWP-10米预测风向, NWP-30米预测风速, NWP-30米预测风向,NWP-50米预测风速, NWP-50米预测风向, NWP-70米预测风速, NWP-70米预测风向,NWP-90米预测风速, NWP-90米预测风向, NWP-110米预测风速, NWP-110米预测风向,NWP-150米预测风速, NWP-150米预测风向, NWP-170米预测风速, NWP-170米预测风向,NWP-低云量, NWP-中云量, NWP-高云量, NWP-总云量, NWP-晴空总辐射, NWP-法相直辐射,NWP-总降水强度, NWP-温度, NWP-湿度, NWP-气压', 'categorical_features': \"''\", 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n",
+      "features:************ ['NWP预测总辐射', ' NWP-10米预测风速', ' NWP-10米预测风向', ' NWP-30米预测风速', ' NWP-30米预测风向', 'NWP-50米预测风速', ' NWP-50米预测风向', ' NWP-70米预测风速', ' NWP-70米预测风向', 'NWP-90米预测风速', ' NWP-90米预测风向', ' NWP-110米预测风速', ' NWP-110米预测风向', 'NWP-150米预测风速', ' NWP-150米预测风向', ' NWP-170米预测风速', ' NWP-170米预测风向', 'NWP-低云量', ' NWP-中云量', ' NWP-高云量', ' NWP-总云量', ' NWP-晴空总辐射', ' NWP-法相直辐射', 'NWP-总降水强度', ' NWP-温度', ' NWP-湿度', ' NWP-气压', \"''\"]\n",
+      "Program execution ends!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 13:53:10,595 - model_training_lightgbm log - INFO - {'numerical_features': 'NWP预测总辐射, NWP-10米预测风速, NWP-10米预测风向, NWP-30米预测风速, NWP-30米预测风向,NWP-50米预测风速, NWP-50米预测风向, NWP-70米预测风速, NWP-70米预测风向,NWP-90米预测风速, NWP-90米预测风向, NWP-110米预测风速, NWP-110米预测风向,NWP-150米预测风速, NWP-150米预测风向, NWP-170米预测风速, NWP-170米预测风向,NWP-低云量, NWP-中云量, NWP-高云量, NWP-总云量, NWP-晴空总辐射, NWP-法相直辐射,NWP-总降水强度, NWP-温度, NWP-湿度, NWP-气压', 'categorical_features': '', 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'numerical_features': 'NWP预测总辐射, NWP-10米预测风速, NWP-10米预测风向, NWP-30米预测风速, NWP-30米预测风向,NWP-50米预测风速, NWP-50米预测风向, NWP-70米预测风速, NWP-70米预测风向,NWP-90米预测风速, NWP-90米预测风向, NWP-110米预测风速, NWP-110米预测风向,NWP-150米预测风速, NWP-150米预测风向, NWP-170米预测风速, NWP-170米预测风向,NWP-低云量, NWP-中云量, NWP-高云量, NWP-总云量, NWP-晴空总辐射, NWP-法相直辐射,NWP-总降水强度, NWP-温度, NWP-湿度, NWP-气压', 'categorical_features': '', 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n",
+      "features:************ ['NWP预测总辐射', ' NWP-10米预测风速', ' NWP-10米预测风向', ' NWP-30米预测风速', ' NWP-30米预测风向', 'NWP-50米预测风速', ' NWP-50米预测风向', ' NWP-70米预测风速', ' NWP-70米预测风向', 'NWP-90米预测风速', ' NWP-90米预测风向', ' NWP-110米预测风速', ' NWP-110米预测风向', 'NWP-150米预测风速', ' NWP-150米预测风向', ' NWP-170米预测风速', ' NWP-170米预测风向', 'NWP-低云量', ' NWP-中云量', ' NWP-高云量', ' NWP-总云量', ' NWP-晴空总辐射', ' NWP-法相直辐射', 'NWP-总降水强度', ' NWP-温度', ' NWP-湿度', ' NWP-气压']\n",
+      "Program execution ends!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2024-09-26 13:54:25,780 - model_training_lightgbm log - INFO - {'numerical_features': 'NWP预测总辐射,NWP-10米预测风速,NWP-10米预测风向,NWP-30米预测风速,NWP-30米预测风向,NWP-50米预测风速,NWP-50米预测风向,NWP-70米预测风速,NWP-70米预测风向,NWP-90米预测风速,NWP-90米预测风向,NWP-110米预测风速,NWP-110米预测风向,NWP-150米预测风速,NWP-150米预测风向,NWP-170米预测风速,NWP-170米预测风向,NWP-低云量,NWP-中云量,NWP-高云量,NWP-总云量,NWP-晴空总辐射,NWP-法相直辐射,NWP-总降水强度,NWP-温度,NWP-湿度,NWP-气压', 'categorical_features': '', 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Program starts execution!\n",
+      "args {'numerical_features': 'NWP预测总辐射,NWP-10米预测风速,NWP-10米预测风向,NWP-30米预测风速,NWP-30米预测风向,NWP-50米预测风速,NWP-50米预测风向,NWP-70米预测风速,NWP-70米预测风向,NWP-90米预测风速,NWP-90米预测风向,NWP-110米预测风速,NWP-110米预测风向,NWP-150米预测风速,NWP-150米预测风向,NWP-170米预测风速,NWP-170米预测风向,NWP-低云量,NWP-中云量,NWP-高云量,NWP-总云量,NWP-晴空总辐射,NWP-法相直辐射,NWP-总降水强度,NWP-温度,NWP-湿度,NWP-气压', 'categorical_features': '', 'label': '实际功率', 'learning_rate': '0.01', 'num_leaves': '31', 'min_data_in_leaf': '21', 'mongodb_connection': 'mongodb://root:Jydl3377@192.168.1.33:27017', 'mongodb_database': 'algorithm_platform', 'mongodb_read_table': 'J00260NWP_records', 'mongodb_write_table': 'models', 'model_name': 'lightgbm_model'}\n",
+      "features:************ ['NWP预测总辐射', 'NWP-10米预测风速', 'NWP-10米预测风向', 'NWP-30米预测风速', 'NWP-30米预测风向', 'NWP-50米预测风速', 'NWP-50米预测风向', 'NWP-70米预测风速', 'NWP-70米预测风向', 'NWP-90米预测风速', 'NWP-90米预测风向', 'NWP-110米预测风速', 'NWP-110米预测风向', 'NWP-150米预测风速', 'NWP-150米预测风向', 'NWP-170米预测风速', 'NWP-170米预测风向', 'NWP-低云量', 'NWP-中云量', 'NWP-高云量', 'NWP-总云量', 'NWP-晴空总辐射', 'NWP-法相直辐射', 'NWP-总降水强度', 'NWP-温度', 'NWP-湿度', 'NWP-气压']\n",
+      "Starting training...\n",
+      "Training completed!\n",
+      "Collection 'models already exist, deleted successfully!\n",
+      "model inserted successfully!\n",
+      "Program execution ends!\n",
+      "server start!\n"
+     ]
+    }
+   ],
+   "source": [
+    " %run model_training_lightgbm.py"
+   ]
+  }
+ ],
+ "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
+}

Some files were not shown because too many files changed in this diff