浏览代码

fix: 预测指标dataList

hsun 2 年之前
父节点
当前提交
2baaf3772e
共有 1 个文件被更改,包括 24 次插入19 次删除
  1. 24 19
      services/data/correlation/chart_info.go

+ 24 - 19
services/data/correlation/chart_info.go

@@ -2,6 +2,7 @@ package correlation
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"github.com/shopspring/decimal"
 	"hongze/hongze_chart_lib/models"
@@ -14,19 +15,19 @@ import (
 )
 
 // HandleDataByLinearRegression 线性方程插值法补全数据
-func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, handleDataMap map[string]float64) (newList []*data_manage.EdbInfoSearchData, err error) {
+func HandleDataByLinearRegression(originList []*models.EdbDataList, handleDataMap map[string]float64) (newList []*models.EdbDataList, err error) {
 	if len(originList) < 2 {
 		return
 	}
 
-	var startEdbInfoData *data_manage.EdbInfoSearchData
+	var startEdbInfoData *models.EdbDataList
 	for _, v := range originList {
 		handleDataMap[v.DataTime] = v.Value
 
 		// 第一个数据就给过滤了,给后面的试用
 		if startEdbInfoData == nil {
 			startEdbInfoData = v
-			newList = append(newList, &data_manage.EdbInfoSearchData{
+			newList = append(newList, &models.EdbDataList{
 				DataTime: v.DataTime,
 				Value:    v.Value,
 			})
@@ -42,7 +43,7 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, h
 		// 如果相差一天,那么过滤
 		if betweenDay <= 1 {
 			startEdbInfoData = v
-			newList = append(newList, &data_manage.EdbInfoSearchData{
+			newList = append(newList, &models.EdbDataList{
 				DataTime: v.DataTime,
 				Value:    v.Value,
 			})
@@ -81,7 +82,7 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, h
 
 				val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).Round(4).Float64()
 				handleDataMap[tmpDataTime.Format(utils.FormatDate)] = val
-				newList = append(newList, &data_manage.EdbInfoSearchData{
+				newList = append(newList, &models.EdbDataList{
 					DataTime: tmpDataTime.Format(utils.FormatDate),
 					Value:    val,
 				})
@@ -94,7 +95,7 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, h
 }
 
 // MoveDataDaysToNewDataList 平移指标数据生成新的数据序列
-func MoveDataDaysToNewDataList(dataList []*data_manage.EdbInfoSearchData, moveDay int) (newDataList []data_manage.EdbInfoSearchData, dateDataMap map[string]float64) {
+func MoveDataDaysToNewDataList(dataList []*models.EdbDataList, moveDay int) (newDataList []models.EdbDataList, dateDataMap map[string]float64) {
 	dateMap := make(map[time.Time]float64)
 	var minDate, maxDate time.Time
 	dateDataMap = make(map[string]float64)
@@ -133,7 +134,7 @@ func MoveDataDaysToNewDataList(dataList []*data_manage.EdbInfoSearchData, moveDa
 				tmpValue = newDataList[len(newDataList)-1].Value
 			}
 		}
-		tmpData := data_manage.EdbInfoSearchData{
+		tmpData := models.EdbDataList{
 			DataTime: currDate.Format(utils.FormatDate),
 			Value:    tmpValue,
 		}
@@ -218,22 +219,26 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
 	}
 
 	// 获取时间基准指标在时间区间内的值
-	baseCond := ` AND edb_info_id = ? AND (data_time BETWEEN ? AND ?) `
-	basePars := make([]interface{}, 0)
-	basePars = append(basePars, baseEdbInfo.EdbInfoId, startDate, endDate)
-	baseDataList, e := data_manage.GetEdbDataListAll(baseCond, basePars, baseEdbInfo.Source, 1)
-	if e != nil {
-		err = fmt.Errorf("获取基准指标值失败, Err: %s", e.Error())
+	baseDataList := make([]*models.EdbDataList, 0)
+	switch baseEdbInfo.EdbInfoCategoryType {
+	case 0:
+		baseDataList, err = models.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.EdbInfoId, startDate, endDate)
+	case 1:
+		_, baseDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(baseEdbInfo.EdbInfoId, startDate, endDate, false)
+	default:
+		err = errors.New("指标base类型异常")
 		return
 	}
 
 	// 获取变频指标所有日期的值, 插值法完善数据
-	changeCond := ` AND edb_info_id = ? `
-	changePars := make([]interface{}, 0)
-	changePars = append(changePars, changeEdbInfo.EdbInfoId)
-	changeDataList, e := data_manage.GetEdbDataListAll(changeCond, changePars, changeEdbInfo.Source, 1)
-	if e != nil {
-		err = fmt.Errorf("获取变频指标值失败, Err: %s", e.Error())
+	changeDataList := make([]*models.EdbDataList, 0)
+	switch changeEdbInfo.EdbInfoCategoryType {
+	case 0:
+		changeDataList, err = models.GetEdbDataList(changeEdbInfo.Source, changeEdbInfo.EdbInfoId, "", "")
+	case 1:
+		_, changeDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(changeEdbInfo.EdbInfoId, "", "", false)
+	default:
+		err = errors.New("指标change类型异常")
 		return
 	}
 	changeDataMap := make(map[string]float64)