diff --git a/Timed_task.bat b/Timed_task.bat deleted file mode 100644 index fed98bb..0000000 --- a/Timed_task.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo on -d: -cd code/PricePredict/ -C:/Users/Hello/.conda/envs/predict-py397/python.exe main.py \ No newline at end of file diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index b5dc8b9..0000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,65 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 6, - "id": "b3cde8ea", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'ovx index': '原油波动率', 'dxy curncy': '美元指数', 'C2403128043': 'Brent连1合约价格拟合残差/美元指数', 'C2403150124': 'Brent连1合约价格拟合残差/Brent 连2-连3', 'DOESCRUD Index': '美国商业原油库存', 'FVHCM1 INDEX': '美国取暖油裂解C1', 'doedtprd index': '美国成品油表需', 'CFFDQMMN INDEX': 'WTI管理资金净多持仓', 'C2403083739': 'WTI基金多空持仓比', 'C2404167878': 'WTI基金净持仓COT指标(代码运算)', 'lmcads03 lme comdty': 'LME铜价', 'GC1 COMB Comdty': '黄金连1合约', 'C2404167855': '金油比'}\n" - ] - } - ], - "source": [ - "data = \"\"\"\n", - "ovx index 原油波动率\n", - "dxy curncy 美元指数\n", - "C2403128043 Brent连1合约价格拟合残差/美元指数\n", - "C2403150124 Brent连1合约价格拟合残差/Brent 连2-连3\n", - "DOESCRUD Index 美国商业原油库存\n", - "FVHCM1 INDEX 美国取暖油裂解C1\n", - "doedtprd index 美国成品油表需\n", - "CFFDQMMN INDEX WTI管理资金净多持仓\n", - "C2403083739 WTI基金多空持仓比\n", - "C2404167878 WTI基金净持仓COT指标(代码运算)\n", - "lmcads03 lme comdty LME铜价\n", - "GC1 COMB Comdty 黄金连1合约\n", - "C2404167855 金油比\n", - "\"\"\"\n", - "\n", - "result_dict = {}\n", - "lines = data.strip().split('\\n')\n", - "for line in lines:\n", - " key, value = line.strip().split(' ')\n", - " result_dict[key] = value\n", - "\n", - "print(result_dict)" - ] - } - ], - "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": 5 -} diff --git a/config_jingbo.py b/config_jingbo.py index 6af9264..b18daba 100644 --- a/config_jingbo.py +++ b/config_jingbo.py @@ -197,24 +197,142 @@ ClassifyId = 1214 ################################################################################################################ 变量定义--测试环境 -login_pushreport_url = "http://192.168.100.53:8080/jingbo-dev/api/server/login" -upload_url = "http://192.168.100.53:8080/jingbo-dev/api/analysis/reportInfo/researchUploadReportSave" +# login_pushreport_url = "http://192.168.100.53:8080/jingbo-dev/api/server/login" +# upload_url = "http://192.168.100.53:8080/jingbo-dev/api/analysis/reportInfo/researchUploadReportSave" +# # upload_url = "http://192.168.100.109:8080/jingbo/api/analysis/reportInfo/researchUploadReportSave" # zhaoqiwei +# upload_warning_url = "http://192.168.100.53:8080/jingbo-dev/api/basicBuiness/crudeOilWarning/save" +# query_data_list_item_nos_url = "http://192.168.100.53:8080/jingbo-dev/api/warehouse/dwDataItem/queryDataListItemNos" + +# login_data = { +# "data": { +# "account": "api_test", +# # "password": "MmVmNzNlOWI0MmY0ZDdjZGUwNzE3ZjFiMDJiZDZjZWU=", # Shihua@123456 +# "password": "ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=", # 123456 +# "tenantHashCode": "8a4577dbd919675758d57999a1e891fe", +# "terminal": "API" +# }, +# "funcModule": "API", +# "funcOperation": "获取token" +# } + +# # upload_data = { +# # "funcModule":'研究报告信息', +# # "funcOperation":'上传原油价格预测报告', +# # "data":{ +# # "ownerAccount":'arui', #报告所属用户账号 +# # "reportType":'OIL_PRICE_FORECAST', # 报告类型,固定为OIL_PRICE_FORECAST +# # "fileName": '2000-40-5-50--100-原油指标数据.xlsx-Brent活跃合约--2024-09-06-15-01-29-预测报告.pdf', #文件名称 +# # "fileBase64": '' ,#文件内容base64 +# # "categoryNo":'yyjgycbg', # 研究报告分类编码 +# # "smartBusinessClassCode":'YCJGYCBG', #分析报告分类编码 +# # "reportEmployeeCode":"E40116", # 报告人 +# # "reportDeptCode" :"D0044" ,# 报告部门 +# # "productGroupCode":"RAW_MATERIAL" # 商品分类 +# # } +# # } + +# upload_data = { +# "funcModule":'研究报告信息', +# "funcOperation":'上传原油价格预测报告', +# "data":{ +# "ownerAccount":'arui', #报告所属用户账号 +# "reportType":'OIL_PRICE_FORECAST', # 报告类型,固定为OIL_PRICE_FORECAST +# "fileName": '2000-40-5-50--100-原油指标数据.xlsx-Brent活跃合约--2024-09-06-15-01-29-预测报告.pdf', #文件名称 +# "fileBase64": '' ,#文件内容base64 +# "categoryNo":'yyjgycbg', # 研究报告分类编码 +# "smartBusinessClassCode":'1', #分析报告分类编码 +# "reportEmployeeCode":"E40116", # 报告人 +# "reportDeptCode" :"D0044" ,# 报告部门 +# "productGroupCode":"RAW_MATERIAL" # 商品分类 +# } +# } + + +# warning_data = { +# "funcModule":'原油特征停更预警', +# "funcOperation":'原油特征停更预警', +# "data":{ +# 'WARNING_TYPE_NAME':'特征数据停更预警', +# 'WARNING_CONTENT':'', +# 'WARNING_DATE':'' +# } +# } + +# query_data_list_item_nos_data = { +# "funcModule": "数据项", +# "funcOperation": "查询", +# "data": { +# "dateStart":"20200101", +# "dateEnd":"20241231", +# "dataItemNoList":["Brentzdj","Brentzgj"] # 数据项编码,代表 brent最低价和最高价 +# } +# } + + +# # 北京环境数据库 +# host = '192.168.101.27' +# port = 3306 +# dbusername ='root' +# password = '123456' +# dbname = 'jingbo_test' +# table_name = 'v_tbl_crude_oil_warning' + + +# ### 开关 +# is_train = False # 是否训练 +# is_debug = False # 是否调试 +# is_eta = False # 是否使用eta接口 +# is_market = True # 是否通过市场信息平台获取特征 ,在is_eta 为true 的情况下生效 +# is_timefurture = True # 是否使用时间特征 +# is_fivemodels = False # 是否使用之前保存的最佳的5个模型 +# is_edbcode = False # 特征使用edbcoding列表中的 +# is_edbnamelist = False # 自定义特征,对应上面的edbnamelist +# is_update_eta = False # 预测结果上传到eta +# is_update_report = True # 是否上传报告 +# is_update_warning_data = False # 是否上传预警数据 +# is_del_corr = 0.6 # 是否删除相关性高的特征,取值为 0-1 ,0 为不删除,0.6 表示删除相关性小于0.6的特征 +# is_del_tow_month = True # 是否删除两个月不更新的特征 + + +################################################################################################################ 变量定义--雍安测试环境 +login_pushreport_url = "http://192.168.100.115:9090/dom-api/api/server/login" +upload_url = "http://192.168.100.115:9090/dom-api/api/analysis/reportInfo/researchUploadReportSave" # upload_url = "http://192.168.100.109:8080/jingbo/api/analysis/reportInfo/researchUploadReportSave" # zhaoqiwei -upload_warning_url = "http://192.168.100.53:8080/jingbo-dev/api/basicBuiness/crudeOilWarning/save" -query_data_list_item_nos_url = "http://192.168.100.53:8080/jingbo-dev/api/warehouse/dwDataItem/queryDataListItemNos" +upload_warning_url = "http://192.168.100.115:9090/dom-api/api/basicBuiness/crudeOilWarning/save" +query_data_list_item_nos_url = "http://192.168.100.115:9090/dom-api/api/warehouse/dwDataItem/queryDataListItemNos" + + + + + login_data = { "data": { - "account": "api_test", - # "password": "MmVmNzNlOWI0MmY0ZDdjZGUwNzE3ZjFiMDJiZDZjZWU=", # Shihua@123456 - "password": "ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=", # 123456 - "tenantHashCode": "8a4577dbd919675758d57999a1e891fe", + "account": "api-dev", + "password": "ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=", + "tenantHashCode": "1eb24ab5a6af12e30daf78af276664f1", "terminal": "API" }, "funcModule": "API", "funcOperation": "获取token" } +# upload_data = { +# "funcModule":'研究报告信息', +# "funcOperation":'上传原油价格预测报告', +# "data":{ +# "ownerAccount":'arui', #报告所属用户账号 +# "reportType":'OIL_PRICE_FORECAST', # 报告类型,固定为OIL_PRICE_FORECAST +# "fileName": '2000-40-5-50--100-原油指标数据.xlsx-Brent活跃合约--2024-09-06-15-01-29-预测报告.pdf', #文件名称 +# "fileBase64": '' ,#文件内容base64 +# "categoryNo":'yyjgycbg', # 研究报告分类编码 +# "smartBusinessClassCode":'YCJGYCBG', #分析报告分类编码 +# "reportEmployeeCode":"E40116", # 报告人 +# "reportDeptCode" :"D0044" ,# 报告部门 +# "productGroupCode":"RAW_MATERIAL" # 商品分类 +# } +# } + upload_data = { "funcModule":'研究报告信息', "funcOperation":'上传原油价格预测报告', @@ -224,13 +342,14 @@ upload_data = { "fileName": '2000-40-5-50--100-原油指标数据.xlsx-Brent活跃合约--2024-09-06-15-01-29-预测报告.pdf', #文件名称 "fileBase64": '' ,#文件内容base64 "categoryNo":'yyjgycbg', # 研究报告分类编码 - "smartBusinessClassCode":'YCJGYCBG', #分析报告分类编码 + "smartBusinessClassCode":'1', #分析报告分类编码 "reportEmployeeCode":"E40116", # 报告人 "reportDeptCode" :"D0044" ,# 报告部门 "productGroupCode":"RAW_MATERIAL" # 商品分类 } } + warning_data = { "funcModule":'原油特征停更预警', "funcOperation":'原油特征停更预警', @@ -271,7 +390,7 @@ is_fivemodels = False # 是否使用之前保存的最佳的5个模型 is_edbcode = False # 特征使用edbcoding列表中的 is_edbnamelist = False # 自定义特征,对应上面的edbnamelist is_update_eta = False # 预测结果上传到eta -is_update_report = False # 是否上传报告 +is_update_report = True # 是否上传报告 is_update_warning_data = False # 是否上传预警数据 is_del_corr = 0.6 # 是否删除相关性高的特征,取值为 0-1 ,0 为不删除,0.6 表示删除相关性小于0.6的特征 is_del_tow_month = True # 是否删除两个月不更新的特征 diff --git a/main_yuanyou.py b/main_yuanyou.py index 5add65e..e1be026 100644 --- a/main_yuanyou.py +++ b/main_yuanyou.py @@ -48,203 +48,203 @@ def predict_main(): 返回: None """ - global end_time - signature = BinanceAPI(APPID, SECRET) - etadata = EtaReader(signature=signature, - classifylisturl=classifylisturl, - classifyidlisturl=classifyidlisturl, - edbcodedataurl=edbcodedataurl, - edbcodelist=edbcodelist, - edbdatapushurl=edbdatapushurl, - edbdeleteurl=edbdeleteurl, - edbbusinessurl=edbbusinessurl - ) - # 获取数据 - if is_eta: - logger.info('从eta获取数据...') - signature = BinanceAPI(APPID, SECRET) - etadata = EtaReader(signature=signature, - classifylisturl=classifylisturl, - classifyidlisturl=classifyidlisturl, - edbcodedataurl=edbcodedataurl, - edbcodelist=edbcodelist, - edbdatapushurl=edbdatapushurl, - edbdeleteurl=edbdeleteurl, - edbbusinessurl=edbbusinessurl, - ) - df_zhibiaoshuju, df_zhibiaoliebiao = etadata.get_eta_api_yuanyou_data(data_set=data_set, dataset=dataset) # 原始数据,未处理 + # global end_time + # signature = BinanceAPI(APPID, SECRET) + # etadata = EtaReader(signature=signature, + # classifylisturl=classifylisturl, + # classifyidlisturl=classifyidlisturl, + # edbcodedataurl=edbcodedataurl, + # edbcodelist=edbcodelist, + # edbdatapushurl=edbdatapushurl, + # edbdeleteurl=edbdeleteurl, + # edbbusinessurl=edbbusinessurl + # ) + # # 获取数据 + # if is_eta: + # logger.info('从eta获取数据...') + # signature = BinanceAPI(APPID, SECRET) + # etadata = EtaReader(signature=signature, + # classifylisturl=classifylisturl, + # classifyidlisturl=classifyidlisturl, + # edbcodedataurl=edbcodedataurl, + # edbcodelist=edbcodelist, + # edbdatapushurl=edbdatapushurl, + # edbdeleteurl=edbdeleteurl, + # edbbusinessurl=edbbusinessurl, + # ) + # df_zhibiaoshuju, df_zhibiaoliebiao = etadata.get_eta_api_yuanyou_data(data_set=data_set, dataset=dataset) # 原始数据,未处理 - if is_market: - logger.info('从市场信息平台获取数据...') - try: - df_zhibiaoshuju = get_market_data(end_time,df_zhibiaoshuju) - except : - logger.info('从市场信息平台获取数据失败') + # if is_market: + # logger.info('从市场信息平台获取数据...') + # try: + # df_zhibiaoshuju = get_market_data(end_time,df_zhibiaoshuju) + # except : + # logger.info('从市场信息平台获取数据失败') - # 保存到xlsx文件的sheet表 - with pd.ExcelWriter(os.path.join(dataset,data_set)) as file: - df_zhibiaoshuju.to_excel(file, sheet_name='指标数据', index=False) - df_zhibiaoliebiao.to_excel(file, sheet_name='指标列表', index=False) + # # 保存到xlsx文件的sheet表 + # with pd.ExcelWriter(os.path.join(dataset,data_set)) as file: + # df_zhibiaoshuju.to_excel(file, sheet_name='指标数据', index=False) + # df_zhibiaoliebiao.to_excel(file, sheet_name='指标列表', index=False) - # 数据处理 - df = datachuli(df_zhibiaoshuju, df_zhibiaoliebiao, y=y, dataset=dataset, add_kdj=add_kdj, is_timefurture=is_timefurture, - end_time=end_time) + # # 数据处理 + # df = datachuli(df_zhibiaoshuju, df_zhibiaoliebiao, y=y, dataset=dataset, add_kdj=add_kdj, is_timefurture=is_timefurture, + # end_time=end_time) - else: - # 读取数据 - logger.info('读取本地数据:' + os.path.join(dataset, data_set)) - df,df_zhibiaoliebiao = getdata(filename=os.path.join(dataset, data_set), y=y, dataset=dataset, add_kdj=add_kdj, - is_timefurture=is_timefurture, end_time=end_time) # 原始数据,未处理 + # else: + # # 读取数据 + # logger.info('读取本地数据:' + os.path.join(dataset, data_set)) + # df,df_zhibiaoliebiao = getdata(filename=os.path.join(dataset, data_set), y=y, dataset=dataset, add_kdj=add_kdj, + # is_timefurture=is_timefurture, end_time=end_time) # 原始数据,未处理 - # 更改预测列名称 - df.rename(columns={y: 'y'}, inplace=True) + # # 更改预测列名称 + # df.rename(columns={y: 'y'}, inplace=True) - if is_edbnamelist: - df = df[edbnamelist] - df.to_csv(os.path.join(dataset, '指标数据.csv'), index=False) - # 保存最新日期的y值到数据库 - # 取第一行数据存储到数据库中 - first_row = df[['ds', 'y']].tail(1) - print(first_row['ds'].values[0]) - print(first_row['y'].values[0]) - # 判断y的类型是否为float - if not isinstance(first_row['y'].values[0], float): - logger.info(f'{end_time}预测目标数据为空,跳过') - return None + # if is_edbnamelist: + # df = df[edbnamelist] + # df.to_csv(os.path.join(dataset, '指标数据.csv'), index=False) + # # 保存最新日期的y值到数据库 + # # 取第一行数据存储到数据库中 + # first_row = df[['ds', 'y']].tail(1) + # print(first_row['ds'].values[0]) + # print(first_row['y'].values[0]) + # # 判断y的类型是否为float + # if not isinstance(first_row['y'].values[0], float): + # logger.info(f'{end_time}预测目标数据为空,跳过') + # return None - # 将最新真实值保存到数据库 - if not sqlitedb.check_table_exists('trueandpredict'): - first_row.to_sql('trueandpredict', sqlitedb.connection, index=False) - else: - for row in first_row.itertuples(index=False): - row_dict = row._asdict() - row_dict['ds'] = row_dict['ds'].strftime('%Y-%m-%d %H:%M:%S') - check_query = sqlitedb.select_data('trueandpredict', where_condition=f"ds = '{row.ds}'") - if len(check_query) > 0: - set_clause = ", ".join([f"{key} = '{value}'" for key, value in row_dict.items()]) - sqlitedb.update_data('trueandpredict', set_clause, where_condition=f"ds = '{row.ds}'") - continue - sqlitedb.insert_data('trueandpredict', tuple(row_dict.values()), columns=row_dict.keys()) + # # 将最新真实值保存到数据库 + # if not sqlitedb.check_table_exists('trueandpredict'): + # first_row.to_sql('trueandpredict', sqlitedb.connection, index=False) + # else: + # for row in first_row.itertuples(index=False): + # row_dict = row._asdict() + # row_dict['ds'] = row_dict['ds'].strftime('%Y-%m-%d %H:%M:%S') + # check_query = sqlitedb.select_data('trueandpredict', where_condition=f"ds = '{row.ds}'") + # if len(check_query) > 0: + # set_clause = ", ".join([f"{key} = '{value}'" for key, value in row_dict.items()]) + # sqlitedb.update_data('trueandpredict', set_clause, where_condition=f"ds = '{row.ds}'") + # continue + # sqlitedb.insert_data('trueandpredict', tuple(row_dict.values()), columns=row_dict.keys()) - # 更新accuracy表的y值 - if not sqlitedb.check_table_exists('accuracy'): - pass - else: - update_y = sqlitedb.select_data('accuracy',where_condition="y is null") - if len(update_y) > 0: - logger.info('更新accuracy表的y值') - # 找到update_y 中ds且df中的y的行 - update_y = update_y[update_y['ds']<=end_time] - logger.info(f'要更新y的信息:{update_y}') - try: - for row in update_y.itertuples(index=False): - row_dict = row._asdict() - yy = df[df['ds']==row_dict['ds']]['y'].values[0] - LOW = df[df['ds']==row_dict['ds']]['Brentzdj'].values[0] - HIGH = df[df['ds']==row_dict['ds']]['Brentzgj'].values[0] - sqlitedb.update_data('accuracy', f"y = {yy},LOW_PRICE = {LOW},HIGH_PRICE = {HIGH}", where_condition=f"ds = '{row_dict['ds']}'") - except Exception as e: - logger.info(f'更新accuracy表的y值失败:{e}') + # # 更新accuracy表的y值 + # if not sqlitedb.check_table_exists('accuracy'): + # pass + # else: + # update_y = sqlitedb.select_data('accuracy',where_condition="y is null") + # if len(update_y) > 0: + # logger.info('更新accuracy表的y值') + # # 找到update_y 中ds且df中的y的行 + # update_y = update_y[update_y['ds']<=end_time] + # logger.info(f'要更新y的信息:{update_y}') + # try: + # for row in update_y.itertuples(index=False): + # row_dict = row._asdict() + # yy = df[df['ds']==row_dict['ds']]['y'].values[0] + # LOW = df[df['ds']==row_dict['ds']]['Brentzdj'].values[0] + # HIGH = df[df['ds']==row_dict['ds']]['Brentzgj'].values[0] + # sqlitedb.update_data('accuracy', f"y = {yy},LOW_PRICE = {LOW},HIGH_PRICE = {HIGH}", where_condition=f"ds = '{row_dict['ds']}'") + # except Exception as e: + # logger.info(f'更新accuracy表的y值失败:{e}') - import datetime - # 判断当前日期是不是周一 - is_weekday = datetime.datetime.now().weekday() == 0 - if is_weekday: - logger.info('今天是周一,更新预测模型') - # 计算最近60天预测残差最低的模型名称 - model_results = sqlitedb.select_data('trueandpredict', order_by="ds DESC", limit="60") - # 删除空值率为40%以上的列 - if len(model_results) > 10: - model_results = model_results.dropna(thresh=len(model_results)*0.6,axis=1) - # 删除空行 - model_results = model_results.dropna() - modelnames = model_results.columns.to_list()[2:] - for col in model_results[modelnames].select_dtypes(include=['object']).columns: - model_results[col] = model_results[col].astype(np.float32) - # 计算每个预测值与真实值之间的偏差率 - for model in modelnames: - model_results[f'{model}_abs_error_rate'] = abs(model_results['y'] - model_results[model]) / model_results['y'] - # 获取每行对应的最小偏差率值 - min_abs_error_rate_values = model_results.apply(lambda row: row[[f'{model}_abs_error_rate' for model in modelnames]].min(), axis=1) - # 获取每行对应的最小偏差率值对应的列名 - min_abs_error_rate_column_name = model_results.apply(lambda row: row[[f'{model}_abs_error_rate' for model in modelnames]].idxmin(), axis=1) - # 将列名索引转换为列名 - min_abs_error_rate_column_name = min_abs_error_rate_column_name.map(lambda x: x.split('_')[0]) - # 取出现次数最多的模型名称 - most_common_model = min_abs_error_rate_column_name.value_counts().idxmax() - logger.info(f"最近60天预测残差最低的模型名称:{most_common_model}") - # 保存结果到数据库 - if not sqlitedb.check_table_exists('most_model'): - sqlitedb.create_table('most_model', columns="ds datetime, most_common_model TEXT") - sqlitedb.insert_data('most_model', (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), most_common_model,), columns=('ds', 'most_common_model',)) + # import datetime + # # 判断当前日期是不是周一 + # is_weekday = datetime.datetime.now().weekday() == 0 + # if is_weekday: + # logger.info('今天是周一,更新预测模型') + # # 计算最近60天预测残差最低的模型名称 + # model_results = sqlitedb.select_data('trueandpredict', order_by="ds DESC", limit="60") + # # 删除空值率为40%以上的列 + # if len(model_results) > 10: + # model_results = model_results.dropna(thresh=len(model_results)*0.6,axis=1) + # # 删除空行 + # model_results = model_results.dropna() + # modelnames = model_results.columns.to_list()[2:] + # for col in model_results[modelnames].select_dtypes(include=['object']).columns: + # model_results[col] = model_results[col].astype(np.float32) + # # 计算每个预测值与真实值之间的偏差率 + # for model in modelnames: + # model_results[f'{model}_abs_error_rate'] = abs(model_results['y'] - model_results[model]) / model_results['y'] + # # 获取每行对应的最小偏差率值 + # min_abs_error_rate_values = model_results.apply(lambda row: row[[f'{model}_abs_error_rate' for model in modelnames]].min(), axis=1) + # # 获取每行对应的最小偏差率值对应的列名 + # min_abs_error_rate_column_name = model_results.apply(lambda row: row[[f'{model}_abs_error_rate' for model in modelnames]].idxmin(), axis=1) + # # 将列名索引转换为列名 + # min_abs_error_rate_column_name = min_abs_error_rate_column_name.map(lambda x: x.split('_')[0]) + # # 取出现次数最多的模型名称 + # most_common_model = min_abs_error_rate_column_name.value_counts().idxmax() + # logger.info(f"最近60天预测残差最低的模型名称:{most_common_model}") + # # 保存结果到数据库 + # if not sqlitedb.check_table_exists('most_model'): + # sqlitedb.create_table('most_model', columns="ds datetime, most_common_model TEXT") + # sqlitedb.insert_data('most_model', (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), most_common_model,), columns=('ds', 'most_common_model',)) - try: - if is_weekday: - # if True: - logger.info('今天是周一,发送特征预警') - # 上传预警信息到数据库 - warning_data_df = df_zhibiaoliebiao.copy() - warning_data_df = warning_data_df[warning_data_df['停更周期']> 3 ][['指标名称', '指标id', '频度','更新周期','指标来源','最后更新时间','停更周期']] - # 重命名列名 - warning_data_df = warning_data_df.rename(columns={'指标名称': 'INDICATOR_NAME', '指标id': 'INDICATOR_ID', '频度': 'FREQUENCY', '更新周期': 'UPDATE_FREQUENCY', '指标来源': 'DATA_SOURCE', '最后更新时间': 'LAST_UPDATE_DATE', '停更周期': 'UPDATE_SUSPENSION_CYCLE'}) - from sqlalchemy import create_engine - import urllib - global password - if '@' in password: - password = urllib.parse.quote_plus(password) + # try: + # if is_weekday: + # # if True: + # logger.info('今天是周一,发送特征预警') + # # 上传预警信息到数据库 + # warning_data_df = df_zhibiaoliebiao.copy() + # warning_data_df = warning_data_df[warning_data_df['停更周期']> 3 ][['指标名称', '指标id', '频度','更新周期','指标来源','最后更新时间','停更周期']] + # # 重命名列名 + # warning_data_df = warning_data_df.rename(columns={'指标名称': 'INDICATOR_NAME', '指标id': 'INDICATOR_ID', '频度': 'FREQUENCY', '更新周期': 'UPDATE_FREQUENCY', '指标来源': 'DATA_SOURCE', '最后更新时间': 'LAST_UPDATE_DATE', '停更周期': 'UPDATE_SUSPENSION_CYCLE'}) + # from sqlalchemy import create_engine + # import urllib + # global password + # if '@' in password: + # password = urllib.parse.quote_plus(password) - engine = create_engine(f'mysql+pymysql://{dbusername}:{password}@{host}:{port}/{dbname}') - warning_data_df['WARNING_DATE'] = datetime.date.today().strftime("%Y-%m-%d %H:%M:%S") - warning_data_df['TENANT_CODE'] = 'T0004' - # 插入数据之前查询表数据然后新增id列 - existing_data = pd.read_sql(f"SELECT * FROM {table_name}", engine) - if not existing_data.empty: - max_id = existing_data['ID'].astype(int).max() - warning_data_df['ID'] = range(max_id + 1, max_id + 1 + len(warning_data_df)) - else: - warning_data_df['ID'] = range(1, 1 + len(warning_data_df)) - warning_data_df.to_sql(table_name, con=engine, if_exists='append', index=False) - if is_update_warning_data: - upload_warning_info(len(warning_data_df)) - except: - logger.info('上传预警信息到数据库失败') + # engine = create_engine(f'mysql+pymysql://{dbusername}:{password}@{host}:{port}/{dbname}') + # warning_data_df['WARNING_DATE'] = datetime.date.today().strftime("%Y-%m-%d %H:%M:%S") + # warning_data_df['TENANT_CODE'] = 'T0004' + # # 插入数据之前查询表数据然后新增id列 + # existing_data = pd.read_sql(f"SELECT * FROM {table_name}", engine) + # if not existing_data.empty: + # max_id = existing_data['ID'].astype(int).max() + # warning_data_df['ID'] = range(max_id + 1, max_id + 1 + len(warning_data_df)) + # else: + # warning_data_df['ID'] = range(1, 1 + len(warning_data_df)) + # warning_data_df.to_sql(table_name, con=engine, if_exists='append', index=False) + # if is_update_warning_data: + # upload_warning_info(len(warning_data_df)) + # except: + # logger.info('上传预警信息到数据库失败') - if is_corr: - df = corr_feature(df=df) + # if is_corr: + # df = corr_feature(df=df) - df1 = df.copy() # 备份一下,后面特征筛选完之后加入ds y 列用 - logger.info(f"开始训练模型...") - row, col = df.shape + # df1 = df.copy() # 备份一下,后面特征筛选完之后加入ds y 列用 + # logger.info(f"开始训练模型...") + # row, col = df.shape - now = datetime.datetime.now().strftime('%Y%m%d%H%M%S') - ex_Model(df, - horizon=horizon, - input_size=input_size, - train_steps=train_steps, - val_check_steps=val_check_steps, - early_stop_patience_steps=early_stop_patience_steps, - is_debug=is_debug, - dataset=dataset, - is_train=is_train, - is_fivemodels=is_fivemodels, - val_size=val_size, - test_size=test_size, - settings=settings, - now=now, - etadata=etadata, - modelsindex=modelsindex, - data=data, - is_eta=is_eta, - end_time=end_time, - ) + # now = datetime.datetime.now().strftime('%Y%m%d%H%M%S') + # ex_Model(df, + # horizon=horizon, + # input_size=input_size, + # train_steps=train_steps, + # val_check_steps=val_check_steps, + # early_stop_patience_steps=early_stop_patience_steps, + # is_debug=is_debug, + # dataset=dataset, + # is_train=is_train, + # is_fivemodels=is_fivemodels, + # val_size=val_size, + # test_size=test_size, + # settings=settings, + # now=now, + # etadata=etadata, + # modelsindex=modelsindex, + # data=data, + # is_eta=is_eta, + # end_time=end_time, + # ) - logger.info('模型训练完成') + # logger.info('模型训练完成') - logger.info('训练数据绘图ing') - model_results3 = model_losss(sqlitedb,end_time=end_time) - logger.info('训练数据绘图end') + # logger.info('训练数据绘图ing') + # model_results3 = model_losss(sqlitedb,end_time=end_time) + # logger.info('训练数据绘图end') # 模型报告 logger.info('制作报告ing') diff --git a/models/nerulforcastmodels.py b/models/nerulforcastmodels.py index d91afb9..0181609 100644 --- a/models/nerulforcastmodels.py +++ b/models/nerulforcastmodels.py @@ -945,14 +945,14 @@ def brent_export_pdf(num_indicators=475,num_models=21, num_dayindicator=202,inpu content.append(Graphs.draw_img(os.path.join(dataset,'历史价格-预测值.png'))) # 波动率画图逻辑 content.append(Graphs.draw_text('图示说明:')) - content.append(Graphs.draw_text(' 确定波动率置信区间:设置残差置信阈值,以每周最佳模型为基准,选取在置信区间的预测值作为置信区间;')) + content.append(Graphs.draw_text(' 确定置信区间:设置残差置信阈值,以每周最佳模型为基准,选取在置信区间的预测值作为置信区间;')) # 添加历史走势及预测价格的走势图片 content.append(Graphs.draw_img(os.path.join(dataset,'历史价格-预测值1.png'))) content.append(Graphs.draw_text('图示说明:')) - content.append(Graphs.draw_text(' 确定波动率置信区间:使用模型评估指标MAE得到前十个模型,取平均值上下1.5作为价格波动置信区间;')) - + content.append(Graphs.draw_text(' 确定置信区间:使用模型评估指标MAE得到前十个模型,取平均值上下1.5作为价格波动置信区间;')) + # 取df中y列为空的行 import pandas as pd