|
@@ -8,10 +8,11 @@ import (
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-func ImportAiPredictModelIndexAndData(imports []*aiPredictModel.AiPredictModelImportData) (err error) {
|
|
|
+func ImportAiPredictModelIndexAndData(imports []*aiPredictModel.AiPredictModelImportData, adminId int, adminRealName string) (err error) {
|
|
|
if len(imports) == 0 {
|
|
|
return
|
|
|
}
|
|
@@ -59,21 +60,33 @@ func ImportAiPredictModelIndexAndData(imports []*aiPredictModel.AiPredictModelIm
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- // 新增
|
|
|
+ // 新增标的/图表
|
|
|
indexCode, e := utils.GenerateEdbCode(1, "IPM")
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("生成标的编码失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
v.Index.IndexCode = indexCode
|
|
|
+ v.Charts = GetAiPredictCharts(v.Index.IndexName, adminId, adminRealName)
|
|
|
createIndexes = append(createIndexes, v)
|
|
|
}
|
|
|
|
|
|
// 新增/更新指标
|
|
|
- if e := indexOb.ImportIndexAndData(createIndexes, updateIndexes, updateCols); e != nil {
|
|
|
+ chartIds, e := indexOb.ImportIndexAndData(createIndexes, updateIndexes, updateCols)
|
|
|
+ if e != nil {
|
|
|
err = fmt.Errorf("导入指标失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 更新图表ES
|
|
|
+ if len(chartIds) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ go func() {
|
|
|
+ for _, v := range chartIds {
|
|
|
+ data.EsAddOrEditChartInfo(v)
|
|
|
+ }
|
|
|
+ }()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -114,8 +127,28 @@ func GetAiPredictChartDetailByData(indexItem *aiPredictModel.AiPredictModelIndex
|
|
|
confLeftMax = indexItem.LeftMax
|
|
|
}
|
|
|
|
|
|
+ // 获取指标对应的图表
|
|
|
+ chartSourceMapping := map[int]int{
|
|
|
+ aiPredictModel.ModelDataSourceMonthly: utils.CHART_SOURCE_AI_PREDICT_MODEL_MONTHLY,
|
|
|
+ aiPredictModel.ModelDataSourceDaily: utils.CHART_SOURCE_AI_PREDICT_MODEL_DAILY,
|
|
|
+ }
|
|
|
+ chartInfo, e := data_manage.GetAiPredictChartInfoByIndexId(chartSourceMapping[source], indexItem.AiPredictModelIndexId)
|
|
|
+ if e != nil && !utils.IsErrNoRow(e) {
|
|
|
+ err = fmt.Errorf("获取标的图表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 获取曲线图主题样式
|
|
|
chartView := new(data_manage.ChartInfoView)
|
|
|
+ if chartInfo != nil && chartInfo.ChartInfoId > 0 {
|
|
|
+ chartView.ChartInfoId = chartInfo.ChartInfoId
|
|
|
+ chartView.ChartName = chartInfo.ChartName
|
|
|
+ chartView.ChartNameEn = chartInfo.ChartNameEn
|
|
|
+ chartView.Source = chartInfo.Source
|
|
|
+ } else {
|
|
|
+ chartView.ChartName = indexItem.IndexName
|
|
|
+ chartView.ChartNameEn = indexItem.IndexName
|
|
|
+ }
|
|
|
chartView.ChartType = utils.CHART_SOURCE_DEFAULT
|
|
|
chartTheme, e := data.GetChartThemeConfig(0, chartView.ChartType, utils.CHART_TYPE_CURVE)
|
|
|
if e != nil {
|
|
@@ -264,3 +297,136 @@ func GetAiPredictChartDetailByData(indexItem *aiPredictModel.AiPredictModelIndex
|
|
|
resp.EdbInfoList = edbList
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetAiPredictCharts 获取AI预测模型图表
|
|
|
+func GetAiPredictCharts(indexName string, adminId int, adminRealName string) (charts []*aiPredictModel.AiPredictModelImportCharts) {
|
|
|
+ charts = make([]*aiPredictModel.AiPredictModelImportCharts, 0)
|
|
|
+
|
|
|
+ // 日度/月度图表
|
|
|
+ frequencyArr := []int{aiPredictModel.ModelDataSourceMonthly, aiPredictModel.ModelDataSourceDaily}
|
|
|
+ sourceMapping := map[int]int{
|
|
|
+ aiPredictModel.ModelDataSourceMonthly: utils.CHART_SOURCE_AI_PREDICT_MODEL_MONTHLY,
|
|
|
+ aiPredictModel.ModelDataSourceDaily: utils.CHART_SOURCE_AI_PREDICT_MODEL_DAILY,
|
|
|
+ }
|
|
|
+ suffixNameMapping := map[int]string{
|
|
|
+ aiPredictModel.ModelDataSourceMonthly: "预测模型/回测",
|
|
|
+ aiPredictModel.ModelDataSourceDaily: "预测模型",
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range frequencyArr {
|
|
|
+ chartSource := sourceMapping[v]
|
|
|
+ newChart := new(aiPredictModel.AiPredictModelImportCharts)
|
|
|
+
|
|
|
+ // 新增图表
|
|
|
+ chartName := fmt.Sprintf("%s%s", indexName, suffixNameMapping[v])
|
|
|
+ chartInfo := new(data_manage.ChartInfo)
|
|
|
+ chartInfo.ChartName = chartName
|
|
|
+ chartInfo.ChartNameEn = chartName
|
|
|
+ chartInfo.ChartType = utils.CHART_TYPE_CURVE
|
|
|
+ chartInfo.Calendar = "公历"
|
|
|
+ chartInfo.SysUserId = adminId
|
|
|
+ chartInfo.SysUserRealName = adminRealName
|
|
|
+ chartInfo.CreateTime = time.Now()
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ chartInfo.Source = chartSource
|
|
|
+ time.Sleep(time.Microsecond)
|
|
|
+ chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + strconv.FormatInt(time.Now().UnixNano(), 10))
|
|
|
+ newChart.ChartInfo = chartInfo
|
|
|
+
|
|
|
+ // chart_edb_mapping中edb_info_id为标的ID
|
|
|
+ edbMapping := new(data_manage.ChartEdbMapping)
|
|
|
+ //edbMapping.EdbInfoId = indexId
|
|
|
+ //edbMapping.UniqueCode = utils.MD5(fmt.Sprint(utils.CHART_PREFIX, "_", indexId, "_", strconv.FormatInt(time.Now().UnixNano(), 10)))
|
|
|
+ edbMapping.Source = chartSource
|
|
|
+ edbMapping.CreateTime = time.Now().Local()
|
|
|
+ edbMapping.ModifyTime = time.Now().Local()
|
|
|
+ newChart.EdbMappings = append(newChart.EdbMappings, edbMapping)
|
|
|
+
|
|
|
+ charts = append(charts, newChart)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// FixAiPredictCharts 修复AI预测模型图表
|
|
|
+func FixAiPredictCharts() {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+ fmt.Println("修复完成")
|
|
|
+ }()
|
|
|
+ fmt.Println("开始修复")
|
|
|
+
|
|
|
+ indexOb := new(aiPredictModel.AiPredictModelIndex)
|
|
|
+ indexes, e := indexOb.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取所有标的失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 日度/月度图表
|
|
|
+ frequencyArr := []int{aiPredictModel.ModelDataSourceMonthly, aiPredictModel.ModelDataSourceDaily}
|
|
|
+ sourceMapping := map[int]int{
|
|
|
+ aiPredictModel.ModelDataSourceMonthly: utils.CHART_SOURCE_AI_PREDICT_MODEL_MONTHLY,
|
|
|
+ aiPredictModel.ModelDataSourceDaily: utils.CHART_SOURCE_AI_PREDICT_MODEL_DAILY,
|
|
|
+ }
|
|
|
+ suffixNameMapping := map[int]string{
|
|
|
+ aiPredictModel.ModelDataSourceMonthly: "预测模型/回测",
|
|
|
+ aiPredictModel.ModelDataSourceDaily: "预测模型",
|
|
|
+ }
|
|
|
+ chartOb := new(data_manage.ChartInfo)
|
|
|
+ for _, v := range indexes {
|
|
|
+ for _, fre := range frequencyArr {
|
|
|
+ chartSource := sourceMapping[fre]
|
|
|
+ item, e := data_manage.GetAiPredictChartInfoByIndexId(chartSource, v.AiPredictModelIndexId)
|
|
|
+ if e != nil && !utils.IsErrNoRow(e) {
|
|
|
+ err = fmt.Errorf("获取AI预测模型图表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 由于标的名称是固定的所以chart_info没有什么可更新的, 已加入过就忽略
|
|
|
+ if item != nil && item.ChartInfoId > 0 {
|
|
|
+ fmt.Printf("标的%d-%d图表已存在, continue\n", v.AiPredictModelIndexId, chartSource)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增图表
|
|
|
+ chartName := fmt.Sprintf("%s%s", v.IndexName, suffixNameMapping[fre])
|
|
|
+ chartInfo := new(data_manage.ChartInfo)
|
|
|
+ chartInfo.ChartName = chartName
|
|
|
+ chartInfo.ChartNameEn = chartName
|
|
|
+ chartInfo.ChartType = utils.CHART_TYPE_CURVE
|
|
|
+ chartInfo.Calendar = "公历"
|
|
|
+ chartInfo.SysUserId = v.SysUserId
|
|
|
+ chartInfo.SysUserRealName = v.SysUserRealName
|
|
|
+ chartInfo.CreateTime = time.Now()
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ chartInfo.Source = chartSource
|
|
|
+ time.Sleep(time.Microsecond)
|
|
|
+ chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + strconv.FormatInt(time.Now().UnixNano(), 10))
|
|
|
+
|
|
|
+ // chart_edb_mapping中edb_info_id为标的ID
|
|
|
+ mappings := make([]*data_manage.ChartEdbMapping, 0)
|
|
|
+ edbMapping := new(data_manage.ChartEdbMapping)
|
|
|
+ edbMapping.EdbInfoId = v.AiPredictModelIndexId
|
|
|
+ edbMapping.UniqueCode = utils.MD5(fmt.Sprint(utils.CHART_PREFIX, "_", v.AiPredictModelIndexId, "_", strconv.FormatInt(time.Now().UnixNano(), 10)))
|
|
|
+ edbMapping.Source = chartSource
|
|
|
+ edbMapping.CreateTime = time.Now().Local()
|
|
|
+ edbMapping.ModifyTime = time.Now().Local()
|
|
|
+ mappings = append(mappings, edbMapping)
|
|
|
+
|
|
|
+ // 新增图表
|
|
|
+ if e = chartOb.AddChartInfoAndEdbMappings(chartInfo, mappings); e != nil {
|
|
|
+ err = fmt.Errorf("新增图表及mapping失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入ES
|
|
|
+ if chartInfo.ChartInfoId <= 0 {
|
|
|
+ err = fmt.Errorf("图表ID有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|