Roc 2 роки тому
батько
коміт
0e71af5a69

+ 4 - 1
services/chart/predict_edb_info.go

@@ -175,7 +175,10 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*predictEdbCo
 				err = tmpErr
 				return
 			}
-			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleNLinearRegression(int(predictEdbConf.PredictEdbInfoID), nValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
+			predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleNLinearRegression(int(predictEdbConf.PredictEdbInfoID), nValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
+			if err != nil {
+				return
+			}
 		case 9: //9:动态环差”预测规则;
 			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTrendsHC(int(predictEdbConf.PredictEdbInfoID), int(predictEdbConf.ConfigID), startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
 		case 10: //10:根据 给定终值后插值 规则获取预测数据

+ 7 - 1
services/chart/predict_edb_info_rule.go

@@ -1,10 +1,12 @@
 package chart
 
 import (
+	"errors"
 	"github.com/shopspring/decimal"
 	edbDataModel "hongze/hongze_yb/models/tables/edb_data"
 	predictEdbRuleDataModel "hongze/hongze_yb/models/tables/predict_edb_rule_data"
 	"hongze/hongze_yb/utils"
+	"math"
 	"time"
 )
 
@@ -472,7 +474,7 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
 //	例1:过去5期值(N=5)分别为:3,5,7,9,11(每两期值之间的时间间隔相等)。那么按照线性回归方程推算,未来三期的预测值是:13,15,17。
 //
 //	例2:过去6期值(N=6)分别为:3,3,5,7,9,11(每两期值之间的时间间隔相等)。那么按照线性回归方程推算,未来三期的预测值是:12.33,14.05,15.76。例1和例2的区别在于,多加了一期数据,导致回归方程发生改变,从而预测值不同。
-func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
+func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
 	//var errMsg string
 	//defer func() {
 	//	if errMsg != `` {
@@ -505,6 +507,10 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
 		coordinateData = append(coordinateData, tmpCoordinate)
 	}
 	a, b := getLinearResult(coordinateData)
+	if math.IsNaN(a) || math.IsNaN(b) {
+		err = errors.New("线性方程公式生成失败")
+		return
+	}
 	//fmt.Println("a:", a, ";======b:", b)
 
 	dayList := getPredictEdbDayList(startDate, endDate, frequency)