{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import xlrd\n",
    "import xlwt\n",
    "from datetime import datetime, timedelta \n",
    "import time\n",
    "import pandas as pd\n",
    "pd.set_option('display.max_columns', None)\n",
    "\n",
    "import numpy as np\n",
    "# 变量定义\n",
    "login_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n",
    "# query_data_list_item_nos_url\n",
    "search_url = \"http://10.200.32.39/jingbo-api/api/warehouse/dwDataItem/queryByItemNos\"  #jingbo-dev/api/warehouse/dwDataItem/queryDataListItemNos\n",
    "upload_url = \"http://10.200.32.39/jingbo-api/api/dw/dataValue/pushDataValueList\"\n",
    "\n",
    "\n",
    "query_data_list_item_nos_data = {\n",
    "    \"funcModule\": \"数据项\",\n",
    "    \"funcOperation\": \"查询\",\n",
    "    \"data\": {\n",
    "        \"dateStart\": \"20200101\",\n",
    "        \"dateEnd\": \"20241231\",\n",
    "        \"dataItemNoList\": [\"Brentzdj\", \"Brentzgj\"]  # 数据项编码,代表 brent最低价和最高价\n",
    "    }\n",
    "}\n",
    "\n",
    "\n",
    "login_data = {\n",
    "    \"data\": {\n",
    "        \"account\": \"api_dev\",\n",
    "        \"password\": \"ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=\",\n",
    "        \"tenantHashCode\": \"8a4577dbd919675758d57999a1e891fe\",\n",
    "        \"terminal\": \"API\"\n",
    "    },\n",
    "    \"funcModule\": \"API\",\n",
    "    \"funcOperation\": \"获取token\"\n",
    "}\n",
    "\n",
    "\n",
    "read_file_path_name = \"定性模型数据项12-11.xlsx\"\n",
    "one_cols = []\n",
    "two_cols = []\n",
    "\n",
    "\n",
    "def update_e_value(file_path, column_index, threshold):\n",
    "    \"\"\"\n",
    "    数据修正需求:2025年1月8日\n",
    "        如果如果今天的成本即期价跟昨天的成本价差正负1000以上,就按照昨天的成本价计算\n",
    "\n",
    "    更新Excel文件中指定列的值,如果新值与前一天的值变化大于阈值,则将新值改为前一天的值。\n",
    "\n",
    "    :param file_path: Excel文件路径\n",
    "    :param column_index: 需要更新的列索引\n",
    "    :param threshold: 变化阈值\n",
    "    \"\"\"\n",
    "    # 读取Excel文件\n",
    "    # try:\n",
    "    #     df = pd.read_excel(file_path, engine='openpyxl')\n",
    "    # except:\n",
    "    #     df = pd.read_excel(file_path, engine='xlrd')\n",
    "        \n",
    "    df = pd.read_excel(file_path)\n",
    "    # 所有列列统一数据格式为float\n",
    "    df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
    "    \n",
    "    # print(df.tail())\n",
    "    # 填充缺失值\n",
    "    df = df.fillna(method='ffill')\n",
    "\n",
    "    # 获取最后两行数据\n",
    "    df1 = df.tail(2)\n",
    "    # print(df1)\n",
    "    # 获取前一天的指定列值\n",
    "    previous_value = df1.iloc[0, column_index]\n",
    "    print('前一天的',previous_value,type(previous_value))\n",
    "    # 获取当前的指定列值\n",
    "    current_value = df1.iloc[1, column_index]\n",
    "    print('现在的',current_value,type(current_value))\n",
    "    # 判断指定列值的变化是否大于阈值\n",
    "    if abs(current_value - previous_value) > threshold:\n",
    "        # 如果变化大于阈值,将当前的指定列值改为前一天的值\n",
    "        df.iloc[-1, column_index] = previous_value\n",
    "        print('修改了')\n",
    "    # print(df.tail())\n",
    "    # 将修改后的数据写回Excel文件\n",
    "    df.to_excel(file_path, index=False,engine='openpyxl')\n",
    "\n",
    "def getLogToken():\n",
    "    login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n",
    "    text = json.loads(login_res.text)\n",
    "    if text[\"status\"]:\n",
    "        token = text[\"data\"][\"accessToken\"]\n",
    "    else:\n",
    "        print(\"获取认证失败\")\n",
    "        token =  None\n",
    "    return token\n",
    "\n",
    "def updateExcelDatabak(date='',token=None):\n",
    "    workbook = xlrd.open_workbook(read_file_path_name)\n",
    "\n",
    "    # 选择第一个表格\n",
    "    sheet = workbook.sheet_by_index(0)\n",
    "\n",
    "    row_data = sheet.row_values(1)\n",
    "    one_cols = row_data\n",
    "\n",
    "    cur_time,cur_time2 = getNow(date)\n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "#     datas = search_value\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else :\n",
    "        datas = None\n",
    "   \n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "#     for data_value in datas:\n",
    "#         dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\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",
    "        # 创建xlwt的Workbook对象\n",
    "        # 创建sheet\n",
    "        new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
    "\n",
    "        # 将原有的数据写入新的sheet\n",
    "        for row in range(row_count):\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row, col, data[row][col])\n",
    "\n",
    "        if i == 0:\n",
    "            \n",
    "            # 在新的sheet中添加数据\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row_count, col, append_rows[col])\n",
    "\n",
    "    # 保存新的xls文件\n",
    "    new_workbook.save(\"定性模型数据项12-11.xlsx\")\n",
    "\n",
    "def updateYesterdayExcelData(date='', token=None):\n",
    "    # 使用pandas读取Excel文件\n",
    "    df = pd.read_excel(read_file_path_name, engine='openpyxl')\n",
    "\n",
    "    # 获取第二行的数据作为列名\n",
    "    one_cols = df.iloc[0,:].tolist()\n",
    "\n",
    "    # 获取当前日期的前一天\n",
    "    if date == '':\n",
    "        previous_date = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')\n",
    "    else:\n",
    "        # 字符串转日期\n",
    "        previous_date = (datetime.strptime(date, \"%Y-%m-%d\")-timedelta(days=1)).strftime('%Y-%m-%d')\n",
    "    \n",
    "\n",
    "    cur_time, cur_time2 = getNow(previous_date)\n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else:\n",
    "        datas = None\n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    print('更新数据前')\n",
    "    print(df.tail(1))\n",
    "    # 检查日期是否已存在于数据中\n",
    "    if previous_date not in df['日期'].values:\n",
    "        # 将新的数据添加到DataFrame中\n",
    "        new_row = pd.DataFrame([append_rows], columns=df.columns.tolist())\n",
    "        df = pd.concat([df, new_row], ignore_index=True)\n",
    "    else:\n",
    "        # 更新现有数据\n",
    "        print('日期存在,即将更新')\n",
    "        print('新数据',append_rows[1:])\n",
    "        df.loc[df['日期'] == previous_date, df.columns.tolist()[1:]] = append_rows[1:]\n",
    "\n",
    "    print('更新数据后')\n",
    "    print(df.tail(1))\n",
    "    # 使用pandas保存Excel文件\n",
    "    df.to_excel(\"定性模型数据项12-11.xlsx\", index=False, engine='openpyxl')\n",
    "\n",
    "\n",
    "def updateExcelData(date='', token=None):\n",
    "    # 使用pandas读取Excel文件\n",
    "    df = pd.read_excel(read_file_path_name, engine='openpyxl')\n",
    "\n",
    "    # 获取第一行的数据作为列名\n",
    "    # one_cols = df.columns.tolist()\n",
    "    \n",
    "    # 获取第二行的数据作为列名\n",
    "    one_cols = df.iloc[0,:].tolist()\n",
    "\n",
    "    cur_time, cur_time2 = getNow(date)\n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else:\n",
    "        datas = None\n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    # 将新的数据添加到DataFrame中\n",
    "    new_row = pd.DataFrame([append_rows], columns=df.columns.tolist())\n",
    "    df = pd.concat([df, new_row], ignore_index=True)\n",
    "    # df = df.append(pd.Series(append_rows), ignore_index=True)\n",
    "\n",
    "    # 使用pandas保存Excel文件\n",
    "    df.to_excel(\"定性模型数据项12-11.xlsx\", index=False, engine='openpyxl')\n",
    "\n",
    "\n",
    "def qualitativeModel():\n",
    "    df = pd.read_excel('定性模型数据项12-11.xlsx')\n",
    "\n",
    "    df=df.fillna(df.ffill())\n",
    "    df1 = df[-2:].reset_index()\n",
    "    '''\n",
    "    # if df1.loc[1,'70号沥青开工率'] > 0.3:   \n",
    "    2025年1月8日 修改:\n",
    "        复盘分析后发现2024-7月开始,开工率数据从0.28 变为了28 ,改为下面的判断规则\n",
    "    '''\n",
    "    if df1.loc[1,'70号沥青开工率'] / 100  > 0.3:\n",
    "        a = -(df1.loc[1,'70号沥青开工率'] / 100 -0.2)*5/0.1\n",
    "    else :\n",
    "        a = 0\n",
    "    b = df1.loc[1,'资金因素']\n",
    "    \n",
    "    print('昨日计划提货偏差改之前',df1.loc[1,'昨日计划提货偏差'])\n",
    "    # 昨日计划提货偏差 = 京博产量 - 计划产量\n",
    "    df1.loc[1,'昨日计划提货偏差'] = df1.loc[1,'京博产量'] - df1.loc[1,'计划产量']\n",
    "    \n",
    "    print('昨日计划提货偏差改之后',df1.loc[1,'昨日计划提货偏差'])\n",
    "    if df1.loc[1,'昨日计划提货偏差']>0:\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/2000\n",
    "    else :\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/3000\n",
    "        \n",
    "    # 生产情况 = (京博产量 - 计划产量)/500*5\n",
    "    d = (df1.loc[1,'京博产量'] - df1.loc[1,'计划产量']) / 500 * 5\n",
    "    \n",
    "    if df1.loc[1,'基质沥青库存']/265007 >0.8:\n",
    "        e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n",
    "    else : \n",
    "        e = 0\n",
    "#     f = df1.loc[1,'下游客户价格预期']\n",
    "    f = 1 # 2025年1月23日修改:价格预期都按1计算\n",
    "    if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n",
    "        g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n",
    "    else :\n",
    "        g = 0\n",
    "    h = df1.loc[1,'订单结构']\n",
    "    x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n",
    "    return x\n",
    "\n",
    "\n",
    "def getNow(date='',offset=0):\n",
    "    if date == '':\n",
    "        now = datetime.now() - timedelta(days=offset)\n",
    "    else:\n",
    "        try:\n",
    "            date = datetime.strptime(date, \"%Y-%m-%d\")\n",
    "        except:\n",
    "            date = datetime.strptime(date, \"%Y%m%d\")\n",
    "        now = date\n",
    "\n",
    "    year = now.year\n",
    "    month = now.month\n",
    "    day = now.day\n",
    "\n",
    "    if month < 10:\n",
    "        month = \"0\" + str(month)\n",
    "    if day < 10:\n",
    "        day = \"0\" + str(day)\n",
    "    cur_time = str(year) + str(month) + str(day)\n",
    "    cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n",
    "    return cur_time,cur_time2\n",
    "\n",
    "def pushData(cur_time,x,token_push):\n",
    "    data1 = {\n",
    "        \"funcModule\": \"数据表信息列表\",\n",
    "        \"funcOperation\": \"新增\",\n",
    "        \"data\": [\n",
    "            {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n",
    "             \"dataDate\": cur_time,\n",
    "             \"dataStatus\": \"add\",\n",
    "             \"dataValue\": x\n",
    "             }\n",
    "        ]\n",
    "    }\n",
    "    headers1 = {\"Authorization\": token_push}\n",
    "    res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n",
    "    \n",
    "def start_2(date='',token=None):\n",
    "    workbook = xlrd.open_workbook(read_file_path_name)\n",
    "\n",
    "    # 选择第一个表格\n",
    "    sheet = workbook.sheet_by_index(0)\n",
    "\n",
    "    # 获取行数和列数\n",
    "    num_rows = sheet.nrows\n",
    "    \n",
    "    row_data = sheet.row_values(1)\n",
    "    one_cols = row_data\n",
    "\n",
    "    cur_time,cur_time2 = getNow(date)\n",
    "    \n",
    "    \n",
    "    \n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "#     datas = search_value\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else :\n",
    "        datas = None\n",
    "   \n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "#     for data_value in datas:\n",
    "#         dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\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",
    "        # 创建xlwt的Workbook对象\n",
    "        # 创建sheet\n",
    "        new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
    "\n",
    "        # 将原有的数据写入新的sheet\n",
    "        for row in range(row_count):\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row, col, data[row][col])\n",
    "\n",
    "        if i == 0:\n",
    "            \n",
    "            # 在新的sheet中添加数据\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row_count, col, append_rows[col])\n",
    "\n",
    "    # 保存新的xls文件\n",
    "    new_workbook.save(\"定性模型数据项12-11.xlsx\")\n",
    "\n",
    "    update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n",
    "\n",
    "    df = pd.read_excel('定性模型数据项12-11.xlsx')\n",
    "\n",
    "    df=df.fillna(df.ffill())\n",
    "    df1 = df[-2:].reset_index()\n",
    "    '''\n",
    "    # if df1.loc[1,'70号沥青开工率'] > 0.3:   \n",
    "    2025年1月8日 修改:\n",
    "        复盘分析后发现2024-7月开始,开工率数据从0.28 变为了28 ,改为下面的判断规则\n",
    "    '''\n",
    "    if df1.loc[1,'70号沥青开工率'] > 30:\n",
    "        a = (df1.loc[1,'70号沥青开工率']-0.2)*5/0.1\n",
    "    else :\n",
    "        a = 0\n",
    "    b = df1.loc[1,'资金因素']\n",
    "    if df1.loc[1,'昨日计划提货偏差']>0:\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/2000\n",
    "    else :\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/3000\n",
    "    d = df1.loc[1,'生产情况']\n",
    "    if df1.loc[1,'基质沥青库存']/265007 >0.8:\n",
    "        e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n",
    "    else : \n",
    "        e = 0\n",
    "#     f = df1.loc[1,'下游客户价格预期']\n",
    "    f = 1 # 2025年1月23日修改:价格预期都按1计算\n",
    "    if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n",
    "        g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n",
    "    else :\n",
    "        g = 0\n",
    "    h = df1.loc[1,'订单结构']\n",
    "    x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n",
    "\n",
    "    login_res1 = requests.post(url=login_push_url, json=login_push_data, timeout=(3, 5))\n",
    "    text1 = json.loads(login_res1.text)\n",
    "    token_push = text1[\"data\"][\"accessToken\"]\n",
    "\n",
    "\n",
    "    data1 = {\n",
    "        \"funcModule\": \"数据表信息列表\",\n",
    "        \"funcOperation\": \"新增\",\n",
    "        \"data\": [\n",
    "            {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n",
    "             \"dataDate\": cur_time,\n",
    "             \"dataStatus\": \"add\",\n",
    "             \"dataValue\": x\n",
    "             }\n",
    "\n",
    "        ]\n",
    "    }\n",
    "    headers1 = {\"Authorization\": token_push}\n",
    "    # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n",
    "    \n",
    "\n",
    "def start():\n",
    "    workbook = xlrd.open_workbook(read_file_path_name)\n",
    "\n",
    "\n",
    "\n",
    "    # 选择第一个表格\n",
    "    sheet = workbook.sheet_by_index(0)\n",
    "\n",
    "    # 获取行数和列数\n",
    "    num_rows = sheet.nrows\n",
    "\n",
    "\n",
    "\n",
    "    row_data = sheet.row_values(1)\n",
    "    one_cols = row_data\n",
    "\n",
    "\n",
    "    login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n",
    "    text = json.loads(login_res.text)\n",
    "    if text[\"status\"]:\n",
    "        token = text[\"data\"][\"accessToken\"]\n",
    "    else:\n",
    "        print(\"获取认证失败\")\n",
    "        token =  None\n",
    "\n",
    "\n",
    "    now = datetime.now()\n",
    "    year = now.year\n",
    "    month = now.month\n",
    "    day = now.day\n",
    "\n",
    "    if month < 10:\n",
    "        month = \"0\" + str(month)\n",
    "    if day < 10:\n",
    "        day = \"0\" + str(day)\n",
    "    cur_time = str(year) + str(month) + str(day)\n",
    "    cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "#     datas = search_value\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else :\n",
    "        datas = None\n",
    "   \n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "#     for data_value in datas:\n",
    "#         dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\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",
    "        # 创建xlwt的Workbook对象\n",
    "        # 创建sheet\n",
    "        new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
    "\n",
    "        # 将原有的数据写入新的sheet\n",
    "        for row in range(row_count):\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row, col, data[row][col])\n",
    "\n",
    "        if i == 0:\n",
    "            # 在新的sheet中添加数据\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row_count, col, append_rows[col])\n",
    "\n",
    "    # 保存新的xls文件\n",
    "    new_workbook.save(\"定性模型数据项12-11.xlsx\")\n",
    "    \n",
    "    update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n",
    "\n",
    "    df = pd.read_excel('定性模型数据项12-11.xlsx')\n",
    "    df=df.fillna(df.ffill())\n",
    "    df1 = df[-2:].reset_index()\n",
    "    # if df1.loc[1,'70号沥青开工率'] > 0.3:   -- 2025年1月9日 发版更改\n",
    "    if df1.loc[1,'70号沥青开工率'] / 100  > 0.3:\n",
    "        a = (df1.loc[1,'70号沥青开工率'] / 100 -0.2)*5/0.1\n",
    "    else :\n",
    "        a = 0\n",
    "    b = df1.loc[1,'资金因素']\n",
    "    if df1.loc[1,'昨日计划提货偏差']>0:\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/2000\n",
    "    else :\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/3000\n",
    "    d = df1.loc[1,'生产情况']\n",
    "    if df1.loc[1,'基质沥青库存']/265007 >0.8:\n",
    "        e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n",
    "    else : \n",
    "        e = 0\n",
    "#     f = df1.loc[1,'下游客户价格预期']\n",
    "    f = 1 # 2025年1月23日修改:价格预期都按1计算\n",
    "    if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n",
    "        g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n",
    "    else :\n",
    "        g = 0\n",
    "    h = df1.loc[1,'订单结构']\n",
    "    x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n",
    "    \n",
    "\n",
    "    # login_res1 = requests.post(url=login_url, json=login_data, timeout=(3, 30))\n",
    "    # text1 = json.loads(login_res1.text)\n",
    "    # token_push = text1[\"data\"][\"accessToken\"]\n",
    "\n",
    "\n",
    "    # data1 = {\n",
    "    #     \"funcModule\": \"数据表信息列表\",\n",
    "    #     \"funcOperation\": \"新增\",\n",
    "    #     \"data\": [\n",
    "    #         {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n",
    "    #          \"dataDate\": cur_time,\n",
    "    #          \"dataStatus\": \"add\",\n",
    "    #          \"dataValue\": x\n",
    "    #          }\n",
    "\n",
    "    #     ]\n",
    "    # }\n",
    "    # headers1 = {\"Authorization\": token_push}\n",
    "    # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n",
    "    \n",
    "    \n",
    "\n",
    "\n",
    "def start_test():\n",
    "    workbook = xlrd.open_workbook(read_file_path_name)\n",
    "\n",
    "\n",
    "\n",
    "    # 选择第一个表格\n",
    "    sheet = workbook.sheet_by_index(0)\n",
    "\n",
    "    # 获取行数和列数\n",
    "    num_rows = sheet.nrows\n",
    "\n",
    "\n",
    "\n",
    "    row_data = sheet.row_values(1)\n",
    "    one_cols = row_data\n",
    "\n",
    "\n",
    "    login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n",
    "    text = json.loads(login_res.text)\n",
    "    if text[\"status\"]:\n",
    "        token = text[\"data\"][\"accessToken\"]\n",
    "    else:\n",
    "        print(\"获取认证失败\")\n",
    "        token =  None\n",
    "\n",
    "\n",
    "    now = datetime.now()\n",
    "    year = now.year\n",
    "    month = now.month\n",
    "    day = now.day\n",
    "\n",
    "    if month < 10:\n",
    "        month = \"0\" + str(month)\n",
    "    if day < 10:\n",
    "        day = \"0\" + str(day)\n",
    "    cur_time = str(year) + str(month) + str(day)\n",
    "    cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "#     datas = search_value\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else :\n",
    "        datas = None\n",
    "   \n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "#     for data_value in datas:\n",
    "#         dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\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",
    "        # 创建xlwt的Workbook对象\n",
    "        # 创建sheet\n",
    "        new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
    "\n",
    "        # 将原有的数据写入新的sheet\n",
    "        for row in range(row_count):\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row, col, data[row][col])\n",
    "\n",
    "        if i == 0:\n",
    "            # 在新的sheet中添加数据\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row_count, col, append_rows[col])\n",
    "\n",
    "    # 保存新的xls文件\n",
    "    new_workbook.save(\"定性模型数据项12-11.xlsx\")\n",
    "    \n",
    "    update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n",
    "\n",
    "    df = pd.read_excel('定性模型数据项12-11.xlsx')\n",
    "    df=df.fillna(df.ffill())\n",
    "    df1 = df[-2:].reset_index()\n",
    "    # if df1.loc[1,'70号沥青开工率'] > 0.3:   -- 2025年1月9日 发版更改\n",
    "    if df1.loc[1,'70号沥青开工率'] / 100  > 0.3:\n",
    "        a = (df1.loc[1,'70号沥青开工率'] / 100 -0.2)*5/0.1\n",
    "    else :\n",
    "        a = 0\n",
    "    b = df1.loc[1,'资金因素']\n",
    "    if df1.loc[1,'昨日计划提货偏差']>0:\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/2000\n",
    "    else :\n",
    "        c = df1.loc[1,'昨日计划提货偏差']*10/3000\n",
    "    d = df1.loc[1,'生产情况']\n",
    "    if df1.loc[1,'基质沥青库存']/265007 >0.8:\n",
    "        e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n",
    "    else : \n",
    "        e = 0\n",
    "#     f = df1.loc[1,'下游客户价格预期']\n",
    "    f = 1 # 2025年1月23日修改:价格预期都按1计算\n",
    "    if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n",
    "        g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n",
    "    else :\n",
    "        g = 0\n",
    "    h = df1.loc[1,'订单结构']\n",
    "    x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n",
    "    \n",
    "\n",
    "    # login_res1 = requests.post(url=login_url, json=login_data, timeout=(3, 30))\n",
    "    # text1 = json.loads(login_res1.text)\n",
    "    # token_push = text1[\"data\"][\"accessToken\"]\n",
    "\n",
    "\n",
    "    # data1 = {\n",
    "    #     \"funcModule\": \"数据表信息列表\",\n",
    "    #     \"funcOperation\": \"新增\",\n",
    "    #     \"data\": [\n",
    "    #         {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n",
    "    #          \"dataDate\": cur_time,\n",
    "    #          \"dataStatus\": \"add\",\n",
    "    #          \"dataValue\": x\n",
    "    #          }\n",
    "\n",
    "    #     ]\n",
    "    # }\n",
    "    # headers1 = {\"Authorization\": token_push}\n",
    "    # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n",
    "    \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "def start_1():\n",
    "    workbook = xlrd.open_workbook(read_file_path_name)\n",
    "\n",
    "\n",
    "\n",
    "    # 选择第一个表格\n",
    "    sheet = workbook.sheet_by_index(0)\n",
    "\n",
    "    # 获取行数和列数\n",
    "    num_rows = sheet.nrows\n",
    "\n",
    "\n",
    "\n",
    "    row_data = sheet.row_values(1)\n",
    "    one_cols = row_data\n",
    "\n",
    "\n",
    "    login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n",
    "    text = json.loads(login_res.text)\n",
    "    if text[\"status\"]:\n",
    "        token = text[\"data\"][\"accessToken\"]\n",
    "    else:\n",
    "        print(\"获取认证失败\")\n",
    "        token =  None\n",
    "\n",
    "\n",
    "    now = datetime.now()  - timedelta(days=1)  \n",
    "    year = now.year\n",
    "    month = now.month\n",
    "    day = now.day\n",
    "\n",
    "    if month < 10:\n",
    "        month = \"0\" + str(month)\n",
    "    if day < 10:\n",
    "        day = \"0\" + str(day)\n",
    "    cur_time = str(year) + str(month) + str(day)\n",
    "    cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n",
    "    search_data = {\n",
    "        \"data\": {\n",
    "            \"date\": cur_time,\n",
    "            \"dataItemNoList\": one_cols[1:]\n",
    "        },\n",
    "        \"funcModule\": \"数据项\",\n",
    "        \"funcOperation\": \"查询\"\n",
    "    }\n",
    "    headers = {\"Authorization\": token}\n",
    "    search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n",
    "    search_value = json.loads(search_res.text)[\"data\"]\n",
    "#     datas = search_value\n",
    "    if search_value:\n",
    "        datas = search_value\n",
    "    else :\n",
    "        datas = None\n",
    "    \n",
    "   \n",
    "\n",
    "    append_rows = [cur_time2]\n",
    "    dataItemNo_dataValue = {}\n",
    "#     for data_value in datas:\n",
    "#         dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for data_value in datas:\n",
    "        if \"dataValue\" not in data_value:\n",
    "            print(data_value)\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n",
    "        else:\n",
    "            dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n",
    "    for value in one_cols[1:]:\n",
    "        if value in dataItemNo_dataValue:\n",
    "            append_rows.append(dataItemNo_dataValue[value])\n",
    "        else:\n",
    "            append_rows.append(\"\")\n",
    "\n",
    "    workbook = xlrd.open_workbook('定性模型数据项12-11.xlsx')\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 - 1\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",
    "        # 创建xlwt的Workbook对象\n",
    "        # 创建sheet\n",
    "        new_sheet = new_workbook.add_sheet(sheet_names[i])\n",
    "\n",
    "        # 将原有的数据写入新的sheet\n",
    "        for row in range(row_count):\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row, col, data[row][col])\n",
    "\n",
    "        if i == 0:\n",
    "            # 在新的sheet中添加数据\n",
    "            for col in range(col_count):\n",
    "                new_sheet.write(row_count, col, append_rows[col])\n",
    "\n",
    "    # 保存新的xls文件\n",
    "    new_workbook.save(\"定性模型数据项12-11.xlsx\")\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 原始代码备份\n",
    "\n",
    "# if __name__ == \"__main__\":\n",
    "\n",
    "    # 需要单独运行放开\n",
    "#      start_1()\n",
    "\n",
    "    # # 每天定时12点运行\n",
    "    # while True:\n",
    "    #     # 获取当前时间\n",
    "    #     current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n",
    "    #     current_time_1 = time.strftime(\"%H:%M:%S\", time.localtime())\n",
    "\n",
    "    #     # 判断当前时间是否为执行任务的时间点\n",
    "    #     if current_time == \"12:00:00\":\n",
    "    #         print(\"执行定时任务\")\n",
    "    #         start()\n",
    "\n",
    "    #     # 休眠1秒钟,避免过多占用CPU资源\n",
    "    #         time.sleep(1)\n",
    "        \n",
    "    #     elif current_time_1 == \"20:00:00\":\n",
    "    #         print(\"更新数据\")\n",
    "    #         start_1()\n",
    "    #     time.sleep(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# if __name__ == \"__main__\":\n",
    "#     def main():\n",
    "#         # 获取当前日期\n",
    "#         date = datetime.now().date()\n",
    "#         date = date.strftime('%Y%m%d')\n",
    "#         # 获取登录token\n",
    "#         token = getLogToken()\n",
    "#         updateExcelData(date,token)\n",
    "#         update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n",
    "#         x = qualitativeModel()\n",
    "#         print('预测结果:',x)\n",
    "#         cur_time,cur_time2 = getNow(date)\n",
    "#         pushData(cur_time,x,token)\n",
    "\n",
    "#     print(\"运行中...\")\n",
    "#     # 每天定时12点运行\n",
    "#     while True:\n",
    "#         # 获取当前时间\n",
    "#         current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n",
    "#         try:\n",
    "#             # 判断当前时间是否为执行任务的时间点\n",
    "#             if current_time == \"12:00:00\":\n",
    "#                 try:\n",
    "#                     main()\n",
    "#                 except Exception as e:\n",
    "#                     print(f\"12点执行失败: {e}\")\n",
    "#                     # 等待到12点30分再次执行\n",
    "#                     while current_time != \"12:30:00\":\n",
    "#                         current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n",
    "#                         time.sleep(1)\n",
    "#                     try:\n",
    "#                         main()\n",
    "#                     except Exception as e:\n",
    "#                         print(f\"12点30分也执行失败: {e}\")\n",
    "#             elif current_time == \"20:00:00\":\n",
    "#                 print(\"更新前一天数据\")\n",
    "#                 token = getLogToken()\n",
    "#                 updateYesterdayExcelData(token=token)\n",
    "                \n",
    "#             time.sleep(1)\n",
    "#         except Exception as e:\n",
    "#             print(f\"执行失败: {e}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20250304\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3543.2385 <class 'float'>\n",
      "现在的 3414.5246 <class 'float'>\n",
      "昨日计划提货偏差改之前 -571.14\n",
      "昨日计划提货偏差改之后 339.1062000000002\n",
      "**************************************************预测结果: 3585.63\n",
      "20250305\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3414.5246 <class 'float'>\n",
      "现在的 3409.5135 <class 'float'>\n",
      "昨日计划提货偏差改之前 3173.74\n",
      "昨日计划提货偏差改之后 436.6761999999999\n",
      "**************************************************预测结果: 3781.57\n",
      "20250306\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3409.5135 <class 'float'>\n",
      "现在的 3304.2291 <class 'float'>\n",
      "昨日计划提货偏差改之前 2324.63\n",
      "昨日计划提货偏差改之后 608.3411999999998\n",
      "**************************************************预测结果: 3760.78\n",
      "20250307\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3304.2291 <class 'float'>\n",
      "现在的 3312.3543 <class 'float'>\n",
      "昨日计划提货偏差改之前 3426.43\n",
      "昨日计划提货偏差改之后 232.5551999999998\n",
      "**************************************************预测结果: 3781.31\n",
      "20250308\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3312.3543 <class 'float'>\n",
      "现在的 3375.9949 <class 'float'>\n",
      "昨日计划提货偏差改之前 2314.8\n",
      "昨日计划提货偏差改之后 95.26919999999973\n",
      "**************************************************预测结果: 3781.04\n",
      "20250309\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3375.9949 <class 'float'>\n",
      "现在的 3367.7575 <class 'float'>\n",
      "昨日计划提货偏差改之前 4676.24\n",
      "昨日计划提货偏差改之后 -324.57479999999987\n",
      "**************************************************预测结果: 3780.47\n",
      "20250310\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3367.7575 <class 'float'>\n",
      "现在的 3347.97 <class 'float'>\n",
      "昨日计划提货偏差改之前 -1038.55\n",
      "昨日计划提货偏差改之后 -176.92599999999993\n",
      "**************************************************预测结果: 3780.72\n",
      "20250311\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3347.97 <class 'float'>\n",
      "现在的 3282.8269 <class 'float'>\n",
      "昨日计划提货偏差改之前 2467.05\n",
      "昨日计划提货偏差改之后 348.5867999999996\n",
      "**************************************************预测结果: 3701.49\n",
      "20250312\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3282.8269 <class 'float'>\n",
      "现在的 3362.2709 <class 'float'>\n",
      "昨日计划提货偏差改之前 -198.73\n",
      "昨日计划提货偏差改之后 338.9767999999999\n",
      "**************************************************预测结果: 3621.48\n",
      "20250313\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3362.2709 <class 'float'>\n",
      "现在的 3476.9658 <class 'float'>\n",
      "昨日计划提货偏差改之前 2356.71\n",
      "昨日计划提货偏差改之后 703.9968000000003\n",
      "**************************************************预测结果: 3644.94\n",
      "20250314\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3476.9658 <class 'float'>\n",
      "现在的 3426.2475 <class 'float'>\n",
      "昨日计划提货偏差改之前 2295.03\n",
      "昨日计划提货偏差改之后 299.41520000000037\n",
      "**************************************************预测结果: 3621.29\n",
      "20250315\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3426.2475 <class 'float'>\n",
      "现在的 3471.3062 <class 'float'>\n",
      "昨日计划提货偏差改之前 3608.02\n",
      "昨日计划提货偏差改之后 326.89519999999993\n",
      "**************************************************预测结果: 3651.37\n",
      "20250316\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3471.3062 <class 'float'>\n",
      "现在的 3484.929 <class 'float'>\n",
      "昨日计划提货偏差改之前 3044.14\n",
      "昨日计划提货偏差改之后 309.15520000000015\n",
      "**************************************************预测结果: 3651.31\n",
      "20250317\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3484.929 <class 'float'>\n",
      "现在的 3553.0486 <class 'float'>\n",
      "昨日计划提货偏差改之前 653.09\n",
      "昨日计划提货偏差改之后 304.6226999999999\n",
      "**************************************************预测结果: 3651.3\n",
      "20250318\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:53: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n",
      "C:\\Users\\EDY\\AppData\\Local\\Temp\\ipykernel_10124\\1472055096.py:57: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
      "  df = df.fillna(method='ffill')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "前一天的 3553.0486 <class 'float'>\n",
      "现在的 3543.2385 <class 'float'>\n",
      "昨日计划提货偏差改之前 3654.03\n",
      "昨日计划提货偏差改之后 31.435199999999895\n",
      "**************************************************预测结果: 3610.87\n"
     ]
    }
   ],
   "source": [
    "# 重新上传定性数据\n",
    "\n",
    "def main(date='',token=None):\n",
    "    updateExcelData(date,token)\n",
    "    update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n",
    "    x = qualitativeModel()\n",
    "    print('**************************************************预测结果:',x)\n",
    "    # cur_time,cur_time2 = getNow(date)\n",
    "    # pushData(cur_time,x,token)\n",
    "\n",
    "\n",
    "start_date = datetime(2025, 3, 4)\n",
    "end_date = datetime(2025, 3, 19)\n",
    "token = getLogToken()\n",
    "while start_date < end_date:\n",
    "    print(start_date.strftime('%Y%m%d'))\n",
    "    main(start_date.strftime('%Y%m%d'),token)\n",
    "    start_date += timedelta(days=1)\n",
    "    time.sleep(5)\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 调试更新数据\n",
    "# date = '2025-01-24'\n",
    "# token = getLogToken()\n",
    "# updateYesterdayExcelData(date=date,token=token)\n",
    "# print('更新完了')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 快速调试线上\n",
    "# def main():\n",
    "#     # 获取当前日期\n",
    "#     date = datetime.now().date()\n",
    "#     date = date.strftime('%Y%m%d')\n",
    "#     # 获取登录token\n",
    "#     token = getLogToken()\n",
    "#     updateExcelData(date,token)\n",
    "#     update_e_value('定性模型数据项12-11.xlsx', 8, 1000)\n",
    "#     x = qualitativeModel()\n",
    "#     print('预测结果:',x)\n",
    "#     cur_time,cur_time2 = getNow(date)\n",
    "#     pushData(cur_time,x,token)\n",
    "\n",
    "# current_time = time.strftime(\"%H:%M:%S\", time.localtime())\n",
    "# main()\n",
    "# token = getLogToken()\n",
    "# updateYesterdayExcelData(token=token)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "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.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}