|
@@ -2,12 +2,13 @@ package correlation
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"hongze/hongze_yb/models/response/chart_info"
|
|
|
"hongze/hongze_yb/models/tables/chart_edb_mapping"
|
|
|
"hongze/hongze_yb/models/tables/chart_info_correlation"
|
|
|
- "hongze/hongze_yb/models/tables/edb_info"
|
|
|
+ "hongze/hongze_yb/models/tables/edb_data"
|
|
|
"hongze/hongze_yb/services/alarm_msg"
|
|
|
"hongze/hongze_yb/services/chart"
|
|
|
"hongze/hongze_yb/utils"
|
|
@@ -16,19 +17,19 @@ import (
|
|
|
)
|
|
|
|
|
|
// HandleDataByLinearRegression 线性方程插值法补全数据
|
|
|
-func HandleDataByLinearRegression(originList []*edb_info.EdbInfoSearchData, handleDataMap map[string]float64) (newList []*edb_info.EdbInfoSearchData, err error) {
|
|
|
+func HandleDataByLinearRegression(originList []*edb_data.EdbDataList, handleDataMap map[string]float64) (newList []*edb_data.EdbDataList, err error) {
|
|
|
if len(originList) < 2 {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- var startEdbInfoData *edb_info.EdbInfoSearchData
|
|
|
+ var startEdbInfoData *edb_data.EdbDataList
|
|
|
for _, v := range originList {
|
|
|
handleDataMap[v.DataTime] = v.Value
|
|
|
|
|
|
// 第一个数据就给过滤了,给后面的试用
|
|
|
if startEdbInfoData == nil {
|
|
|
startEdbInfoData = v
|
|
|
- newList = append(newList, &edb_info.EdbInfoSearchData{
|
|
|
+ newList = append(newList, &edb_data.EdbDataList{
|
|
|
DataTime: v.DataTime,
|
|
|
Value: v.Value,
|
|
|
})
|
|
@@ -44,7 +45,7 @@ func HandleDataByLinearRegression(originList []*edb_info.EdbInfoSearchData, hand
|
|
|
// 如果相差一天,那么过滤
|
|
|
if betweenDay <= 1 {
|
|
|
startEdbInfoData = v
|
|
|
- newList = append(newList, &edb_info.EdbInfoSearchData{
|
|
|
+ newList = append(newList, &edb_data.EdbDataList{
|
|
|
DataTime: v.DataTime,
|
|
|
Value: v.Value,
|
|
|
})
|
|
@@ -83,7 +84,7 @@ func HandleDataByLinearRegression(originList []*edb_info.EdbInfoSearchData, hand
|
|
|
|
|
|
val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).Round(4).Float64()
|
|
|
handleDataMap[tmpDataTime.Format(utils.FormatDate)] = val
|
|
|
- newList = append(newList, &edb_info.EdbInfoSearchData{
|
|
|
+ newList = append(newList, &edb_data.EdbDataList{
|
|
|
DataTime: tmpDataTime.Format(utils.FormatDate),
|
|
|
Value: val,
|
|
|
})
|
|
@@ -96,7 +97,7 @@ func HandleDataByLinearRegression(originList []*edb_info.EdbInfoSearchData, hand
|
|
|
}
|
|
|
|
|
|
// MoveDataDaysToNewDataList 平移指标数据生成新的数据序列
|
|
|
-func MoveDataDaysToNewDataList(dataList []*edb_info.EdbInfoSearchData, moveDay int) (newDataList []edb_info.EdbInfoSearchData, dateDataMap map[string]float64) {
|
|
|
+func MoveDataDaysToNewDataList(dataList []*edb_data.EdbDataList, moveDay int) (newDataList []edb_data.EdbDataList, dateDataMap map[string]float64) {
|
|
|
dateMap := make(map[time.Time]float64)
|
|
|
var minDate, maxDate time.Time
|
|
|
dateDataMap = make(map[string]float64)
|
|
@@ -135,7 +136,7 @@ func MoveDataDaysToNewDataList(dataList []*edb_info.EdbInfoSearchData, moveDay i
|
|
|
tmpValue = newDataList[len(newDataList)-1].Value
|
|
|
}
|
|
|
}
|
|
|
- tmpData := edb_info.EdbInfoSearchData{
|
|
|
+ tmpData := edb_data.EdbDataList{
|
|
|
DataTime: currDate.Format(utils.FormatDate),
|
|
|
Value: tmpValue,
|
|
|
}
|
|
@@ -224,22 +225,26 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *chart_edb_mapping.C
|
|
|
}
|
|
|
|
|
|
// 获取时间基准指标在时间区间内的值
|
|
|
- baseCond := ` AND edb_info_id = ? AND (data_time BETWEEN ? AND ?) `
|
|
|
- basePars := make([]interface{}, 0)
|
|
|
- basePars = append(basePars, baseEdbInfo.EdbInfoId, startDate, endDate)
|
|
|
- baseDataList, e := edb_info.GetEdbDataListAll(baseCond, basePars, baseEdbInfo.Source, 1)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取基准指标值失败, Err: %s", e.Error())
|
|
|
+ baseDataList := make([]*edb_data.EdbDataList, 0)
|
|
|
+ switch baseEdbInfo.EdbInfoCategoryType {
|
|
|
+ case 0:
|
|
|
+ baseDataList, err = edb_data.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.EdbInfoId, startDate, endDate)
|
|
|
+ case 1:
|
|
|
+ _, baseDataList, _, _, err, _ = chart.GetPredictDataListByPredictEdbInfoId(baseEdbInfo.EdbInfoId, startDate, endDate, false)
|
|
|
+ default:
|
|
|
+ err = errors.New("指标base类型异常")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 获取变频指标所有日期的值, 插值法完善数据
|
|
|
- changeCond := ` AND edb_info_id = ? `
|
|
|
- changePars := make([]interface{}, 0)
|
|
|
- changePars = append(changePars, changeEdbInfo.EdbInfoId)
|
|
|
- changeDataList, e := edb_info.GetEdbDataListAll(changeCond, changePars, changeEdbInfo.Source, 1)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取变频指标值失败, Err: %s", e.Error())
|
|
|
+ changeDataList := make([]*edb_data.EdbDataList, 0)
|
|
|
+ switch changeEdbInfo.EdbInfoCategoryType {
|
|
|
+ case 0:
|
|
|
+ changeDataList, err = edb_data.GetEdbDataList(changeEdbInfo.Source, changeEdbInfo.EdbInfoId, "", "")
|
|
|
+ case 1:
|
|
|
+ _, changeDataList, _, _, err, _ = chart.GetPredictDataListByPredictEdbInfoId(changeEdbInfo.EdbInfoId, "", "", false)
|
|
|
+ default:
|
|
|
+ err = errors.New("指标change类型异常")
|
|
|
return
|
|
|
}
|
|
|
changeDataMap := make(map[string]float64)
|