|
@@ -884,6 +884,8 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
}
|
|
|
// 分母
|
|
|
decimalN := decimal.NewFromInt(int64(nValue))
|
|
|
+ // 需要减去的年份
|
|
|
+ subYear := year - dayList[0].Year()
|
|
|
|
|
|
//获取后面的预测数据
|
|
|
for k, currentDate := range dayList {
|
|
@@ -895,7 +897,7 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
// 数据集合中的最后一个数据
|
|
|
tmpDecimalVal := decimal.NewFromFloat(allDataList[tmpIndex].Value)
|
|
|
averageDateList = append(averageDateList, allDataList[tmpIndex].DataTime)
|
|
|
- for tmpK := 2; tmpK <= nValue; tmpK++ {
|
|
|
+ for tmpK := 1; tmpK < nValue; tmpK++ {
|
|
|
tmpIndex2 := tmpIndex - tmpK //上N期的值
|
|
|
tmpDecimalVal2 := decimal.NewFromFloat(allDataList[tmpIndex2].Value)
|
|
|
tmpDecimalVal = tmpDecimalVal.Add(tmpDecimalVal2)
|
|
@@ -913,7 +915,7 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
tmpHistoryValNum := 0
|
|
|
{
|
|
|
//前几年当日的日期
|
|
|
- tmpHistoryCurrentDate := currentDate.AddDate(year-currentDate.Year(), 0, 0)
|
|
|
+ tmpHistoryCurrentDate := currentDate.AddDate(subYear, 0, 0)
|
|
|
for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找
|
|
|
tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, i)
|
|
|
if val, ok := existMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
@@ -938,7 +940,7 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
return
|
|
|
}
|
|
|
//前几年上一期的日期
|
|
|
- tmpHistoryLastDate := lastDay.AddDate(year-lastDay.Year(), 0, 0)
|
|
|
+ tmpHistoryLastDate := lastDay.AddDate(subYear, 0, 0)
|
|
|
for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找
|
|
|
tmpDate := tmpHistoryLastDate.AddDate(0, 0, i)
|
|
|
if val, ok := existMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
@@ -969,8 +971,10 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ // 计算最近N期平均值
|
|
|
+ tmpHistoryAverageVal := tmpHistoryDecimalVal.Div(decimalN)
|
|
|
// 计算最近N期同比值
|
|
|
- tbVal := tmpAverageVal.Div(tmpHistoryDecimalVal)
|
|
|
+ tbVal := tmpAverageVal.Div(tmpHistoryAverageVal)
|
|
|
|
|
|
// 预测值结果 = 同比年份同期值(tmpHistoryCurrentVal的值)* 同比值(tbVal的值)
|
|
|
val, _ := decimal.NewFromFloat(tmpHistoryCurrentVal).Mul(tbVal).RoundCeil(4).Float64()
|