255 lines
9.3 KiB
Python
255 lines
9.3 KiB
Python
import logging
|
||
import os
|
||
import logging.handlers
|
||
import datetime
|
||
|
||
|
||
# eta 接口token
|
||
APPID = "XNLDvxZHHugj7wJ7"
|
||
SECRET = "iSeU4s6cKKBVbt94htVY1p0sqUMqb2xa"
|
||
|
||
# eta 接口url
|
||
sourcelisturl = 'http://10.189.2.78:8108/v1/edb/source/list'
|
||
classifylisturl = 'http://10.189.2.78:8108/v1/edb/classify/list?ClassifyType='
|
||
uniquecodedataurl = 'http://10.189.2.78:8108/v1/edb/data?UniqueCode=4991c37becba464609b409909fe4d992&StartDate=2024-02-01'
|
||
classifyidlisturl = 'http://10.189.2.78:8108/v1/edb/list?ClassifyId='
|
||
edbcodedataurl = 'http://10.189.2.78:8108/v1/edb/data?EdbCode='
|
||
edbdatapushurl = 'http://10.189.2.78:8108/v1/edb/push'
|
||
edbdeleteurl = 'http://10.189.2.78:8108/v1/edb/business/edb/del'
|
||
edbbusinessurl = 'http://10.189.2.78:8108/v1/edb/business/data/del'
|
||
edbcodelist = ['CO1 Comdty', 'ovx index', 'C2404194834', 'C2404199738', 'dxy curncy', 'C2403128043', 'C2403150124',
|
||
'DOESCRUD Index', 'WTRBM1 EEGC Index', 'FVHCM1 INDEX', 'doedtprd index', 'CFFDQMMN INDEX',
|
||
'C2403083739', 'C2404167878', 'C2403250571', 'lmcads03 lme comdty', 'GC1 COMB Comdty',
|
||
'C2404171822','C2404167855']
|
||
|
||
# 临时写死用指定的列,与上面的edbcode对应,后面更改
|
||
edbnamelist = [
|
||
'ds','y',
|
||
'Brent c1-c6','Brent c1-c3','Brent-WTI','美国商业原油库存',
|
||
'DFL','美国汽油裂解价差','ovx index','dxy curncy','lmcads03 lme comdty',
|
||
'C2403128043','C2403150124','FVHCM1 INDEX','doedtprd index','CFFDQMMN INDEX',
|
||
'C2403083739','C2404167878',
|
||
'GC1 COMB Comdty','C2404167855'
|
||
]
|
||
|
||
|
||
|
||
# eta自有数据指标编码
|
||
modelsindex = {
|
||
'NHITS': 'SELF0000001',
|
||
'Informer':'SELF0000057',
|
||
'LSTM':'SELF0000058',
|
||
'iTransformer':'SELF0000059',
|
||
'TSMixer':'SELF0000060',
|
||
'TSMixerx':'SELF0000061',
|
||
'PatchTST':'SELF0000062',
|
||
'RNN':'SELF0000063',
|
||
'GRU':'SELF0000064',
|
||
'TCN':'SELF0000065',
|
||
'BiTCN':'SELF0000066',
|
||
'DilatedRNN':'SELF0000067',
|
||
'MLP':'SELF0000068',
|
||
'DLinear':'SELF0000069',
|
||
'NLinear':'SELF0000070',
|
||
'TFT':'SELF0000071',
|
||
'FEDformer':'SELF0000072',
|
||
'StemGNN':'SELF0000073',
|
||
'MLPMultivariate':'SELF0000074',
|
||
'TiDE':'SELF0000075',
|
||
'DeepNPTS':'SELF0000076'
|
||
}
|
||
|
||
# eta 上传预测结果的请求体,后面发起请求的时候更改 model datalist 数据
|
||
data = {
|
||
"IndexCode": "",
|
||
"IndexName": "价格预测模型",
|
||
"Unit": "无",
|
||
"Frequency": "日度",
|
||
"SourceName": f"价格预测",
|
||
"Remark": 'ddd',
|
||
"DataList": [
|
||
{
|
||
"Date": "2024-05-02",
|
||
"Value": 333444
|
||
}
|
||
]
|
||
}
|
||
|
||
# eta 分类
|
||
# level:3才可以获取到数据,所以需要人工把能源化工下所有的level3级都找到
|
||
# url = 'http://10.189.2.78:8108/v1/edb/list?ClassifyId=1214'
|
||
#ParentId ":1160, 能源化工
|
||
# ClassifyId ":1214,原油
|
||
#ParentId ":1214,",就是原油下所有的数据。
|
||
ClassifyId = 1214
|
||
|
||
|
||
### 报告上传配置
|
||
# 变量定义--线上环境
|
||
login_pushreport_url = "http://10.200.32.39/jingbo-api/api/server/login"
|
||
upload_url = "http://10.200.32.39/jingbo-api/api/analysis/reportInfo/researchUploadReportSave"
|
||
|
||
login_data = {
|
||
"data": {
|
||
"account": "api_dev",
|
||
"password": "ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=",
|
||
"tenantHashCode": "8a4577dbd919675758d57999a1e891fe",
|
||
"terminal": "API"
|
||
},
|
||
"funcModule": "API",
|
||
"funcOperation": "获取token"
|
||
}
|
||
|
||
|
||
|
||
upload_data = {
|
||
"funcModule":'研究报告信息',
|
||
"funcOperation":'上传原油价格预测报告',
|
||
"data":{
|
||
"ownerAccount":'27663', #报告所属用户账号 27663 - 刘小朋
|
||
"reportType":'OIL_PRICE_FORECAST', # 报告类型,固定为OIL_PRICE_FORECAST
|
||
"fileName": '', #文件名称
|
||
"fileBase64": '' ,#文件内容base64
|
||
"categoryNo":'yyjgycbg', # 研究报告分类编码
|
||
"smartBusinessClassCode":'YCJGYCBG', #分析报告分类编码
|
||
"reportEmployeeCode":"E40482" ,# 报告人 E40482 - 管理员 0000027663 - 刘小朋
|
||
"reportDeptCode" :"002000621000", # 报告部门 - 002000621000 SH期货研究部
|
||
"productGroupCode":"RAW_MATERIAL" # 商品分类
|
||
}
|
||
}
|
||
|
||
|
||
|
||
# # 变量定义--测试环境
|
||
# 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
|
||
|
||
|
||
# login_data = {
|
||
# "data": {
|
||
# "account": "api_test",
|
||
# "password": "MmVmNzNlOWI0MmY0ZDdjZGUwNzE3ZjFiMDJiZDZjZWU=",
|
||
# "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" # 商品分类
|
||
# }
|
||
# }
|
||
|
||
|
||
### 线上开关
|
||
# is_train = True # 是否训练
|
||
# is_debug = False # 是否调试
|
||
# is_eta = True # 是否使用eta接口
|
||
# is_timefurture = True # 是否使用时间特征
|
||
# is_fivemodels = False # 是否使用之前保存的最佳的5个模型
|
||
# is_edbcode = False # 特征使用edbcoding列表中的
|
||
# is_edbnamelist = False # 自定义特征,对应上面的edbnamelist
|
||
# is_update_eta = True # 预测结果上传到eta
|
||
# is_update_report = True # 是否上传报告
|
||
|
||
### 开关
|
||
is_train = True # 是否训练
|
||
is_debug = False # 是否调试
|
||
is_eta = True # 是否使用eta接口
|
||
is_timefurture = True # 是否使用时间特征
|
||
is_fivemodels = False # 是否使用之前保存的最佳的5个模型
|
||
is_edbcode = False # 特征使用edbcoding列表中的
|
||
is_edbnamelist = False # 自定义特征,对应上面的edbnamelist
|
||
is_update_eta = False # 预测结果上传到eta
|
||
is_update_report = False # 是否上传报告
|
||
|
||
|
||
# 数据截取日期
|
||
end_time = '' # 数据截取日期
|
||
delweekenday = True
|
||
is_corr = False # 特征是否参与滞后领先提升相关系数
|
||
add_kdj = False # 是否添加kdj指标
|
||
if add_kdj and is_edbnamelist:
|
||
edbnamelist = edbnamelist+['K','D','J']
|
||
### 模型参数
|
||
y = 'Brent活跃合约' # 原油指标数据的目标变量
|
||
# y = '期货结算价(连续):布伦特原油:前一个观测值' # ineoil的目标变量
|
||
horizon =5 # 预测的步长
|
||
input_size = 40 # 输入序列长度
|
||
train_steps = 50 if is_debug else 1000 # 训练步数,用来限定epoch次数
|
||
val_check_steps = 30 # 评估频率
|
||
early_stop_patience_steps = 5 # 早停的耐心步数
|
||
# --- 交叉验证用的参数
|
||
test_size = 200 # 测试集大小,定义100,后面使用的时候重新赋值
|
||
val_size = test_size # 验证集大小,同测试集大小
|
||
|
||
### 特征筛选用到的参数
|
||
k = 100 # 特征筛选数量,如果是0或者值比特征数量大,代表全部特征
|
||
|
||
|
||
|
||
### 文件
|
||
data_set = '原油指标数据.xlsx' # 数据集文件
|
||
# data_set = 'INE_OIL(1).csv'
|
||
### 文件夹
|
||
dataset = 'dataset' # 数据集文件夹
|
||
|
||
# 数据库名称
|
||
db_name = os.path.join(dataset,'jbsh_yuanyou.db')
|
||
|
||
settings = f'{input_size}-{horizon}-{train_steps}--{k}-{data_set}-{y}'
|
||
# 获取日期时间
|
||
now = datetime.datetime.now().strftime('%Y%m%d%H%M%S') # 获取当前日期时间
|
||
# now = datetime.datetime.now().strftime('%Y-%m-%d') # 获取当前日期时间
|
||
reportname = f'Brent原油大模型预测--{now}.pdf' # 报告文件名
|
||
reportname = reportname.replace(':', '-') # 替换冒号
|
||
|
||
### 邮件配置
|
||
username='1321340118@qq.com'
|
||
passwd='wgczgyhtyyyyjghi'
|
||
# recv=['liurui_test@163.com','52585119@qq.com']
|
||
recv=['liurui_test@163.com']
|
||
title='reportname'
|
||
content='brent价格预测报告请看附件'
|
||
file=os.path.join(dataset,'reportname')
|
||
# file=os.path.join(dataset,'14-7-50--100-原油指标数据.xlsx-Brent连1合约价格--20240731175936-预测报告.pdf')
|
||
ssl=True
|
||
|
||
|
||
### 日志配置
|
||
|
||
# 创建日志目录(如果不存在)
|
||
log_dir = 'logs'
|
||
if not os.path.exists(log_dir):
|
||
os.makedirs(log_dir)
|
||
|
||
# 配置日志记录器
|
||
logger = logging.getLogger('my_logger')
|
||
logger.setLevel(logging.INFO)
|
||
|
||
# 配置文件处理器,将日志记录到文件
|
||
file_handler = logging.handlers.RotatingFileHandler(os.path.join(log_dir, 'pricepredict.log'), maxBytes=1024 * 1024, backupCount=5)
|
||
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
||
|
||
# 配置控制台处理器,将日志打印到控制台
|
||
console_handler = logging.StreamHandler()
|
||
console_handler.setFormatter(logging.Formatter('%(message)s'))
|
||
|
||
# 将处理器添加到日志记录器
|
||
logger.addHandler(file_handler)
|
||
logger.addHandler(console_handler)
|
||
|
||
# logger.info('当前配置:'+settings) |