Browse Source

Merge remote-tracking branch 'origin/chart/14.8'

Roc 1 year ago
parent
commit
91c7044f91

+ 12 - 0
models/data_manage/edb_data_base.go

@@ -126,6 +126,18 @@ func GetEdbDataTableName(source int) (tableName string) {
 		tableName = "edb_data_calculate_correlation"
 	case utils.DATA_SOURCE_NATIONAL_STATISTICS:
 		tableName = "edb_data_national_statistics"
+	case utils.DATA_SOURCE_CALCULATE_LJZZJ: //累计值转季 -> 61
+		tableName = "edb_data_calculate_ljzzj"
+	case utils.DATA_SOURCE_CALCULATE_LJZ: //累计值 -> 62
+		tableName = "edb_data_calculate_ljz"
+	case utils.DATA_SOURCE_CALCULATE_LJZNCZJ: //累计值(年初至今) -> 63
+		tableName = "edb_data_calculate_ljznczj"
+	case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZJ: // 预测指标 - 累计值 -> 65
+		tableName = "edb_data_predict_calculate_ljzzj"
+	case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZ: //预测指标 - 累计值转季->64
+		tableName = "edb_data_predict_calculate_ljz"
+	case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ: //预测指标 - 累计值(年初至今) -> 66
+		tableName = "edb_data_predict_calculate_ljznczj"
 	default:
 		tableName = ""
 	}

+ 7 - 0
services/data/correlation/chart_info.go

@@ -90,6 +90,13 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbDataList, handleD
 			}
 		}
 
+		// 最后将自己赋值
+		newList = append(newList, &data_manage.EdbDataList{
+			EdbDataId: v.EdbDataId,
+			DataTime:  v.DataTime,
+			Value:     v.Value,
+		})
+
 		startEdbInfoData = v
 	}
 	return

+ 33 - 0
services/data/predict_edb_info.go

@@ -374,6 +374,15 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency string) (dayLi
 		for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
 			dayList = append(dayList, currDate)
 		}
+	case "旬度":
+		for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
+			nextDate := currDate.AddDate(0, 0, 1)
+			//每个月的10号、20号、最后一天,那么就写入
+			if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
+				dayList = append(dayList, currDate)
+			}
+			currDate = nextDate
+		}
 	case "月度":
 		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
 			currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
@@ -382,6 +391,30 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency string) (dayLi
 			}
 			currDate = currDate.AddDate(0, 0, 1)
 		}
+	case "季度":
+		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
+			// 每月的最后一天
+			currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+			if !currDate.After(endDate) && !currDate.Equal(startDate) {
+				// 季度日期就写入,否则不写入
+				if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
+					dayList = append(dayList, currDate)
+				}
+			}
+			currDate = currDate.AddDate(0, 0, 1)
+		}
+	case "半年度":
+		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
+			// 每月的最后一天
+			currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+			if !currDate.After(endDate) && !currDate.Equal(startDate) {
+				// 半年度日期就写入,否则不写入
+				if currDate.Month() == 6 || currDate.Month() == 12 {
+					dayList = append(dayList, currDate)
+				}
+			}
+			currDate = currDate.AddDate(0, 0, 1)
+		}
 	case "年度":
 		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
 			currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())

+ 5 - 0
utils/calculate.go

@@ -136,6 +136,11 @@ func ComputeCorrelation(sList []Coordinate) (r float64) {
 		varYDeci = varYDeci.Add(diffYYbarDeci.Mul(diffYYbarDeci))
 		//varY += diffYYbar ** 2
 	}
+	//当输入的两个数组完全相同时,计算相关系数会导致除以零的操作,从而产生 NaN(Not a Number)的结果。为了避免这种情况,可以在计算相关系数之前先进行一个判断,如果两个数组的标准差为零,则相关系数应为1
+	if varXDeci.IsZero() && varYDeci.IsZero() {
+		r = 1
+		return
+	}
 	sqrtVal, _ := varXDeci.Mul(varYDeci).Round(4).Float64()
 	//fmt.Println("sqrtVal:", sqrtVal)
 	sst := math.Sqrt(sqrtVal) // 平方根

+ 6 - 0
utils/constants.go

@@ -217,6 +217,12 @@ const (
 	DATA_SOURCE_STOCK_PLANT                             //存量装置 ->58
 	DATA_SOURCE_CALCULATE_CORRELATION                   //滚动相关性->59
 	DATA_SOURCE_NATIONAL_STATISTICS                     //国家统计局->60
+	DATA_SOURCE_CALCULATE_LJZZJ                         //累计值转季 -> 61
+	DATA_SOURCE_CALCULATE_LJZ                           //累计值 -> 62
+	DATA_SOURCE_CALCULATE_LJZNCZJ                       //累计值(年初至今) -> 63
+	DATA_SOURCE_PREDICT_CALCULATE_LJZZJ                 //预测指标 - 累计值转季->64
+	DATA_SOURCE_PREDICT_CALCULATE_LJZ                   //预测指标 - 累计值 -> 65
+	DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ               //预测指标 - 累计值(年初至今) -> 66
 )
 
 // 数据刷新频率