添加市场信息接口到数据特征文件
This commit is contained in:
parent
c074f1eeae
commit
0c13c27173
@ -214,13 +214,12 @@ warning_data = {
|
||||
}
|
||||
|
||||
query_data_list_item_nos_data = {
|
||||
"funcModule":'数据项管理',
|
||||
"funcOperation":'查询数据项编码',
|
||||
"data":{
|
||||
"dataItemNoList":['Brent活跃合约',''],
|
||||
"dateEnd":'',
|
||||
"dateStart":'2023-01-01'
|
||||
|
||||
"funcModule": "数据项",
|
||||
"funcOperation": "查询",
|
||||
"data": {
|
||||
"dateStart":"20200101",
|
||||
"dateEnd":"20241231",
|
||||
"dataItemNoList":["Brentzdj","Brentzgj"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,6 +237,7 @@ table_name = 'v_tbl_crude_oil_warning'
|
||||
is_train = False # 是否训练
|
||||
is_debug = False # 是否调试
|
||||
is_eta = True # 是否使用eta接口
|
||||
is_market = True # 是否通过市场信息平台获取特征 ,在is_eta 为true 的情况下生效
|
||||
is_timefurture = True # 是否使用时间特征
|
||||
is_fivemodels = False # 是否使用之前保存的最佳的5个模型
|
||||
is_edbcode = False # 特征使用edbcoding列表中的
|
||||
|
@ -1639,6 +1639,33 @@ class EtaReader():
|
||||
raise Exception(f'Error: {response.status_code}, {response.text}')
|
||||
|
||||
|
||||
def get_market_data(end_time,df):
|
||||
"""
|
||||
获取市场数据,拼接到df中
|
||||
"""
|
||||
# 获取token
|
||||
token = get_head_auth_report()
|
||||
# 定义请求参数
|
||||
query_data_list_item_nos_data['data']['dateEnd'] = end_time.replace('-','')
|
||||
# 发送请求
|
||||
headers = {"Authorization": token}
|
||||
items_res = requests.post(url=query_data_list_item_nos_url, headers=headers, json=query_data_list_item_nos_data, timeout=(3, 35))
|
||||
json_data = json.loads(items_res.text)
|
||||
df = pd.DataFrame(json_data['data'])
|
||||
# 按照dataItemNo 分组 得到多个dataframe ,最后根据dataDate merge 成一个dataframe
|
||||
df2 = pd.DataFrame()
|
||||
for i in df['dataItemNo'].unique():
|
||||
df1 = df[df['dataItemNo'] == i]
|
||||
df1 = df1[['dataDate', 'dataValue']]
|
||||
df1 = df1.rename(columns={'dataValue': i})
|
||||
df2 = pd.concat([df2, df1], axis=0)
|
||||
df2 = df2.rename(columns={'dataDate': 'ds'})
|
||||
# 20240101 转换为 2024-01-01
|
||||
df2['ds'] = pd.to_datetime(df2['ds'], format='%Y%m%d')
|
||||
df2['ds'] = df2['ds'].dt.strftime('%Y-%m-%d')
|
||||
df = pd.merge(df, df2, how='outer',on='ds')
|
||||
return df
|
||||
|
||||
# 时间特征,年,月,一年的多少天,周几,第几周,第几季度,每月的第几天, 每季度的第几天,是否每月的第一天,是否每月的最后一天,是否每季度的第一天,是否每季度的最后一天,是否每年的第一天,是否每年的最后一天
|
||||
def addtimecharacteristics(df,dataset):
|
||||
"""
|
||||
|
@ -74,6 +74,10 @@ def predict_main():
|
||||
)
|
||||
df_zhibiaoshuju, df_zhibiaoliebiao = etadata.get_eta_api_yuanyou_data(data_set=data_set, dataset=dataset) # 原始数据,未处理
|
||||
|
||||
if is_market:
|
||||
logger.info('从市场信息平台获取数据...')
|
||||
df_zhibiaoshuju = get_market_data(end_time,df_zhibiaoshuju)
|
||||
|
||||
# 数据处理
|
||||
df = datachuli(df_zhibiaoshuju, df_zhibiaoliebiao, y=y, dataset=dataset, add_kdj=add_kdj, is_timefurture=is_timefurture,
|
||||
end_time=end_time)
|
||||
@ -94,11 +98,11 @@ def predict_main():
|
||||
# 取第一行数据存储到数据库中
|
||||
first_row = df[['ds', 'y']].tail(1)
|
||||
# 判断ds是否与ent_time 一致且 y 不为空
|
||||
if len(first_row) > 0 and first_row['y'].values[0] is not None:
|
||||
if first_row['ds'].values[0] == end_time and not np.isnan(first_row['y'].values[0]):
|
||||
pass
|
||||
else:
|
||||
logger.info('{end_time}预测目标数据为空,跳过')
|
||||
return
|
||||
logger.info(f'{end_time}预测目标数据为空,跳过')
|
||||
return None
|
||||
# 将最新真实值保存到数据库
|
||||
if not sqlitedb.check_table_exists('trueandpredict'):
|
||||
first_row.to_sql('trueandpredict', sqlitedb.connection, index=False)
|
||||
@ -190,7 +194,6 @@ def predict_main():
|
||||
except:
|
||||
logger.info('上传预警信息到数据库失败')
|
||||
|
||||
|
||||
if is_corr:
|
||||
df = corr_feature(df=df)
|
||||
|
||||
@ -263,7 +266,7 @@ if __name__ == '__main__':
|
||||
global end_time
|
||||
is_on = True
|
||||
# 遍历2024-11-25 到 2024-12-3 之间的工作日日期
|
||||
for i_time in pd.date_range('2024-12-25', '2024-12-26', freq='B'):
|
||||
for i_time in pd.date_range('2024-12-24', '2024-12-26', freq='B'):
|
||||
end_time = i_time.strftime('%Y-%m-%d')
|
||||
predict_main()
|
||||
if is_on:
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user