|
@@ -204,6 +204,7 @@ func (this *AiPredictModelIndexController) Import() {
|
|
}
|
|
}
|
|
imports := make(map[string]*aiPredictModel.AiPredictModelImportData)
|
|
imports := make(map[string]*aiPredictModel.AiPredictModelImportData)
|
|
importsData := make(map[string]map[time.Time]*aiPredictModel.AiPredictModelData)
|
|
importsData := make(map[string]map[time.Time]*aiPredictModel.AiPredictModelData)
|
|
|
|
+ importsDailyData := make(map[string]map[time.Time]*aiPredictModel.AiPredictModelData)
|
|
for sheetKey, sheet := range xlFile.Sheets {
|
|
for sheetKey, sheet := range xlFile.Sheets {
|
|
maxRow := sheet.MaxRow
|
|
maxRow := sheet.MaxRow
|
|
|
|
|
|
@@ -262,7 +263,12 @@ func (this *AiPredictModelIndexController) Import() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
imports[indexName].Index.PredictDate = predictDate
|
|
imports[indexName].Index.PredictDate = predictDate
|
|
- predictVal, _ := cells[5].Float()
|
|
|
|
|
|
+
|
|
|
|
+ strVal := strings.TrimSpace(cells[5].String())
|
|
|
|
+ if strVal == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ predictVal, _ := strconv.ParseFloat(strVal, 64)
|
|
imports[indexName].Index.PredictValue = predictVal
|
|
imports[indexName].Index.PredictValue = predictVal
|
|
imports[indexName].Index.PredictFrequency = strings.TrimSpace(cells[6].String())
|
|
imports[indexName].Index.PredictFrequency = strings.TrimSpace(cells[6].String())
|
|
imports[indexName].Index.DirectionAccuracy = strings.TrimSpace(cells[7].String())
|
|
imports[indexName].Index.DirectionAccuracy = strings.TrimSpace(cells[7].String())
|
|
@@ -270,7 +276,7 @@ func (this *AiPredictModelIndexController) Import() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 数据页
|
|
|
|
|
|
+ // 月度数据页
|
|
if sheetKey == 1 {
|
|
if sheetKey == 1 {
|
|
// 每五列为一个指标的数据
|
|
// 每五列为一个指标的数据
|
|
colKeys := make(map[int]*ImportDataColKey) // 每一列对应的指标名称以及对应的字段序号
|
|
colKeys := make(map[int]*ImportDataColKey) // 每一列对应的指标名称以及对应的字段序号
|
|
@@ -362,6 +368,7 @@ func (this *AiPredictModelIndexController) Import() {
|
|
importsData[colKeys[ck].IndexName][dataDate].DataTime = dataDate
|
|
importsData[colKeys[ck].IndexName][dataDate].DataTime = dataDate
|
|
importsData[colKeys[ck].IndexName][dataDate].CreateTime = time.Now()
|
|
importsData[colKeys[ck].IndexName][dataDate].CreateTime = time.Now()
|
|
importsData[colKeys[ck].IndexName][dataDate].ModifyTime = time.Now()
|
|
importsData[colKeys[ck].IndexName][dataDate].ModifyTime = time.Now()
|
|
|
|
+ importsData[colKeys[ck].IndexName][dataDate].Source = aiPredictModel.ModelDataSourceMonthly
|
|
case 2, 3:
|
|
case 2, 3:
|
|
// 实际值和预测值, 可能为空
|
|
// 实际值和预测值, 可能为空
|
|
dataDate := colKeys[ck].DataDate
|
|
dataDate := colKeys[ck].DataDate
|
|
@@ -401,6 +408,132 @@ func (this *AiPredictModelIndexController) Import() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 日度数据页
|
|
|
|
+ if sheetKey == 2 {
|
|
|
|
+ // 每3列为一个指标的数据
|
|
|
|
+ colKeys := make(map[int]*ImportDataColKey) // 每一列对应的指标名称以及对应的字段序号
|
|
|
|
+ for i := 0; i < maxRow; i++ {
|
|
|
|
+ // 首行为指标名称
|
|
|
|
+ if i == 0 {
|
|
|
|
+ nameCol := 0
|
|
|
|
+ row := sheet.Row(i)
|
|
|
|
+ for ck, cell := range row.Cells {
|
|
|
|
+ nameCol += 1
|
|
|
|
+ if nameCol > 3 {
|
|
|
|
+ nameCol = 1
|
|
|
|
+ }
|
|
|
|
+ if nameCol == 1 {
|
|
|
|
+ // nameCol=1时为指标/数据行则为日期
|
|
|
|
+ indexName := strings.TrimSpace(cell.String())
|
|
|
|
+ if indexName == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ importsDailyData[indexName] = make(map[time.Time]*aiPredictModel.AiPredictModelData)
|
|
|
|
+
|
|
|
|
+ colKeys[ck] = &ImportDataColKey{
|
|
|
|
+ ColKey: 1,
|
|
|
|
+ IndexName: indexName,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 后面两列分别对应: 实际值|预测值, 这里直接加无须考虑是否会越界
|
|
|
|
+ colKeys[ck+1] = &ImportDataColKey{
|
|
|
|
+ ColKey: 2,
|
|
|
|
+ IndexName: indexName,
|
|
|
|
+ }
|
|
|
|
+ colKeys[ck+2] = &ImportDataColKey{
|
|
|
|
+ ColKey: 3,
|
|
|
|
+ IndexName: indexName,
|
|
|
|
+ }
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 第二行为标题,遇到"预测值"单元格,需要取出其中的值作为预测图例名称
|
|
|
|
+ if i == 1 {
|
|
|
|
+ row := sheet.Row(i)
|
|
|
|
+ for ck, cell := range row.Cells {
|
|
|
|
+ if colKeys[ck] == nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if colKeys[ck].IndexName == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if colKeys[ck].ColKey != 3 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if imports[colKeys[ck].IndexName] != nil && imports[colKeys[ck].IndexName].Index != nil {
|
|
|
|
+ var extraConfig aiPredictModel.AiPredictModelIndexExtraConfig
|
|
|
|
+ extraConfig.DailyChart.PredictLegendName = strings.TrimSpace(cell.String())
|
|
|
|
+ b, _ := json.Marshal(extraConfig)
|
|
|
|
+ imports[colKeys[ck].IndexName].Index.ExtraConfig = string(b)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 剩余为数据行
|
|
|
|
+ row := sheet.Row(i)
|
|
|
|
+ for ck, cell := range row.Cells {
|
|
|
|
+ if colKeys[ck] == nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if colKeys[ck].IndexName == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ switch colKeys[ck].ColKey {
|
|
|
|
+ case 1:
|
|
|
|
+ // 日期列
|
|
|
|
+ strDate := strings.TrimSpace(cell.String())
|
|
|
|
+ dataDate, _ := time.Parse("2006/01/02", strDate)
|
|
|
|
+ if dataDate.IsZero() {
|
|
|
|
+ dataDate, _ = time.Parse("01-02-06", strDate)
|
|
|
|
+ if dataDate.IsZero() {
|
|
|
|
+ dataDate, _ = time.Parse("2006/1/2", strDate)
|
|
|
|
+ if dataDate.IsZero() {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ colKeys[ck].DataDate = dataDate
|
|
|
|
+ colKeys[ck+1].DataDate = dataDate
|
|
|
|
+ colKeys[ck+2].DataDate = dataDate
|
|
|
|
+ importRow := imports[colKeys[ck].IndexName]
|
|
|
|
+ if importRow == nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ // 新增当前日期数据
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate] = new(aiPredictModel.AiPredictModelData)
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].DataTime = dataDate
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].CreateTime = time.Now()
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].ModifyTime = time.Now()
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].Source = aiPredictModel.ModelDataSourceDaily
|
|
|
|
+ case 2, 3:
|
|
|
|
+ // 实际值和预测值, 可能为空
|
|
|
|
+ dataDate := colKeys[ck].DataDate
|
|
|
|
+ if importsDailyData[colKeys[ck].IndexName][dataDate] == nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ strVal := strings.TrimSpace(cell.String())
|
|
|
|
+ if strVal == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ val, _ := strconv.ParseFloat(strVal, 64)
|
|
|
|
+ if colKeys[ck].ColKey == 2 {
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].Value.Valid = true
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].Value.Float64 = val
|
|
|
|
+ } else {
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].PredictValue.Valid = true
|
|
|
|
+ importsDailyData[colKeys[ck].IndexName][dataDate].PredictValue.Float64 = val
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
for indexName, v := range importsData {
|
|
for indexName, v := range importsData {
|
|
@@ -411,6 +544,14 @@ func (this *AiPredictModelIndexController) Import() {
|
|
imports[indexName].Data = append(imports[indexName].Data, dateData)
|
|
imports[indexName].Data = append(imports[indexName].Data, dateData)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ for indexName, v := range importsDailyData {
|
|
|
|
+ if imports[indexName] == nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ for _, dateData := range v {
|
|
|
|
+ imports[indexName].Data = append(imports[indexName].Data, dateData)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
importIndexes := make([]*aiPredictModel.AiPredictModelImportData, 0)
|
|
importIndexes := make([]*aiPredictModel.AiPredictModelImportData, 0)
|
|
for _, v := range imports {
|
|
for _, v := range imports {
|
|
importIndexes = append(importIndexes, v)
|
|
importIndexes = append(importIndexes, v)
|
|
@@ -471,40 +612,60 @@ func (this *AiPredictModelIndexController) Detail() {
|
|
}
|
|
}
|
|
|
|
|
|
// 获取标的数据
|
|
// 获取标的数据
|
|
- indexData := make([]*aiPredictModel.AiPredictModelData, 0)
|
|
|
|
|
|
+ monthData, dailyData := make([]*aiPredictModel.AiPredictModelData, 0), make([]*aiPredictModel.AiPredictModelData, 0)
|
|
{
|
|
{
|
|
tableData := make([]*aiPredictModel.AiPredictModelDataItem, 0)
|
|
tableData := make([]*aiPredictModel.AiPredictModelDataItem, 0)
|
|
dataOb := new(aiPredictModel.AiPredictModelData)
|
|
dataOb := new(aiPredictModel.AiPredictModelData)
|
|
- dataCond := fmt.Sprintf(` AND %s = ?`, dataOb.Cols().AiPredictModelIndexId)
|
|
|
|
|
|
+ dataCond := fmt.Sprintf(` AND %s = ?`, dataOb.Cols().IndexCode)
|
|
dataPars := make([]interface{}, 0)
|
|
dataPars := make([]interface{}, 0)
|
|
- dataPars = append(dataPars, indexId)
|
|
|
|
|
|
+ dataPars = append(dataPars, indexItem.IndexCode)
|
|
list, e := dataOb.GetItemsByCondition(dataCond, dataPars, []string{}, fmt.Sprintf("%s DESC", dataOb.Cols().DataTime))
|
|
list, e := dataOb.GetItemsByCondition(dataCond, dataPars, []string{}, fmt.Sprintf("%s DESC", dataOb.Cols().DataTime))
|
|
if e != nil {
|
|
if e != nil {
|
|
br.Msg = "获取失败"
|
|
br.Msg = "获取失败"
|
|
br.ErrMsg = fmt.Sprintf("获取标的数据失败, %v", e)
|
|
br.ErrMsg = fmt.Sprintf("获取标的数据失败, %v", e)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- indexData = list
|
|
|
|
- // tableData最多显示10条
|
|
|
|
|
|
+
|
|
|
|
+ // tableData取月度数据,最多显示10条
|
|
count, limit := 0, 10
|
|
count, limit := 0, 10
|
|
for _, v := range list {
|
|
for _, v := range list {
|
|
- if count >= limit {
|
|
|
|
- break
|
|
|
|
|
|
+ // 日度数据
|
|
|
|
+ if v.Source == aiPredictModel.ModelDataSourceDaily {
|
|
|
|
+ dailyData = append(dailyData, v)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 月度数据
|
|
|
|
+ if count < limit {
|
|
|
|
+ tableData = append(tableData, v.Format2Item())
|
|
|
|
+ count += 1
|
|
}
|
|
}
|
|
- tableData = append(tableData, v.Format2Item())
|
|
|
|
- count += 1
|
|
|
|
|
|
+ monthData = append(monthData, v)
|
|
}
|
|
}
|
|
resp.TableData = tableData
|
|
resp.TableData = tableData
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取图表数据
|
|
|
|
- chartDetail, e := services.GetAiPredictChartDetailByData(indexItem, indexData)
|
|
|
|
- if e != nil {
|
|
|
|
- br.Msg = "获取失败"
|
|
|
|
- br.ErrMsg = fmt.Sprintf("获取图表数据失败, %v", e)
|
|
|
|
- return
|
|
|
|
|
|
+ // 月度图表
|
|
|
|
+ if len(monthData) > 0 {
|
|
|
|
+ chartDetail, e := services.GetAiPredictChartDetailByData(indexItem, monthData, aiPredictModel.ModelDataSourceMonthly)
|
|
|
|
+ if e != nil {
|
|
|
|
+ br.Msg = "获取失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取月度图表失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ resp.ChartView = chartDetail
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 日度图表
|
|
|
|
+ if len(dailyData) > 0 {
|
|
|
|
+ dailyChartDetail, e := services.GetAiPredictChartDetailByData(indexItem, dailyData, aiPredictModel.ModelDataSourceDaily)
|
|
|
|
+ if e != nil {
|
|
|
|
+ br.Msg = "获取失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取日度图表失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ resp.DailyChartView = dailyChartDetail
|
|
}
|
|
}
|
|
- resp.ChartView = chartDetail
|
|
|
|
|
|
|
|
br.Data = resp
|
|
br.Data = resp
|
|
br.Ret = 200
|
|
br.Ret = 200
|
|
@@ -553,22 +714,34 @@ func (this *AiPredictModelIndexController) Save() {
|
|
br.Msg = "标的已被删除,请刷新页面"
|
|
br.Msg = "标的已被删除,请刷新页面"
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- br.Msg = "获取失败"
|
|
|
|
|
|
+ br.Msg = "操作失败"
|
|
br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
|
|
br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- var updateCols []string
|
|
|
|
- if req.LeftMin != "" {
|
|
|
|
- indexItem.LeftMin = req.LeftMin
|
|
|
|
- updateCols = append(updateCols, indexOb.Cols().LeftMin)
|
|
|
|
|
|
+ var extraConfig aiPredictModel.AiPredictModelIndexExtraConfig
|
|
|
|
+ if indexItem.ExtraConfig != "" {
|
|
|
|
+ if e = json.Unmarshal([]byte(indexItem.ExtraConfig), &extraConfig); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("标的配置解析失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if req.LeftMax != "" {
|
|
|
|
- indexItem.LeftMax = req.LeftMax
|
|
|
|
- updateCols = append(updateCols, indexOb.Cols().LeftMax)
|
|
|
|
|
|
+ if req.MonthlyChart != nil {
|
|
|
|
+ extraConfig.MonthlyChart.LeftMin = req.MonthlyChart.LeftMin
|
|
|
|
+ extraConfig.MonthlyChart.LeftMax = req.MonthlyChart.LeftMax
|
|
|
|
+ extraConfig.MonthlyChart.Unit = req.MonthlyChart.Unit
|
|
}
|
|
}
|
|
|
|
+ if req.DailyChart != nil {
|
|
|
|
+ extraConfig.DailyChart.LeftMin = req.DailyChart.LeftMin
|
|
|
|
+ extraConfig.DailyChart.LeftMax = req.DailyChart.LeftMax
|
|
|
|
+ extraConfig.DailyChart.Unit = req.DailyChart.Unit
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ configByte, _ := json.Marshal(extraConfig)
|
|
|
|
+ indexItem.ExtraConfig = string(configByte)
|
|
indexItem.ModifyTime = time.Now()
|
|
indexItem.ModifyTime = time.Now()
|
|
- updateCols = append(updateCols, indexOb.Cols().ModifyTime)
|
|
|
|
|
|
+ updateCols := []string{indexOb.Cols().ExtraConfig, indexOb.Cols().ModifyTime}
|
|
if e = indexItem.Update(updateCols); e != nil {
|
|
if e = indexItem.Update(updateCols); e != nil {
|
|
br.Msg = "操作失败"
|
|
br.Msg = "操作失败"
|
|
br.ErrMsg = fmt.Sprintf("保存标的失败, %v", e)
|
|
br.ErrMsg = fmt.Sprintf("保存标的失败, %v", e)
|
|
@@ -626,11 +799,6 @@ func (this *AiPredictModelIndexController) DashboardSave() {
|
|
br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
|
|
br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- // 仅标的创建人有权限操作看板
|
|
|
|
- //if sysUser.AdminId != indexItem.SysUserId {
|
|
|
|
- // br.Msg = "仅创建人可操作"
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
|
|
|
|
// 获取看板
|
|
// 获取看板
|
|
var isUpdate bool
|
|
var isUpdate bool
|