液化气、石油苯逻辑更改

This commit is contained in:
workpc 2025-03-28 14:43:24 +08:00
parent 1e75070ca3
commit fcb657e407
4 changed files with 305 additions and 37 deletions

View File

@ -5,37 +5,36 @@
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARNING:tensorflow:From C:\\Users\\EDY\\AppData\\Roaming\\Python\\Python311\\site-packages\\keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n",
"\n"
]
},
{
"data": {
"text/html": [
" <script type=\"text/javascript\">\n",
" window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
" if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
" if (typeof require !== 'undefined') {\n",
" require.undef(\"plotly\");\n",
" requirejs.config({\n",
" paths: {\n",
" 'plotly': ['https://cdn.plot.ly/plotly-2.12.1.min']\n",
" }\n",
" });\n",
" require(['plotly'], function(Plotly) {\n",
" window._Plotly = Plotly;\n",
" });\n",
" }\n",
" </script>\n",
" <script type=\"module\">import \"https://cdn.plot.ly/plotly-3.0.1.min\"</script>\n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"获取的token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcGlfZGV2IiwidGgiOiI4YTQ1NzdkYmQ5MTk2NzU3NThkNTc5OTlhMWU4OTFmZSIsImx0IjoiYXBpIiwiaXNzIjoiIiwidG0iOiJQQyIsImV4cCI6MTc0MzEwNTAxMCwianRpIjoiN2QwMjE1N2Q0NzIwNDZjMjk3NTE4ODMzNjA3NzY3OTQifQ.F2QXnRxR_YUmQ8w2GIWkvjy0xLMTZg93rJ-wHkuyIzw\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\h5218\\AppData\\Local\\Temp\\ipykernel_31728\\3153608672.py:885: 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"
]
}
],
"source": [
@ -49,6 +48,7 @@
"login_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n",
"search_url = \"http://10.200.32.39/jingbo-api/api/warehouse/dwDataItem/queryByItemNos\"\n",
"# search_url = \"http://10.200.32.39/jingbo-api/api/warehouse/dwDataItem/queryDataListItemNos\" \n",
"queryDataListItemNos_url = \"http://10.200.32.39/jingbo-api//api/warehouse/dwDataItem/queryDataListItemNos\"\n",
"\n",
"\n",
"login_push_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n",
@ -835,12 +835,146 @@
"\n",
" # 保存新的xls文件\n",
" new_workbook.save(\"液化气数据.xls\")\n",
"\n"
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"def get_queryDataListItemNos_value(token, url, dataItemNoList, dateStart, dateEnd):\n",
"\n",
" search_data = {\n",
" \"funcModule\": \"数据项\",\n",
" \"funcOperation\": \"查询\",\n",
" \"data\": {\n",
" \"dateStart\": dateStart,\n",
" \"dateEnd\": dateEnd,\n",
" \"dataItemNoList\": dataItemNoList # 数据项编码,代表 brent最低价和最高价\n",
" }\n",
" }\n",
"\n",
" headers = {\"Authorization\": token}\n",
" search_res = requests.post(url=url, headers=headers, json=search_data, timeout=(3, 5))\n",
" search_value = json.loads(search_res.text)[\"data\"]\n",
" if search_value:\n",
" return search_value\n",
" else:\n",
" return None\n",
"\n",
"\n",
"\n",
"def save_queryDataListItemNos_xls(data_df,dataItemNoList):\n",
"\n",
" current_year_month = datetime.now().strftime('%Y-%m')\n",
" grouped = data_df.groupby(\"dataDate\")\n",
"\n",
" # 打开xls文件\n",
" workbook = xlrd.open_workbook('液化气数据.xls')\n",
"\n",
" # 获取所有sheet的个数\n",
" sheet_count = len(workbook.sheet_names())\n",
"\n",
" # 获取所有sheet的名称\n",
" sheet_names = workbook.sheet_names()\n",
"\n",
" new_workbook = xlwt.Workbook()\n",
" for i in range(sheet_count):\n",
" # 获取当前sheet\n",
" sheet = workbook.sheet_by_index(i)\n",
"\n",
" # 获取sheet的行数和列数\n",
" row_count = sheet.nrows\n",
" col_count = sheet.ncols\n",
" # 获取原有数据\n",
" data = []\n",
" for row in range(row_count):\n",
" row_data = []\n",
" for col in range(col_count):\n",
" row_data.append(sheet.cell_value(row, col))\n",
" data.append(row_data)\n",
"\n",
" # 创建xlwt的Workbook对象\n",
" # 创建sheet\n",
" new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
"\n",
"\n",
" current_year_month_row = 0\n",
" # 将原有的数据写入新的sheet\n",
" for row in range(row_count):\n",
" for col in range(col_count):\n",
" col0 = data[row][0]\n",
" # print(\"col0\",col0[:7])\n",
" if col0[:7] == current_year_month:\n",
" current_year_month_row += 1\n",
" break\n",
" new_sheet.write(row, col, data[row][col])\n",
"\n",
"\n",
" # print(\"current_year_month_row\",current_year_month_row)\n",
" if i == 0:\n",
" rowFlag = 0\n",
" # 查看每组数据\n",
" for date, group in grouped:\n",
" new_sheet.write(row_count + rowFlag - current_year_month_row, 0, date)\n",
" for j in range(len(dataItemNoList)):\n",
" dataItemNo = dataItemNoList[j]\n",
"\n",
" # for dataItemNo in dataItemNoList:\n",
" if group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values and (not str(group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values[0]) == 'nan'):\n",
" # if group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values:\n",
"\n",
" new_sheet.write(row_count + rowFlag - current_year_month_row, j + 1, group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values[0])\n",
"\n",
" rowFlag += 1\n",
"\n",
"\n",
" # 保存新的xls文件\n",
" new_workbook.save(\"液化气数据.xls\")\n",
"\n",
"\n",
"\n",
"\n",
"def queryDataListItemNos():\n",
" df = pd.read_excel('液化气数据.xls')\n",
" dataItemNoList = df.iloc[0].tolist()[1:]\n",
"\n",
" token = get_head_auth()\n",
" if not token:\n",
" return\n",
"\n",
" # 获取当前日期\n",
" current_date = datetime.now()\n",
"\n",
" # 获取当月1日\n",
" first_day_of_month = current_date.replace(day=1)\n",
"\n",
" # 格式化为 YYYYMMDD 格式\n",
" dateEnd = current_date.strftime('%Y%m%d')\n",
" dateStart = first_day_of_month.strftime('%Y%m%d')\n",
"\n",
" search_value = get_queryDataListItemNos_value(token, queryDataListItemNos_url, dataItemNoList, dateStart, dateEnd)\n",
"\n",
"\n",
" data_df = pd.DataFrame(search_value)\n",
"\n",
" data_df[\"dataDate\"] = pd.to_datetime(data_df[\"dataDate\"])\n",
" data_df[\"dataDate\"] = data_df[\"dataDate\"].dt.strftime('%Y-%m-%d')\n",
" save_queryDataListItemNos_xls(data_df,dataItemNoList)\n",
"\n",
"\n",
"\n",
"\n",
"# if __name__ == \"__main__\":\n",
"\n",
"# # 获取当月的数据写入到指定文件\n",
"# queryDataListItemNos()\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"scrolled": true
},
@ -862,6 +996,11 @@
"# current_time_1 = time.strftime(\"%H:%M:%S\", time.localtime())\n",
"# # print(current_time_1)\n",
"\n",
"\n",
" # 获取当月的数据写入到指定文件\n",
" # queryDataListItemNos()\n",
"\n",
"\n",
"# # 判断当前时间是否为执行任务的时间点\n",
"# if current_time == \"09:15:00\":\n",
"# print(\"执行定时任务\")\n",
@ -927,7 +1066,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -941,7 +1080,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.12.4"
}
},
"nbformat": 4,

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
@ -11,23 +11,23 @@
" <script type=\"text/javascript\">\n",
" window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
" if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
" if (typeof require !== 'undefined') {\n",
" require.undef(\"plotly\");\n",
" requirejs.config({\n",
" paths: {\n",
" 'plotly': ['https://cdn.plot.ly/plotly-2.12.1.min']\n",
" }\n",
" });\n",
" require(['plotly'], function(Plotly) {\n",
" window._Plotly = Plotly;\n",
" });\n",
" }\n",
" </script>\n",
" <script type=\"module\">import \"https://cdn.plot.ly/plotly-3.0.1.min\"</script>\n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\h5218\\AppData\\Local\\Temp\\ipykernel_35936\\3451377547.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"
]
}
],
"source": [
@ -43,6 +43,7 @@
"\n",
"login_push_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n",
"upload_url = \"http://10.200.32.39/jingbo-api/api/dw/dataValue/pushDataValueList\"\n",
"queryDataListItemNos_url = \"http://10.200.32.39/jingbo-api//api/warehouse/dwDataItem/queryDataListItemNos\"\n",
"\n",
"login_data = {\n",
" \"data\": {\n",
@ -674,7 +675,132 @@
" new_workbook.save(\"纯苯数据项.xls\")\n",
"\n",
"\n",
"\n",
"\n",
"def get_queryDataListItemNos_value(token, url, dataItemNoList, dateStart, dateEnd):\n",
"\n",
" search_data = {\n",
" \"funcModule\": \"数据项\",\n",
" \"funcOperation\": \"查询\",\n",
" \"data\": {\n",
" \"dateStart\": dateStart,\n",
" \"dateEnd\": dateEnd,\n",
" \"dataItemNoList\": dataItemNoList # 数据项编码,代表 brent最低价和最高价\n",
" }\n",
" }\n",
"\n",
" headers = {\"Authorization\": token}\n",
" search_res = requests.post(url=url, headers=headers, json=search_data, timeout=(3, 5))\n",
" search_value = json.loads(search_res.text)[\"data\"]\n",
" if search_value:\n",
" return search_value\n",
" else:\n",
" return None\n",
"\n",
"\n",
"\n",
"def save_queryDataListItemNos_xls(data_df,dataItemNoList):\n",
"\n",
" current_year_month = datetime.datetime.now().strftime('%Y-%m')\n",
" grouped = data_df.groupby(\"dataDate\")\n",
"\n",
" # 打开xls文件\n",
" workbook = xlrd.open_workbook('纯苯数据项.xls')\n",
"\n",
" # 获取所有sheet的个数\n",
" sheet_count = len(workbook.sheet_names())\n",
"\n",
" # 获取所有sheet的名称\n",
" sheet_names = workbook.sheet_names()\n",
"\n",
" new_workbook = xlwt.Workbook()\n",
" for i in range(sheet_count):\n",
" # 获取当前sheet\n",
" sheet = workbook.sheet_by_index(i)\n",
"\n",
" # 获取sheet的行数和列数\n",
" row_count = sheet.nrows\n",
" col_count = sheet.ncols\n",
" # 获取原有数据\n",
" data = []\n",
" for row in range(row_count):\n",
" row_data = []\n",
" for col in range(col_count):\n",
" row_data.append(sheet.cell_value(row, col))\n",
" data.append(row_data)\n",
"\n",
" # 创建xlwt的Workbook对象\n",
" # 创建sheet\n",
" new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
"\n",
"\n",
" current_year_month_row = 0\n",
" # 将原有的数据写入新的sheet\n",
" for row in range(row_count):\n",
" for col in range(col_count):\n",
" col0 = data[row][0]\n",
" # print(\"col0\",col0[:7])\n",
" if col0[:7] == current_year_month:\n",
" current_year_month_row += 1\n",
" break\n",
" new_sheet.write(row, col, data[row][col])\n",
"\n",
"\n",
" # print(\"current_year_month_row\",current_year_month_row)\n",
" if i == 0:\n",
" rowFlag = 0\n",
" # 查看每组数据\n",
" for date, group in grouped:\n",
" new_sheet.write(row_count + rowFlag - current_year_month_row, 0, date)\n",
" for j in range(len(dataItemNoList)):\n",
" dataItemNo = dataItemNoList[j]\n",
"\n",
" if group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values and (not str(group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values[0]) == 'nan'):\n",
"\n",
" new_sheet.write(row_count + rowFlag - current_year_month_row, j + 1, group[group[\"dataItemNo\"] == dataItemNo][\"dataValue\"].values[0])\n",
"\n",
" rowFlag += 1\n",
"\n",
"\n",
" # 保存新的xls文件\n",
" new_workbook.save(\"纯苯数据项.xls\")\n",
"\n",
"\n",
"\n",
"\n",
"def queryDataListItemNos():\n",
" df = pd.read_excel('纯苯数据项.xls')\n",
" dataItemNoList = df.iloc[0].tolist()[1:]\n",
"\n",
" token = get_head_auth()\n",
" if not token:\n",
" return\n",
"\n",
" # 获取当前日期\n",
" current_date = datetime.datetime.now()\n",
"\n",
" # 获取当月1日\n",
" first_day_of_month = current_date.replace(day=1)\n",
"\n",
" # 格式化为 YYYYMMDD 格式\n",
" dateEnd = current_date.strftime('%Y%m%d')\n",
" dateStart = first_day_of_month.strftime('%Y%m%d')\n",
"\n",
" search_value = get_queryDataListItemNos_value(token, queryDataListItemNos_url, dataItemNoList, dateStart, dateEnd)\n",
"\n",
"\n",
" data_df = pd.DataFrame(search_value)\n",
"\n",
" data_df[\"dataDate\"] = pd.to_datetime(data_df[\"dataDate\"])\n",
" data_df[\"dataDate\"] = data_df[\"dataDate\"].dt.strftime('%Y-%m-%d')\n",
" save_queryDataListItemNos_xls(data_df,dataItemNoList)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
" # queryDataListItemNos()\n",
" pass\n",
" # 需要单独运行放开\n",
" # start_1()\n",
@ -684,6 +810,9 @@
" # # 获取当前时间\n",
" # current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n",
" # current_time_1 = time.strftime(\"%H:%M:%S\", time.localtime())\n",
" # # 获取当月的数据写入到指定文件\n",
" # queryDataListItemNos()\n",
"\n",
"\n",
" # # 判断当前时间是否为执行任务的时间点\n",
" # if current_time == \"09:15:00\":\n",
@ -1654,7 +1783,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -1668,7 +1797,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.12.4"
}
},
"nbformat": 4,