|
@@ -2,6 +2,7 @@ package correlation
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"hongze/hongze_chart_lib/models"
|
|
@@ -14,19 +15,19 @@ import (
|
|
|
)
|
|
|
|
|
|
|
|
|
-func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, handleDataMap map[string]float64) (newList []*data_manage.EdbInfoSearchData, err error) {
|
|
|
+func HandleDataByLinearRegression(originList []*models.EdbDataList, handleDataMap map[string]float64) (newList []*models.EdbDataList, err error) {
|
|
|
if len(originList) < 2 {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- var startEdbInfoData *data_manage.EdbInfoSearchData
|
|
|
+ var startEdbInfoData *models.EdbDataList
|
|
|
for _, v := range originList {
|
|
|
handleDataMap[v.DataTime] = v.Value
|
|
|
|
|
|
|
|
|
if startEdbInfoData == nil {
|
|
|
startEdbInfoData = v
|
|
|
- newList = append(newList, &data_manage.EdbInfoSearchData{
|
|
|
+ newList = append(newList, &models.EdbDataList{
|
|
|
DataTime: v.DataTime,
|
|
|
Value: v.Value,
|
|
|
})
|
|
@@ -42,7 +43,7 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, h
|
|
|
|
|
|
if betweenDay <= 1 {
|
|
|
startEdbInfoData = v
|
|
|
- newList = append(newList, &data_manage.EdbInfoSearchData{
|
|
|
+ newList = append(newList, &models.EdbDataList{
|
|
|
DataTime: v.DataTime,
|
|
|
Value: v.Value,
|
|
|
})
|
|
@@ -81,7 +82,7 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, h
|
|
|
|
|
|
val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).Round(4).Float64()
|
|
|
handleDataMap[tmpDataTime.Format(utils.FormatDate)] = val
|
|
|
- newList = append(newList, &data_manage.EdbInfoSearchData{
|
|
|
+ newList = append(newList, &models.EdbDataList{
|
|
|
DataTime: tmpDataTime.Format(utils.FormatDate),
|
|
|
Value: val,
|
|
|
})
|
|
@@ -94,7 +95,7 @@ func HandleDataByLinearRegression(originList []*data_manage.EdbInfoSearchData, h
|
|
|
}
|
|
|
|
|
|
|
|
|
-func MoveDataDaysToNewDataList(dataList []*data_manage.EdbInfoSearchData, moveDay int) (newDataList []data_manage.EdbInfoSearchData, dateDataMap map[string]float64) {
|
|
|
+func MoveDataDaysToNewDataList(dataList []*models.EdbDataList, moveDay int) (newDataList []models.EdbDataList, dateDataMap map[string]float64) {
|
|
|
dateMap := make(map[time.Time]float64)
|
|
|
var minDate, maxDate time.Time
|
|
|
dateDataMap = make(map[string]float64)
|
|
@@ -133,7 +134,7 @@ func MoveDataDaysToNewDataList(dataList []*data_manage.EdbInfoSearchData, moveDa
|
|
|
tmpValue = newDataList[len(newDataList)-1].Value
|
|
|
}
|
|
|
}
|
|
|
- tmpData := data_manage.EdbInfoSearchData{
|
|
|
+ tmpData := models.EdbDataList{
|
|
|
DataTime: currDate.Format(utils.FormatDate),
|
|
|
Value: tmpValue,
|
|
|
}
|
|
@@ -218,22 +219,26 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
|
|
|
}
|
|
|
|
|
|
|
|
|
- baseCond := ` AND edb_info_id = ? AND (data_time BETWEEN ? AND ?) `
|
|
|
- basePars := make([]interface{}, 0)
|
|
|
- basePars = append(basePars, baseEdbInfo.EdbInfoId, startDate, endDate)
|
|
|
- baseDataList, e := data_manage.GetEdbDataListAll(baseCond, basePars, baseEdbInfo.Source, 1)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取基准指标值失败, Err: %s", e.Error())
|
|
|
+ baseDataList := make([]*models.EdbDataList, 0)
|
|
|
+ switch baseEdbInfo.EdbInfoCategoryType {
|
|
|
+ case 0:
|
|
|
+ baseDataList, err = models.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.EdbInfoId, startDate, endDate)
|
|
|
+ case 1:
|
|
|
+ _, baseDataList, _, _, err, _ = data.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 := data_manage.GetEdbDataListAll(changeCond, changePars, changeEdbInfo.Source, 1)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取变频指标值失败, Err: %s", e.Error())
|
|
|
+ changeDataList := make([]*models.EdbDataList, 0)
|
|
|
+ switch changeEdbInfo.EdbInfoCategoryType {
|
|
|
+ case 0:
|
|
|
+ changeDataList, err = models.GetEdbDataList(changeEdbInfo.Source, changeEdbInfo.EdbInfoId, "", "")
|
|
|
+ case 1:
|
|
|
+ _, changeDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(changeEdbInfo.EdbInfoId, "", "", false)
|
|
|
+ default:
|
|
|
+ err = errors.New("指标change类型异常")
|
|
|
return
|
|
|
}
|
|
|
changeDataMap := make(map[string]float64)
|