Эх сурвалжийг харах

指标运算的起始时间和截止时间调整

xyxie 1 жил өмнө
parent
commit
954088babd

+ 7 - 14
models/base_from_calculate.go

@@ -307,8 +307,6 @@ func refreshAllCalculate(to orm.TxOrmer, edbInfoIdArr []*EdbInfo, edbInfoId, sou
 			return err
 		}
 
-		lenData := len(dataList)
-
 		for _, dv := range dataList {
 			if val, ok := realSaveDataMap[dv.DataTime]; ok {
 				if _, ok := val[v.EdbInfoId]; !ok {
@@ -334,18 +332,13 @@ func refreshAllCalculate(to orm.TxOrmer, edbInfoIdArr []*EdbInfo, edbInfoId, sou
 			// 以第一个指标的日期作为基准日期
 			if edbInfoIndex == 0 {
 				dateList = append(dateList, dv.DataTime)
-			}
-		}
-
-		if lenData > 0 {
-			tmpLatestDate, _ := time.ParseInLocation(utils.FormatDate, dataList[lenData-1].DataTime, time.Local)
-			if minLatestDate.IsZero() || minLatestDate.After(tmpLatestDate) {
-				minLatestDate = tmpLatestDate
-			}
-
-			tmpStartDate, _ := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
-			if maxStartDate.IsZero() || maxStartDate.Before(tmpStartDate) {
-				maxStartDate = tmpStartDate
+				tmpDate, _ := time.ParseInLocation(utils.FormatDate, dv.DataTime, time.Local)
+				if minLatestDate.IsZero() || tmpDate.After(minLatestDate) {
+					minLatestDate = tmpDate
+				}
+				if maxStartDate.IsZero() || tmpDate.Before(maxStartDate) {
+					maxStartDate = tmpDate
+				}
 			}
 		}
 	}

+ 9 - 2
models/base_predict_from_calculate.go

@@ -276,7 +276,7 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 
 	for edbInfoIndex, v := range edbInfoIdList {
 		// 单独存储max、min函数里的指标的数据
-		tmpLatestDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
+		/*tmpLatestDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
 		if tmpErr != nil {
 			err = errors.New(`最近的日期格式化失败;日期:` + v.EndDate + `;err:` + tmpErr.Error())
 			return
@@ -291,7 +291,7 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 		}
 		if maxStartDate.IsZero() || maxStartDate.Before(tmpStartDate) {
 			maxStartDate = tmpStartDate
-		}
+		}*/
 
 		// 获取关联指标数据
 		dataList, tmpErr := GetPredictEdbDataListAllByStartDate(v, 1, startDate)
@@ -323,6 +323,13 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 			}
 			if edbInfoIndex == 0 {
 				dateList = append(dateList, dv.DataTime)
+				tmpDate, _ := time.ParseInLocation(utils.FormatDate, dv.DataTime, time.Local)
+				if minLatestDate.IsZero() || tmpDate.After(minLatestDate) {
+					minLatestDate = tmpDate
+				}
+				if maxStartDate.IsZero() || tmpDate.Before(maxStartDate) {
+					maxStartDate = tmpDate
+				}
 			}
 		}
 	}

+ 10 - 3
models/predict_edb.go

@@ -65,7 +65,7 @@ func CalculateByRuleBy9(to orm.TxOrmer, rule CalculateRule) (resultDataList []*E
 			return
 		}
 
-		lenData := len(dataList)
+		//lenData := len(dataList)
 		for edbInfoIndex, dv := range dataList {
 			// 现有实际数据
 			if val, ok := realSaveDataMap[dv.DataTime]; ok {
@@ -92,10 +92,17 @@ func CalculateByRuleBy9(to orm.TxOrmer, rule CalculateRule) (resultDataList []*E
 			// 以第一个指标的日期作为基准日期
 			if edbInfoIndex == 0 {
 				dateList = append(dateList, dv.DataTime)
+				tmpDate, _ := time.ParseInLocation(utils.FormatDate, dv.DataTime, time.Local)
+				if minLatestDate.IsZero() || tmpDate.After(minLatestDate) {
+					minLatestDate = tmpDate
+				}
+				if maxStartDate.IsZero() || tmpDate.Before(maxStartDate) {
+					maxStartDate = tmpDate
+				}
 			}
 		}
 
-		if lenData > 0 {
+		/*if lenData > 0 {
 			tmpLatestDate, _ := time.ParseInLocation(utils.FormatDate, dataList[lenData-1].DataTime, time.Local)
 			if minLatestDate.IsZero() || minLatestDate.After(tmpLatestDate) {
 				minLatestDate = tmpLatestDate
@@ -105,7 +112,7 @@ func CalculateByRuleBy9(to orm.TxOrmer, rule CalculateRule) (resultDataList []*E
 			if maxStartDate.IsZero() || maxStartDate.Before(tmpStartDate) {
 				maxStartDate = tmpStartDate
 			}
-		}
+		}*/
 	}
 
 	// todo 数据处理,将日期内不全的数据做填补

+ 18 - 11
services/base_from_predict.go

@@ -94,7 +94,7 @@ func CalculateByRuleByNine(formulaStr string, edbInfoList []*models.EdbInfo, edb
 			return
 		}
 		dataMap := make(map[string]float64)
-		lenData := len(sourceDataList)
+		//lenData := len(sourceDataList)
 		for _, dv := range sourceDataList {
 			// 实际数据
 			if val, ok := realSaveDataMap[dv.DataTime]; ok {
@@ -121,19 +121,26 @@ func CalculateByRuleByNine(formulaStr string, edbInfoList []*models.EdbInfo, edb
 			// 以第一个指标的日期作为基准日期
 			if edbInfoIndex == 0 {
 				dateList = append(dateList, dv.DataTime)
-			}
-
-			if lenData > 0 {
-				tmpLatestDate, _ := time.ParseInLocation(utils.FormatDate, sourceDataList[lenData-1].DataTime, time.Local)
-				if minLatestDate.IsZero() || minLatestDate.After(tmpLatestDate) {
-					minLatestDate = tmpLatestDate
+				tmpDate, _ := time.ParseInLocation(utils.FormatDate, dv.DataTime, time.Local)
+				if minLatestDate.IsZero() || tmpDate.After(minLatestDate) {
+					minLatestDate = tmpDate
 				}
-
-				tmpStartDate, _ := time.ParseInLocation(utils.FormatDate, sourceDataList[0].DataTime, time.Local)
-				if maxStartDate.IsZero() || maxStartDate.Before(tmpStartDate) {
-					maxStartDate = tmpStartDate
+				if maxStartDate.IsZero() || tmpDate.Before(maxStartDate) {
+					maxStartDate = tmpDate
 				}
 			}
+
+			/*			if lenData > 0 {
+						tmpLatestDate, _ := time.ParseInLocation(utils.FormatDate, sourceDataList[lenData-1].DataTime, time.Local)
+						if minLatestDate.IsZero() || minLatestDate.After(tmpLatestDate) {
+							minLatestDate = tmpLatestDate
+						}
+
+						tmpStartDate, _ := time.ParseInLocation(utils.FormatDate, sourceDataList[0].DataTime, time.Local)
+						if maxStartDate.IsZero() || maxStartDate.Before(tmpStartDate) {
+							maxStartDate = tmpStartDate
+						}
+					}*/
 		}
 		item := new(models.CalculateItems)
 		item.EdbInfoId = v.EdbInfoId