聚烯烃保存数据逻辑更改,更新数据库改为删除数据库,

This commit is contained in:
liurui 2024-11-26 13:18:25 +08:00
parent 2f0c2a94fa
commit 22842b5710
8 changed files with 7911 additions and 21982 deletions

View File

@ -17,10 +17,7 @@
"id": "07e338e7-1dd1-417f-b4e2-65d0efc983d6", "id": "07e338e7-1dd1-417f-b4e2-65d0efc983d6",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": []
"df = pd.read_csv(os.path.join(dataset,'last_update_times.csv'))\n",
"df = df.sort_values(by=['warning_date'], ascending=[False])"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",

View File

@ -211,7 +211,7 @@ upload_data = {
### 开关 ### 开关
is_train = True # 是否训练 is_train = True # 是否训练
is_debug = False # 是否调试 is_debug = False # 是否调试
is_eta = True # 是否使用eta接口 is_eta = False # 是否使用eta接口
is_timefurture = True # 是否使用时间特征 is_timefurture = True # 是否使用时间特征
is_fivemodels = False # 是否使用之前保存的最佳的5个模型 is_fivemodels = False # 是否使用之前保存的最佳的5个模型
is_edbcode = False # 特征使用edbcoding列表中的 is_edbcode = False # 特征使用edbcoding列表中的

View File

@ -425,6 +425,11 @@ class SQLiteHandler:
result = self.execute_query(query).fetchone() result = self.execute_query(query).fetchone()
return result is not None return result is not None
def drop_table(self, table_name):
query = f"DROP TABLE IF EXISTS {table_name}"
self.execute_query(query)
self.commit()
def add_column_if_not_exists(self, table_name, column_name, column_type): def add_column_if_not_exists(self, table_name, column_name, column_type):
# 查询表结构 # 查询表结构
query = f"PRAGMA table_info({table_name})" query = f"PRAGMA table_info({table_name})"

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,7 @@ def predict_main():
import datetime import datetime
# 判断当前日期是不是周一 # 判断当前日期是不是周一
is_weekday = datetime.datetime.now().weekday() == 1 is_weekday = datetime.datetime.now().weekday() == 0
if is_weekday: if is_weekday:
logger.info('今天是周一,更新预测模型') logger.info('今天是周一,更新预测模型')
# 计算最近20天预测残差最低的模型名称 # 计算最近20天预测残差最低的模型名称

View File

@ -657,23 +657,10 @@ def model_losss_juxiting(sqlitedb):
pass pass
df_combined3.to_csv(os.path.join(dataset,"testandpredict_groupby.csv"),index=False) df_combined3.to_csv(os.path.join(dataset,"testandpredict_groupby.csv"),index=False)
# 历史价格+预测价格
# 将预测结果保存到数据库
# 判断表存在
if not sqlitedb.check_table_exists('testandpredict_groupby'):
df_combined3.to_sql('testandpredict_groupby',sqlitedb.connection,index=False)
else:
for row in df_combined3.itertuples(index=False):
row_dict = row._asdict()
print(row_dict)
check_query = sqlitedb.select_data('testandpredict_groupby',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('testandpredict_groupby',set_clause,where_condition = f"ds = '{row.ds}'")
continue
row_dict['ds'] = row.ds.strftime('%Y-%m-%d 00:00:00')
sqlitedb.insert_data('testandpredict_groupby',tuple(row_dict.values()),columns=row_dict.keys())
# 历史价格+预测价格
sqlitedb.drop_table('testandpredict_groupby')
df_combined3.to_sql('testandpredict_groupby',sqlitedb.connection,index=False)
def _plt_predict_ture(df): def _plt_predict_ture(df):
lens = df.shape[0] if df.shape[0] < 180 else 90 lens = df.shape[0] if df.shape[0] < 180 else 90