|
@@ -245,6 +245,7 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
|
|
|
// 2023-03-17 时间序列始终以指标A为基准, 始终是B进行平移
|
|
|
baseDataList := make([]*models.EdbDataList, 0)
|
|
|
+ baseDataMap := make(map[string]float64)
|
|
|
changeDataList := make([]*models.EdbDataList, 0)
|
|
|
changeDataMap := make(map[string]float64)
|
|
|
|
|
@@ -261,8 +262,7 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
|
|
|
// 如果A指标是高频,那么就需要对B指标进行升频
|
|
|
if frequencyIntMap[edbInfoMappingA.Frequency] < frequencyIntMap[edbInfoMappingB.Frequency] {
|
|
|
- aDataMap := make(map[string]float64)
|
|
|
- tmpNewChangeDataList, e := HandleDataByLinearRegression(aDataList, aDataMap)
|
|
|
+ tmpNewChangeDataList, e := HandleDataByLinearRegression(aDataList, baseDataMap)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("获取变频指标插值法Map失败, Err: %s", e.Error())
|
|
|
return
|
|
@@ -270,6 +270,9 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
baseDataList = tmpNewChangeDataList
|
|
|
} else {
|
|
|
baseDataList = aDataList
|
|
|
+ for _, v := range baseDataList {
|
|
|
+ baseDataMap[v.DataTime] = v.Value
|
|
|
+ }
|
|
|
}
|
|
|
// 如果B指标是高频,那么就需要对A指标进行升频
|
|
|
if frequencyIntMap[edbInfoMappingA.Frequency] > frequencyIntMap[edbInfoMappingB.Frequency] {
|
|
@@ -281,10 +284,11 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
changeDataList = tmpNewChangeDataList
|
|
|
} else {
|
|
|
changeDataList = bDataList
|
|
|
- for _, v := range bDataList {
|
|
|
+ for _, v := range changeDataList {
|
|
|
changeDataMap[v.DataTime] = v.Value
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 计算不领先也不滞后时的相关系数
|
|
@@ -294,15 +298,22 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
baseDataTimeArr = append(baseDataTimeArr, baseDataList[i].DataTime)
|
|
|
baseCalculateData = append(baseCalculateData, baseDataList[i].Value)
|
|
|
}
|
|
|
+
|
|
|
+ zeroBaseData := make([]float64, 0)
|
|
|
zeroCalculateData := make([]float64, 0)
|
|
|
for i := range baseDataTimeArr {
|
|
|
- zeroCalculateData = append(zeroCalculateData, changeDataMap[baseDataTimeArr[i]])
|
|
|
+ tmpBaseVal, ok1 := baseDataMap[baseDataTimeArr[i]]
|
|
|
+ tmpCalculateVal, ok2 := changeDataMap[baseDataTimeArr[i]]
|
|
|
+ if ok1 && ok2 {
|
|
|
+ zeroBaseData = append(zeroBaseData, tmpBaseVal)
|
|
|
+ zeroCalculateData = append(zeroCalculateData, tmpCalculateVal)
|
|
|
+ }
|
|
|
}
|
|
|
- if len(baseCalculateData) != len(zeroCalculateData) {
|
|
|
+ if len(zeroBaseData) != len(zeroCalculateData) {
|
|
|
err = fmt.Errorf("相关系数两组序列元素数不一致, %d-%d", len(baseCalculateData), len(zeroCalculateData))
|
|
|
return
|
|
|
}
|
|
|
- zeroRatio := utils.CalculateCorrelationByIntArr(baseCalculateData, zeroCalculateData)
|
|
|
+ zeroRatio := utils.CalculateCorrelationByIntArr(zeroBaseData, zeroCalculateData)
|
|
|
if leadValue == 0 {
|
|
|
yData = append(yData, zeroRatio)
|
|
|
}
|
|
@@ -332,12 +343,14 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
}
|
|
|
}
|
|
|
if len(yCalculateData) <= 0 {
|
|
|
- // 领先滞后后,没有可以计算的数据了,那么退出当前循环
|
|
|
+ //err = fmt.Errorf("领先滞后相关系数两组序列元素数不一致, %d-%d", len(baseCalculateData), len(yCalculateData))
|
|
|
+ //return
|
|
|
+ // 领先滞后后,没有可以计算的数据了
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 公式计算出领先/滞后频度对应点的相关性系数
|
|
|
- ratio := utils.CalculateCorrelationByIntArr(baseCalculateData, yCalculateData)
|
|
|
+ ratio := utils.CalculateCorrelationByIntArr(xCalculateData, yCalculateData)
|
|
|
yData = append(yData, ratio)
|
|
|
}
|
|
|
}
|
|
@@ -404,7 +417,7 @@ func GetRollingCorrelationChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *m
|
|
|
}
|
|
|
//baseDataList = tmpNewChangeDataList
|
|
|
}
|
|
|
- // A指标不管三七二十一,先变个频再说
|
|
|
+ // B指标不管三七二十一,先变个频再说
|
|
|
{
|
|
|
tmpNewChangeDataList, e := HandleDataByLinearRegression(bDataList, changeDataMap)
|
|
|
if e != nil {
|