|
@@ -304,7 +304,7 @@ func HandleTaskRecordSuccessByTaskRecord(taskType string, indexTaskRecordInfo *m
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- handleTaskRecordSuccessByTrain(indexConfigItem, indexItem)
|
|
|
|
|
|
+ handleTaskRecordSuccessByTrain(aiPredictModelImportData, indexConfigItem, indexItem)
|
|
|
|
|
|
case utils.INDEX_TASK_TYPE_AI_MODEL_RUN: // 运行模型
|
|
case utils.INDEX_TASK_TYPE_AI_MODEL_RUN: // 运行模型
|
|
|
|
|
|
@@ -335,27 +335,74 @@ func HandleTaskRecordSuccessByTaskRecord(taskType string, indexTaskRecordInfo *m
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func handleTaskRecordSuccessByTrain(indexConfigItem *aiPredictModel.AiPredictModelIndexConfig, indexItem *aiPredictModel.AiPredictModelIndex) {
|
|
|
|
- // 修改模型状态信息
|
|
|
|
- if indexItem != nil {
|
|
|
|
- indexItem.TrainStatus = aiPredictModel.TrainStatusSuccess
|
|
|
|
- indexItem.ModifyTime = time.Now()
|
|
|
|
- tmpErr := indexItem.Update([]string{"train_status", "modify_time"})
|
|
|
|
- if tmpErr != nil {
|
|
|
|
- utils.FileLog.Error("%d,修改模型训练状态失败, err: %s", indexItem.AiPredictModelIndexId, tmpErr.Error())
|
|
|
|
|
|
+// handleTaskRecordSuccessByTrain
|
|
|
|
+// @Description: 处理模型训练成功后的操作
|
|
|
|
+// @author: Roc
|
|
|
|
+// @datetime 2025-05-14 18:25:12
|
|
|
|
+// @param aiPredictModelImportData request.AiPredictModelImportData
|
|
|
|
+// @param indexConfigItem *aiPredictModel.AiPredictModelIndexConfig
|
|
|
|
+// @param indexItem *aiPredictModel.AiPredictModelIndex
|
|
|
|
+// @return err error
|
|
|
|
+func handleTaskRecordSuccessByTrain(aiPredictModelImportData request.AiPredictModelImportData, indexConfigItem *aiPredictModel.AiPredictModelIndexConfig, indexItem *aiPredictModel.AiPredictModelIndex) (err error) {
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Error(fmt.Sprintf(`handleTaskRecordSuccessByTrain err:%v`, err))
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }()
|
|
|
|
|
|
- // 修改模型配置状态信息
|
|
|
|
- if indexConfigItem != nil {
|
|
|
|
|
|
+ // 标的状态修改
|
|
|
|
+ updateIndexCols := []string{"train_status", "modify_time"}
|
|
|
|
+ indexItem.TrainStatus = aiPredictModel.TrainStatusSuccess
|
|
|
|
+ indexItem.ModifyTime = time.Now()
|
|
|
|
+
|
|
|
|
+ updateIndexConfigCols := []string{"train_status", `remark`, "modify_time", `train_mse`, `train_r2`, `test_mse`, `test_r2`}
|
|
|
|
+ // 配置状态修改
|
|
|
|
+ {
|
|
|
|
+ // 训练参数
|
|
|
|
+ trainData := aiPredictModelImportData.TrainData
|
|
indexConfigItem.TrainStatus = aiPredictModel.TrainStatusSuccess
|
|
indexConfigItem.TrainStatus = aiPredictModel.TrainStatusSuccess
|
|
indexConfigItem.Remark = `成功`
|
|
indexConfigItem.Remark = `成功`
|
|
|
|
+ indexConfigItem.TrainMse = fmt.Sprint(trainData.TrainMse)
|
|
|
|
+ indexConfigItem.TrainR2 = fmt.Sprint(trainData.TrainR2)
|
|
|
|
+ indexConfigItem.TestMse = fmt.Sprint(trainData.TestMse)
|
|
|
|
+ indexConfigItem.TestR2 = fmt.Sprint(trainData.TestR2)
|
|
indexConfigItem.ModifyTime = time.Now()
|
|
indexConfigItem.ModifyTime = time.Now()
|
|
- tmpErr := indexConfigItem.Update([]string{"train_status", `remark`, "modify_time"})
|
|
|
|
- if tmpErr != nil {
|
|
|
|
- utils.FileLog.Error("%d,修改模型训练状态失败, err: %s", indexItem.AiPredictModelIndexId, tmpErr.Error())
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ indexConfigOb := new(aiPredictModel.AiPredictModelIndexConfig)
|
|
|
|
+
|
|
|
|
+ dataList := make([]*aiPredictModel.AiPredictModelIndexConfigTrainData, 0)
|
|
|
|
+ for _, tmpData := range aiPredictModelImportData.Data {
|
|
|
|
+ tmpDate, e := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
|
|
|
|
+ if e != nil {
|
|
|
|
+ err = fmt.Errorf("数据日期解析失败, %v", e)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ dataList = append(dataList, &aiPredictModel.AiPredictModelIndexConfigTrainData{
|
|
|
|
+ //AiPredictModelDataId: 0,
|
|
|
|
+ AiPredictModelIndexConfigId: indexConfigItem.AiPredictModelIndexConfigId,
|
|
|
|
+ AiPredictModelIndexId: indexItem.AiPredictModelIndexId,
|
|
|
|
+ IndexCode: indexItem.IndexCode,
|
|
|
|
+ DataTime: tmpDate,
|
|
|
|
+ Value: tmpData.Value,
|
|
|
|
+ PredictValue: tmpData.PredictValue,
|
|
|
|
+ Direction: tmpData.Direction,
|
|
|
|
+ DeviationRate: tmpData.DeviationRate,
|
|
|
|
+ CreateTime: time.Now(),
|
|
|
|
+ ModifyTime: time.Now(),
|
|
|
|
+ DataTimestamp: tmpData.DataTimestamp,
|
|
|
|
+ Source: tmpData.Source,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新指标和数据
|
|
|
|
+ err = indexConfigOb.UpdateIndexAndData(indexItem, indexConfigItem, dataList, updateIndexCols, updateIndexConfigCols)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// handleTaskRecordSuccessByRun
|
|
// handleTaskRecordSuccessByRun
|
|
@@ -373,19 +420,8 @@ func handleTaskRecordSuccessByRun(aiPredictModelImportData request.AiPredictMode
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
}()
|
|
}()
|
|
- // 查询已存在的标的
|
|
|
|
|
|
+
|
|
indexOb := new(aiPredictModel.AiPredictModelIndex)
|
|
indexOb := new(aiPredictModel.AiPredictModelIndex)
|
|
- indexNameItem := make(map[string]*aiPredictModel.AiPredictModelIndex)
|
|
|
|
- {
|
|
|
|
- list, e := indexOb.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
|
|
|
|
- if e != nil {
|
|
|
|
- err = fmt.Errorf("获取标的失败, %v", e)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- for _, v := range list {
|
|
|
|
- indexNameItem[v.IndexName] = v
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
updateCols := []string{indexOb.Cols().RunStatus, indexOb.Cols().PredictValue, indexOb.Cols().DirectionAccuracy, indexOb.Cols().AbsoluteDeviation, indexOb.Cols().ExtraConfig, indexOb.Cols().ModifyTime}
|
|
updateCols := []string{indexOb.Cols().RunStatus, indexOb.Cols().PredictValue, indexOb.Cols().DirectionAccuracy, indexOb.Cols().AbsoluteDeviation, indexOb.Cols().ExtraConfig, indexOb.Cols().ModifyTime}
|
|
|
|
|
|
@@ -444,7 +480,7 @@ func handleTaskRecordSuccessByRun(aiPredictModelImportData request.AiPredictMode
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- // 更新指标
|
|
|
|
|
|
+ // 更新指标和数据
|
|
err = indexOb.UpdateIndexAndData(indexItem, dataList, updateCols)
|
|
err = indexOb.UpdateIndexAndData(indexItem, dataList, updateCols)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|