Roc 2 роки тому
батько
коміт
0125cb9f07
3 змінених файлів з 50 додано та 29 видалено
  1. 4 4
      models/edb_info.go
  2. 46 24
      models/predict_edb_info_rule.go
  3. 0 1
      models/test.go

+ 4 - 4
models/edb_info.go

@@ -464,7 +464,7 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 				return
 			}
 			tbValue, _ := tmpValDecimal.Float64()
-			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTb(predictEdbConf.PredictEdbInfoId, tbValue, startDate, dataEndTime, frequency, predictEdbInfoData, existMap)
+			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTb(predictEdbConf.PredictEdbInfoId, tbValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
 		case 4: //4:同差
 			tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
 			if tmpErr != nil {
@@ -472,7 +472,7 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 				return
 			}
 			tcValue, _ := tmpValDecimal.Float64()
-			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTc(predictEdbConf.PredictEdbInfoId, tcValue, startDate, dataEndTime, frequency, predictEdbInfoData, existMap)
+			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTc(predictEdbConf.PredictEdbInfoId, tcValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
 		case 5: //5:环比
 			tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
 			if tmpErr != nil {
@@ -480,7 +480,7 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 				return
 			}
 			hbValue, _ := tmpValDecimal.Float64()
-			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHb(predictEdbConf.PredictEdbInfoId, hbValue, startDate, dataEndTime, frequency, predictEdbInfoData, existMap)
+			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHb(predictEdbConf.PredictEdbInfoId, hbValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
 		case 6: //6:环差
 			tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
 			if tmpErr != nil {
@@ -488,7 +488,7 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 				return
 			}
 			hcValue, _ := tmpValDecimal.Float64()
-			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHc(predictEdbConf.PredictEdbInfoId, hcValue, startDate, dataEndTime, frequency, predictEdbInfoData, existMap)
+			predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHc(predictEdbConf.PredictEdbInfoId, hcValue, startDate, dataEndTime, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
 		case 7: //7:N期移动均值
 			nValue, tmpErr := strconv.Atoi(predictEdbConf.Value)
 			if tmpErr != nil {

+ 46 - 24
models/predict_edb_info_rule.go

@@ -26,9 +26,13 @@ func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, sta
 //	GetChartPredictEdbInfoDataListByRuleTb 根据同比值规则获取预测数据
 //	2.1 同比: 在未来某一个时间段内,给定一个固定的同比增速a,用去年同期值X乘以同比增速(1+a),得到预测值Y=X(1+a)
 //	例: 今年1-3月值,100,100,120。给定同比增速a=0.1,则明年1-3月预测值为: 100*1.1=110,100*1.1=110,120*1.1=132。
-func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+	allDataList := make([]*EdbInfoSearchData, 0)
+	allDataList = append(allDataList, realPredictEdbInfoData...)
+	allDataList = append(allDataList, predictEdbInfoData...)
 	newPredictEdbInfoData = predictEdbInfoData
-	index := len(predictEdbInfoData)
+
+	index := len(allDataList)
 	//获取后面的预测数据
 	dayList := getPredictEdbDayList(startDate, endDate, frequency)
 	predictEdbInfoData = make([]*EdbInfoSearchData, 0)
@@ -108,12 +112,14 @@ func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, star
 		if calculateStatus {
 			tmpData.Value = val
 			newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
+			allDataList = append(allDataList, tmpData)
+			existMap[tmpData.DataTime] = val
 
 			// 最大最小值
 			if val < minValue {
 				minValue = val
 			}
-			if val < maxValue {
+			if val > maxValue {
 				maxValue = val
 			}
 		}
@@ -149,9 +155,13 @@ func PredictTbzDiv(a, b float64) (result float64) {
 //	GetChartPredictEdbInfoDataListByRuleTc 根据同差值规则获取预测数据
 //	2.2 同差: 在未来某一个时间段内,给定一个固定的同比增加值a,用去年同期值X加上同比增加值A,得到预测值Y=X+a
 //	例: 今年1-3月值,100,100,120。给定同比增加值a=10,则明年1-3月预测值为: 100+10=110,100+10=110,120+10=130
-func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+	allDataList := make([]*EdbInfoSearchData, 0)
+	allDataList = append(allDataList, realPredictEdbInfoData...)
+	allDataList = append(allDataList, predictEdbInfoData...)
 	newPredictEdbInfoData = predictEdbInfoData
-	index := len(predictEdbInfoData)
+
+	index := len(allDataList)
 	//获取后面的预测数据
 	dayList := getPredictEdbDayList(startDate, endDate, frequency)
 	predictEdbInfoData = make([]*EdbInfoSearchData, 0)
@@ -231,12 +241,14 @@ func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, star
 		if calculateStatus {
 			tmpData.Value = val
 			newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
+			allDataList = append(allDataList, tmpData)
+			existMap[tmpData.DataTime] = val
 
 			// 最大最小值
 			if val < minValue {
 				minValue = val
 			}
-			if val < maxValue {
+			if val > maxValue {
 				maxValue = val
 			}
 		}
@@ -266,30 +278,36 @@ func PredictTczDiv(a, b float64) (result float64) {
 //	GetChartPredictEdbInfoDataListByRuleHb 根据环比值规则获取预测数据
 //	环比:在未来某一个时间段内,给定一个固定的环比增速a,用上一期值X乘以环比增速(1+a),得到预测值Y=X(1+a)
 //	例: 最近1期值为100,给定环比增速a=0.2,则未来3期预测值为: 100*1.2=120,120*1.2=144,144*1.2=172.8
-func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+	allDataList := make([]*EdbInfoSearchData, 0)
+	allDataList = append(allDataList, realPredictEdbInfoData...)
+	allDataList = append(allDataList, predictEdbInfoData...)
 	newPredictEdbInfoData = predictEdbInfoData
-	index := len(predictEdbInfoData)
+
+	index := len(allDataList)
 	//获取后面的预测数据
 	dayList := getPredictEdbDayList(startDate, endDate, frequency)
 	for k, currentDate := range dayList {
 		tmpK := index + k - 1 //上1期的值
 
 		// 环比值计算
-		val := PredictHbzDiv(newPredictEdbInfoData[tmpK].Value, hbValue)
+		val := PredictHbzDiv(allDataList[tmpK].Value, hbValue)
 
 		currentDateStr := currentDate.Format(utils.FormatDate)
-		newPredictEdbInfoData = append(newPredictEdbInfoData, &EdbInfoSearchData{
+		tmpData := &EdbInfoSearchData{
 			EdbDataId: edbInfoId + 10000000000 + index + k,
 			DataTime:  currentDateStr,
 			Value:     val,
-		})
+		}
+		newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
+		allDataList = append(allDataList, tmpData)
 		existMap[currentDateStr] = val
 
 		// 最大最小值
 		if val < minValue {
 			minValue = val
 		}
-		if val < maxValue {
+		if val > maxValue {
 			maxValue = val
 		}
 	}
@@ -324,30 +342,36 @@ func PredictHbzDiv(a, b float64) (result float64) {
 //	GetChartPredictEdbInfoDataListByRuleHc 根据环差值规则获取预测数据
 //	2.4 环差:在未来某一个时间段内,给定一个固定的环比增加值a,用上一期值X加上环比增加值a,得到预测值Y=X+a
 //	例: 最近1期值为100,给定环比增加值a=10,则未来3期预测值为: 100+10=110,110+10=120,120+10=130
-func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
+	allDataList := make([]*EdbInfoSearchData, 0)
+	allDataList = append(allDataList, realPredictEdbInfoData...)
+	allDataList = append(allDataList, predictEdbInfoData...)
 	newPredictEdbInfoData = predictEdbInfoData
-	index := len(predictEdbInfoData)
+
+	index := len(allDataList)
 	//获取后面的预测数据
 	dayList := getPredictEdbDayList(startDate, endDate, frequency)
 	for k, currentDate := range dayList {
 		tmpK := index + k - 1 //上1期的值
 
 		// 环差别值计算
-		val := PredictHczDiv(newPredictEdbInfoData[tmpK].Value, hcValue)
+		val := PredictHczDiv(allDataList[tmpK].Value, hcValue)
 
 		currentDateStr := currentDate.Format(utils.FormatDate)
-		newPredictEdbInfoData = append(newPredictEdbInfoData, &EdbInfoSearchData{
+		tmpData := &EdbInfoSearchData{
 			EdbDataId: edbInfoId + 10000000000 + index + k,
 			DataTime:  currentDateStr,
 			Value:     val,
-		})
+		}
+		newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
+		allDataList = append(allDataList, tmpData)
 		existMap[currentDateStr] = val
 
 		// 最大最小值
 		if val < minValue {
 			minValue = val
 		}
-		if val < maxValue {
+		if val > maxValue {
 			maxValue = val
 		}
 	}
@@ -380,7 +404,6 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
 	allDataList := make([]*EdbInfoSearchData, 0)
 	allDataList = append(allDataList, realPredictEdbInfoData...)
 	allDataList = append(allDataList, predictEdbInfoData...)
-
 	newPredictEdbInfoData = predictEdbInfoData
 
 	lenAllData := len(allDataList)
@@ -423,7 +446,7 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
 		if val < minValue {
 			minValue = val
 		}
-		if val < maxValue {
+		if val > maxValue {
 			maxValue = val
 		}
 	}
@@ -445,7 +468,6 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
 	allDataList := make([]*EdbInfoSearchData, 0)
 	allDataList = append(allDataList, realPredictEdbInfoData...)
 	allDataList = append(allDataList, predictEdbInfoData...)
-
 	newPredictEdbInfoData = predictEdbInfoData
 
 	lenAllData := len(allDataList)
@@ -453,7 +475,7 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
 		return
 	}
 
-	if nValue <= 0 {
+	if nValue <= 1 {
 		return
 	}
 
@@ -495,7 +517,7 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
 		if val < minValue {
 			minValue = val
 		}
-		if val < maxValue {
+		if val > maxValue {
 			maxValue = val
 		}
 	}
@@ -511,7 +533,7 @@ type Coordinate struct {
 }
 
 func getLinearResult(s []Coordinate) (gradient, intercept float64) {
-	if len(s) == 0 {
+	if len(s) <= 1 {
 		return
 	}
 

+ 0 - 1
models/test.go

@@ -1 +0,0 @@
-package models