diff --git a/aisenzhecode/石油苯/日度价格预测_最佳模型.pkl b/aisenzhecode/石油苯/日度价格预测_最佳模型.pkl index b25f3a2..e816e1b 100644 Binary files a/aisenzhecode/石油苯/日度价格预测_最佳模型.pkl and b/aisenzhecode/石油苯/日度价格预测_最佳模型.pkl differ diff --git a/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb b/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb index 8b2538c..dc1c8eb 100644 --- a/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb +++ b/aisenzhecode/石油苯/纯苯价格预测-自定义日期ytj.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -28,6 +28,14 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "获取到的数据项ID['数据项编码', 'C01100047|STRIKE_PRICE', 'Brentspj', '913716251671540959|EXCHANGE_RATE', 'C01100010|LIST_PRICE01', '250326561|STRIKE_PRICE', 'C01100047|LIST_PRICE', 'C01100047|LIST_PRICE-1', 'C01100047|LIST_PRICE-01', 'OIL_CHEM|guonei|6097|PRICE', '91370500674526498A|C01100008|STRIKE_PRICE', '91370783724809024G|BEN|PRICE', '91370500737223620X|BEN|PRICE', '91370503706169019D|BEN|PRICE', '91370503164840647R|BEN|PRICE', 'C01100047|TURNOVER', '913705221649223519|C01100047|EXW', 'C01100047|CAPACITY']\n", + "获取到的数据项ID['C01100047|STRIKE_PRICE', 'Brentspj', '913716251671540959|EXCHANGE_RATE', 'C01100010|LIST_PRICE01', '250326561|STRIKE_PRICE', 'C01100047|LIST_PRICE', 'C01100047|LIST_PRICE-1', 'C01100047|LIST_PRICE-01', 'OIL_CHEM|guonei|6097|PRICE', '91370500674526498A|C01100008|STRIKE_PRICE', '91370783724809024G|BEN|PRICE', '91370500737223620X|BEN|PRICE', '91370503706169019D|BEN|PRICE', '91370503164840647R|BEN|PRICE', 'C01100047|TURNOVER', '913705221649223519|C01100047|EXW', 'C01100047|CAPACITY']\n" + ] } ], "source": [ @@ -150,7 +158,7 @@ "def get_data_value(token, dataItemNoList,date):\n", " search_data = {\n", " \"data\": {\n", - " \"date\": get_cur_time(date)[0],\n", + " \"date\": getNow(date)[0],\n", " \"dataItemNoList\": dataItemNoList\n", " },\n", " \"funcModule\": \"数据项\",\n", @@ -188,6 +196,43 @@ " workbook.save(get_cur_time(date)[0] + '.xls')\n", "\n", "\n", + "\n", + "def getNow(date='', offset=0):\n", + " \"\"\"生成指定日期的两种格式字符串\n", + " Args:\n", + " date: 支持多种输入类型:\n", + " - datetime对象\n", + " - 字符串格式(支持'%Y-%m-%d'和'%Y%m%d')\n", + " - 空字符串表示当前日期\n", + " offset: 日期偏移天数\n", + " Returns:\n", + " tuple: (紧凑日期字符串, 标准日期字符串)\n", + " \"\"\"\n", + " # 日期解析逻辑\n", + " if isinstance(date, datetime):\n", + " now = date\n", + " else:\n", + " now = datetime.now()\n", + " if date:\n", + " # 尝试多种日期格式解析\n", + " for fmt in ('%Y-%m-%d', '%Y%m%d', '%Y/%m/%d'):\n", + " try:\n", + " now = datetime.strptime(str(date), fmt)\n", + " break\n", + " except ValueError:\n", + " continue\n", + " else:\n", + " raise ValueError(f\"无法解析的日期格式: {date}\")\n", + "\n", + " # 应用日期偏移\n", + " now = now - timedelta(days=offset)\n", + " \n", + " # 统一格式化输出\n", + " date_str = now.strftime(\"%Y-%m-%d\")\n", + " compact_date = date_str.replace(\"-\", \"\")\n", + " return compact_date, date_str\n", + "\n", + "\n", "def get_cur_time(date=''):\n", " if date == '':\n", " now = datetime.now()\n", @@ -495,7 +540,9 @@ " # two_cols.append(row_data[1])\n", "\n", " row_data = sheet.row_values(1)\n", - " one_cols = row_data\n", + " print(f'获取到的数据项ID{row_data}')\n", + " one_cols = row_data[1:]\n", + " print(f'获取到的数据项ID{one_cols}')\n", "\n", " # 关闭 XLS 文件\n", " # workbook.close()\n", @@ -503,20 +550,21 @@ "\n", "\n", "\n", - "def start(date,token=None,token_push=None):\n", + "def start(date=None,token=None,token_push=None):\n", " read_xls_data()\n", - "\n", + " if date == None:\n", + " date = getNow()[0]\n", " if token == None:\n", " token = get_head_auth()\n", " token_push = get_head_push_auth()\n", "\n", - " datas = get_data_value(token, one_cols[1:],date)\n", + " datas = get_data_value(token, one_cols,date)\n", " if not datas:\n", " print(\"今天没有新数据\")\n", " return\n", "\n", " # data_list = [two_cols, one_cols]\n", - " append_rows = [get_cur_time(date)[1]]\n", + " append_rows = [getNow()[1]]\n", " dataItemNo_dataValue = {}\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", @@ -525,7 +573,7 @@ " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " \n", - " for value in one_cols[1:]:\n", + " for value in one_cols:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", @@ -542,20 +590,21 @@ " # write_xls(data_list)\n", "\n", "\n", - "def start_1(date):\n", + "def start_1(date=None):\n", " read_xls_data()\n", - "\n", + " if date == None:\n", + " date = getNow(offset=1)[0]\n", " token = get_head_auth()\n", " if not token:\n", " return\n", " \n", "\n", - " datas = get_data_value(token, one_cols[1:])\n", + " datas = get_data_value(token, one_cols,date=date)\n", "# if not datas:\n", "# return\n", "\n", " # data_list = [two_cols, one_cols]\n", - " append_rows = [get_cur_time(date)[1]]\n", + " append_rows = [getNow(offset=1)[1]]\n", " dataItemNo_dataValue = {}\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", @@ -564,7 +613,7 @@ " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " \n", - " for value in one_cols[1:]:\n", + " for value in one_cols:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", @@ -794,9 +843,6 @@ " save_queryDataListItemNos_xls(data_df,dataItemNoList)\n", "\n", "\n", - "\n", - "\n", - "\n", "if __name__ == \"__main__\":\n", "\n", " # 每天定时12点运行\n", @@ -810,6 +856,7 @@ " # 判断当前时间是否为执行任务的时间点\n", " if current_time == \"09:15:00\":\n", " print(\"执行定时任务\")\n", + " queryDataListItemNos()\n", " start()\n", "\n", " # 休眠1秒钟,避免过多占用CPU资源\n", @@ -828,73 +875,9 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 16, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "20250408\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_31052\\2446979738.py:725: DeprecationWarning:\n", - "\n", - "The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n", - "\n", - "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_31052\\2446979738.py:279: UserWarning:\n", - "\n", - "The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n", - "\n", - "d:\\ProgramData\\anaconda3\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:631: ConvergenceWarning:\n", - "\n", - "Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 6.083e+05, tolerance: 4.378e+04\n", - "\n", - "d:\\ProgramData\\anaconda3\\Lib\\site-packages\\IPython\\core\\magics\\pylab.py:162: UserWarning:\n", - "\n", - "pylab import has clobbered these variables: ['plot', 'datetime', '__version__', 'random']\n", - "`%matplotlib` prevents importing * from pylab and numpy\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Using matplotlib backend: QtAgg\n", - "%pylab is deprecated, use %matplotlib inline and import the required libraries.\n", - "Populating the interactive namespace from numpy and matplotlib\n", - "Fitting 3 folds for each of 180 candidates, totalling 540 fits\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_31052\\2446979738.py:232: UserWarning:\n", - "\n", - "The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.\n", - "\n", - "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_31052\\2446979738.py:262: FutureWarning:\n", - "\n", - "Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Date\n", - "2025-04-08 6302.519043\n", - "Name: 日度预测价格, dtype: float32\n" - ] - } - ], + "outputs": [], "source": [ "# # 自定义日期执行预测\n", "\n", diff --git a/aisenzhecode/石油苯/纯苯数据项.xls b/aisenzhecode/石油苯/纯苯数据项.xls index e567883..9bc24cd 100644 Binary files a/aisenzhecode/石油苯/纯苯数据项.xls and b/aisenzhecode/石油苯/纯苯数据项.xls differ