Browse Source

fix:预测规则,季节性预测规则恢复成原先版本,移除查找前后35天日期的逻辑

Roc 5 days ago
parent
commit
263d06481c
1 changed files with 44 additions and 37 deletions
  1. 44 37
      services/data/predict_edb_info_rule.go

+ 44 - 37
services/data/predict_edb_info_rule.go

@@ -774,55 +774,62 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, configValue strin
 		tmpHistoryVal := decimal.NewFromFloat(0) //往期的差值总和
 		tmpHistoryValNum := 0                    // 往期差值计算的数量
 
+		//fmt.Println(`填充后的数据长度:`, len(handleDataMap))
+
 		tmpLenAllDataList := len(allDataList)
 		tmpK := tmpLenAllDataList - 1    //上1期数据的下标
 		lastDayData := allDataList[tmpK] // 上1期的数据
-		//lastDayStr := lastDayData.DataTime
+		lastDayStr := lastDayData.DataTime
 		lastDayVal := lastDayData.Value
-		//lastDay, tmpErr := time.ParseInLocation(utils.FormatDate, lastDayStr, time.Local)
-		//if tmpErr != nil {
-		//	err = errors.New("获取上期日期转换失败:" + tmpErr.Error())
-		//}
+		lastDay, tmpErr := time.ParseInLocation(utils.FormatDate, lastDayStr, time.Local)
+		if tmpErr != nil {
+			err = errors.New("获取上期日期转换失败:" + tmpErr.Error())
+		}
+		//fmt.Println("当前需要计算的日期:", currentDate.Format(utils.FormatDate))
 		for _, year := range yearList {
 			moveDay := moveDayMap[year] //需要移动的天数
 			var tmpHistoryCurrentVal, tmpHistoryLastVal float64
 			var isFindHistoryCurrent, isFindHistoryLast bool //是否找到前几年的数据
 
 			//前几年当日的日期
-			tmpHistoryCurrentDate := currentDate.AddDate(year-currentDate.Year(), 0, -(moveDay + 1))
-			for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找
-				tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, i)
-				if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
-					tmpHistoryCurrentVal = val
-					isFindHistoryCurrent = true
-					break
-				} else {
-					tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, -i)
-					if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
-						tmpHistoryCurrentVal = val
-						isFindHistoryCurrent = true
-						break
-					}
-				}
-			}
+			tmpHistoryCurrentDate := currentDate.AddDate(year-currentDate.Year(), 0, -moveDay)
+			tmpHistoryCurrentVal, isFindHistoryCurrent = handleDataMap[tmpHistoryCurrentDate.Format(utils.FormatDate)]
+			//for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找(但是这个其实没有意义,因为这整个数据都通过插值法进行数据填充了, 2025-5-30 14:10:22)
+			//	tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, i)
+			//	if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
+			//		tmpHistoryCurrentVal = val
+			//		isFindHistoryCurrent = true
+			//		break
+			//	} else {
+			//		tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, -i)
+			//		if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
+			//			tmpHistoryCurrentVal = val
+			//			isFindHistoryCurrent = true
+			//			break
+			//		}
+			//	}
+			//}
 
 			//前几年上一期的日期
-			tmpHistoryLastDate := tmpHistoryCurrentDate.AddDate(0, 0, -1)
-			for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找
-				tmpDate := tmpHistoryLastDate.AddDate(0, 0, i)
-				if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
-					tmpHistoryLastVal = val
-					isFindHistoryLast = true
-					break
-				} else {
-					tmpDate := tmpHistoryLastDate.AddDate(0, 0, -i)
-					if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
-						tmpHistoryLastVal = val
-						isFindHistoryLast = true
-						break
-					}
-				}
-			}
+			tmpHistoryLastDate := lastDay.AddDate(year-lastDay.Year(), 0, -moveDay)
+			tmpHistoryLastVal, isFindHistoryLast = handleDataMap[tmpHistoryLastDate.Format(utils.FormatDate)]
+			//for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找(但是这个其实没有意义,因为这整个数据都通过插值法进行数据填充了, 2025-5-30 14:10:22)
+			//	tmpDate := tmpHistoryLastDate.AddDate(0, 0, i)
+			//	if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
+			//		tmpHistoryLastVal = val
+			//		isFindHistoryLast = true
+			//		break
+			//	} else {
+			//		tmpDate := tmpHistoryLastDate.AddDate(0, 0, -i)
+			//		if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
+			//			tmpHistoryLastVal = val
+			//			isFindHistoryLast = true
+			//			break
+			//		}
+			//	}
+			//}
+			
+			//fmt.Println("第一期日期:", tmpHistoryCurrentDate.Format(utils.FormatDate), ";第二期的日期:", tmpHistoryLastDate.Format(utils.FormatDate))
 
 			// 如果两个日期对应的数据都找到了,那么计算两期的差值
 			if isFindHistoryCurrent && isFindHistoryLast {