|
@@ -12,10 +12,9 @@ import (
|
|
|
)
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData) {
|
|
|
+func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, dayList []time.Time, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData) {
|
|
|
newPredictEdbInfoData = predictEdbInfoData
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
|
for k, v := range dayList {
|
|
|
newPredictEdbInfoData = append(newPredictEdbInfoData, &EdbInfoSearchData{
|
|
@@ -31,7 +30,7 @@ func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, sta
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -39,7 +38,6 @@ func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
@@ -160,7 +158,7 @@ func PredictTbzDiv(a, b float64) (result float64) {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -168,7 +166,6 @@ func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
@@ -283,7 +280,7 @@ func PredictTczDiv(a, b float64) (result float64) {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -291,7 +288,6 @@ func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpK := index + k - 1
|
|
|
|
|
@@ -347,7 +343,7 @@ func PredictHbzDiv(a, b float64) (result float64) {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -355,7 +351,6 @@ func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpK := index + k - 1
|
|
|
|
|
@@ -405,7 +400,7 @@ func PredictHczDiv(a, b float64) (result float64) {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -422,7 +417,6 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
|
|
|
decimalN := decimal.NewFromInt(int64(nValue))
|
|
|
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpIndex := lenAllData + k - 1
|
|
|
|
|
@@ -463,7 +457,7 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
|
|
|
|
|
|
|
|
@@ -486,16 +480,16 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
|
|
|
|
|
|
|
|
|
|
|
|
- coordinateData := make([]Coordinate, 0)
|
|
|
+ coordinateData := make([]utils.Coordinate, 0)
|
|
|
for tmpK := nValue; tmpK > 0; tmpK-- {
|
|
|
tmpIndex2 := lenAllData - tmpK
|
|
|
- tmpCoordinate := Coordinate{
|
|
|
+ tmpCoordinate := utils.Coordinate{
|
|
|
X: float64(nValue - tmpK + 1),
|
|
|
Y: allDataList[tmpIndex2].Value,
|
|
|
}
|
|
|
coordinateData = append(coordinateData, tmpCoordinate)
|
|
|
}
|
|
|
- a, b := getLinearResult(coordinateData)
|
|
|
+ a, b := utils.GetLinearResult(coordinateData)
|
|
|
if math.IsNaN(a) || math.IsNaN(b) {
|
|
|
err = errors.New("线性方程公式生成失败")
|
|
|
return
|
|
@@ -504,7 +498,6 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
|
|
|
|
|
|
aDecimal := decimal.NewFromFloat(a)
|
|
|
bDecimal := decimal.NewFromFloat(b)
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpK := nValue + k + 1
|
|
|
|
|
@@ -532,49 +525,6 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-type Series []Coordinate
|
|
|
-
|
|
|
-
|
|
|
-type Coordinate struct {
|
|
|
- X, Y float64
|
|
|
-}
|
|
|
-
|
|
|
-func getLinearResult(s []Coordinate) (gradient, intercept float64) {
|
|
|
- if len(s) <= 1 {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- var sum [5]float64
|
|
|
-
|
|
|
-
|
|
|
- i := 0
|
|
|
- for ; i < len(s); i++ {
|
|
|
- sum[0] += s[i].X
|
|
|
- sum[1] += s[i].Y
|
|
|
- sum[2] += s[i].X * s[i].X
|
|
|
- sum[3] += s[i].X * s[i].Y
|
|
|
- sum[4] += s[i].Y * s[i].Y
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- f := float64(i)
|
|
|
- gradient = (f*sum[3] - sum[0]*sum[1]) / (f*sum[2] - sum[0]*sum[0])
|
|
|
- intercept = (sum[1] / f) - (gradient * sum[0] / f)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -588,7 +538,7 @@ func getLinearResult(s []Coordinate) (gradient, intercept float64) {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, hcDataMap, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -599,17 +549,6 @@ func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, start
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- hcDataMap := make(map[string]float64)
|
|
|
-
|
|
|
- tmpPredictEdbRuleDataList, err := GetPredictEdbRuleDataItemList(edbInfoId, configId, startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range tmpPredictEdbRuleDataList {
|
|
|
- hcDataMap[v.DataTime] = v.Value
|
|
|
- }
|
|
|
-
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
|
tmpLenAllDataList := len(allDataList)
|
|
@@ -658,7 +597,7 @@ func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, start
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -666,7 +605,6 @@ func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue
|
|
|
|
|
|
index := len(allDataList)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
lenDay := len(dayList)
|
|
|
if lenDay <= 0 {
|
|
|
return
|
|
@@ -744,7 +682,7 @@ type SeasonConf struct {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int, calendar string, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int, calendar string, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -800,7 +738,6 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
|
|
|
index := len(allDataList)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
|
|
|
|
|
|
predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
@@ -932,7 +869,7 @@ type MoveAverageConf struct {
|
|
|
|
|
|
|
|
|
|
|
|
-func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, year int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, year int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -949,7 +886,6 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
decimalN := decimal.NewFromInt(int64(nValue))
|
|
|
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpLenAllDataList := len(allDataList)
|
|
|
tmpIndex := tmpLenAllDataList - 1
|
|
@@ -1061,3 +997,378 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTbzscz(edbInfoId int, tbEndValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
+ allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
+ allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
+ allDataList = append(allDataList, predictEdbInfoData...)
|
|
|
+ newPredictEdbInfoData = predictEdbInfoData
|
|
|
+
|
|
|
+ index := len(allDataList)
|
|
|
+
|
|
|
+
|
|
|
+ if index <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lastData := allDataList[index-1]
|
|
|
+ lastDayTime, _ := time.ParseInLocation(utils.FormatDate, lastData.DataTime, time.Local)
|
|
|
+
|
|
|
+ var lastTb decimal.Decimal
|
|
|
+ {
|
|
|
+
|
|
|
+ preDate := lastDayTime.AddDate(-1, 0, 0)
|
|
|
+ preDateStr := preDate.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[preDateStr]; ok {
|
|
|
+ lastTb = decimal.NewFromFloat(lastData.Value).Div(decimal.NewFromFloat(preValue))
|
|
|
+ } else {
|
|
|
+ switch frequency {
|
|
|
+ case "月度":
|
|
|
+
|
|
|
+ nextDateDay := preDate
|
|
|
+ preDateDay := preDate
|
|
|
+ for i := 0; i <= 35; i++ {
|
|
|
+ nextDateDayStr := nextDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[nextDateDayStr]; ok {
|
|
|
+ lastTb = decimal.NewFromFloat(lastData.Value).Div(decimal.NewFromFloat(preValue))
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ preDateDayStr := preDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[preDateDayStr]; ok {
|
|
|
+ lastTb = decimal.NewFromFloat(lastData.Value).Div(decimal.NewFromFloat(preValue))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ nextDateDay = nextDateDay.AddDate(0, 0, 1)
|
|
|
+ preDateDay = preDateDay.AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+
|
|
|
+ case "季度", "年度":
|
|
|
+ if preValue, ok := existMap[preDateStr]; ok {
|
|
|
+ lastTb = decimal.NewFromFloat(lastData.Value).Div(decimal.NewFromFloat(preValue))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ nextDateDay := preDate
|
|
|
+ preDateDay := preDate
|
|
|
+
|
|
|
+ for i := 0; i < 35; i++ {
|
|
|
+ nextDateDayStr := nextDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[nextDateDayStr]; ok {
|
|
|
+ lastTb = decimal.NewFromFloat(lastData.Value).Div(decimal.NewFromFloat(preValue))
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ preDateDayStr := preDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[preDateDayStr]; ok {
|
|
|
+ lastTb = decimal.NewFromFloat(lastData.Value).Div(decimal.NewFromFloat(preValue))
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ nextDateDay = nextDateDay.AddDate(0, 0, 1)
|
|
|
+ preDateDay = preDateDay.AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ lenDay := len(dayList)
|
|
|
+ tbEndValueDecimal := decimal.NewFromFloat(tbEndValue)
|
|
|
+ avgTbVal := tbEndValueDecimal.Sub(lastTb).Div(decimal.NewFromInt(int64(lenDay)))
|
|
|
+
|
|
|
+ fmt.Println(lastTb.Float64())
|
|
|
+ fmt.Println(decimal.NewFromFloat(tbEndValue).Sub(lastTb))
|
|
|
+ fmt.Println(avgTbVal.Float64())
|
|
|
+
|
|
|
+ predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
|
+ for k, currentDate := range dayList {
|
|
|
+ var tbValue decimal.Decimal
|
|
|
+ if k == lenDay-1 {
|
|
|
+ tbValue = tbEndValueDecimal
|
|
|
+ } else {
|
|
|
+ tbValue = lastTb.Add(avgTbVal.Mul(decimal.NewFromInt(int64(k + 1))))
|
|
|
+ }
|
|
|
+ tmpData := &EdbInfoSearchData{
|
|
|
+ EdbDataId: edbInfoId + 100000 + index + k,
|
|
|
+
|
|
|
+ DataTime: currentDate.Format(utils.FormatDate),
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var val float64
|
|
|
+ var calculateStatus bool
|
|
|
+
|
|
|
+
|
|
|
+ preDate := currentDate.AddDate(-1, 0, 0)
|
|
|
+ preDateStr := preDate.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[preDateStr]; ok {
|
|
|
+ val, _ = decimal.NewFromFloat(preValue).Mul(tbValue).RoundCeil(4).Float64()
|
|
|
+ calculateStatus = true
|
|
|
+ } else {
|
|
|
+ switch frequency {
|
|
|
+ case "月度":
|
|
|
+
|
|
|
+ nextDateDay := preDate
|
|
|
+ preDateDay := preDate
|
|
|
+ for i := 0; i <= 35; i++ {
|
|
|
+ nextDateDayStr := nextDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[nextDateDayStr]; ok {
|
|
|
+ val, _ = decimal.NewFromFloat(preValue).Mul(tbValue).RoundCeil(4).Float64()
|
|
|
+ calculateStatus = true
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ preDateDayStr := preDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[preDateDayStr]; ok {
|
|
|
+ val, _ = decimal.NewFromFloat(preValue).Mul(tbValue).RoundCeil(4).Float64()
|
|
|
+ calculateStatus = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ nextDateDay = nextDateDay.AddDate(0, 0, 1)
|
|
|
+ preDateDay = preDateDay.AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+
|
|
|
+ case "季度", "年度":
|
|
|
+ if preValue, ok := existMap[preDateStr]; ok {
|
|
|
+ val, _ = decimal.NewFromFloat(preValue).Mul(tbValue).RoundCeil(4).Float64()
|
|
|
+ calculateStatus = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ nextDateDay := preDate
|
|
|
+ preDateDay := preDate
|
|
|
+
|
|
|
+ for i := 0; i < 35; i++ {
|
|
|
+ nextDateDayStr := nextDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[nextDateDayStr]; ok {
|
|
|
+ val, _ = decimal.NewFromFloat(preValue).Mul(tbValue).RoundCeil(4).Float64()
|
|
|
+ calculateStatus = true
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ preDateDayStr := preDateDay.Format(utils.FormatDate)
|
|
|
+ if preValue, ok := existMap[preDateDayStr]; ok {
|
|
|
+ val, _ = decimal.NewFromFloat(preValue).Mul(tbValue).RoundCeil(4).Float64()
|
|
|
+ calculateStatus = true
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ nextDateDay = nextDateDay.AddDate(0, 0, 1)
|
|
|
+ preDateDay = preDateDay.AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if calculateStatus {
|
|
|
+ tmpData.Value = val
|
|
|
+ newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
|
|
|
+ allDataList = append(allDataList, tmpData)
|
|
|
+ existMap[tmpData.DataTime] = val
|
|
|
+
|
|
|
+
|
|
|
+ if val < minValue {
|
|
|
+ minValue = val
|
|
|
+ }
|
|
|
+ if val > maxValue {
|
|
|
+ maxValue = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type RuleLineNhConf struct {
|
|
|
+ StartDate string `description:"开始日期"`
|
|
|
+ EndDate string `description:"结束日期"`
|
|
|
+ MoveDay int `description:"移动天数"`
|
|
|
+ EdbInfoId int `description:"指标id"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func GetChartPredictEdbInfoDataListByRuleLineNh(edbInfoId int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, newNhccDataMap, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
+ allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
+ allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
+ allDataList = append(allDataList, predictEdbInfoData...)
|
|
|
+ newPredictEdbInfoData = predictEdbInfoData
|
|
|
+
|
|
|
+ lenAllData := len(allDataList)
|
|
|
+ if lenAllData <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, currentDate := range dayList {
|
|
|
+
|
|
|
+ currentDateStr := currentDate.Format(utils.FormatDate)
|
|
|
+ val, ok := newNhccDataMap[currentDateStr]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ tmpData := &EdbInfoSearchData{
|
|
|
+ EdbDataId: edbInfoId + 100000 + lenAllData + k,
|
|
|
+
|
|
|
+ DataTime: currentDateStr,
|
|
|
+ Value: val,
|
|
|
+
|
|
|
+ }
|
|
|
+ newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
|
|
|
+ allDataList = append(allDataList, tmpData)
|
|
|
+ existMap[currentDateStr] = val
|
|
|
+
|
|
|
+
|
|
|
+ if val < minValue {
|
|
|
+ minValue = val
|
|
|
+ }
|
|
|
+ if val > maxValue {
|
|
|
+ maxValue = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func getCalculateNhccData(secondDataList []*EdbInfoSearchData, ruleConf RuleLineNhConf) (newBDataMap map[string]float64, err error) {
|
|
|
+ firstEdbInfoId := ruleConf.EdbInfoId
|
|
|
+ moveDay := ruleConf.MoveDay
|
|
|
+ startDate, _ := time.ParseInLocation(utils.FormatDate, ruleConf.StartDate, time.Local)
|
|
|
+ endDate, _ := time.ParseInLocation(utils.FormatDate, ruleConf.EndDate, time.Local)
|
|
|
+
|
|
|
+
|
|
|
+ edbInfo, err := GetEdbInfoById(firstEdbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ aDataList := make([]EdbInfoSearchData, 0)
|
|
|
+ aDataMap := make(map[string]float64)
|
|
|
+ {
|
|
|
+
|
|
|
+ var firstDataList []*EdbInfoSearchData
|
|
|
+ switch edbInfo.EdbInfoType {
|
|
|
+ case 0:
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += " AND edb_info_id=? "
|
|
|
+ pars = append(pars, edbInfo.EdbInfoId)
|
|
|
+
|
|
|
+
|
|
|
+ firstDataList, err = GetEdbDataListAll(condition, pars, edbInfo.Source, 1)
|
|
|
+ case 1:
|
|
|
+ firstDataList, err = GetPredictEdbDataListAllByStartDate(edbInfo, 1, "")
|
|
|
+ default:
|
|
|
+ err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ aDataList, aDataMap = handleNhccData(firstDataList, moveDay)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bDataList := make([]EdbInfoSearchData, 0)
|
|
|
+ bDataMap := make(map[string]float64)
|
|
|
+ {
|
|
|
+ bDataList, bDataMap = handleNhccData(secondDataList, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(aDataList) <= 0 {
|
|
|
+ err = errors.New("指标A没有数据")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(bDataList) <= 0 {
|
|
|
+ err = errors.New("指标B没有数据")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ endAData := aDataList[len(aDataList)-1]
|
|
|
+ tmpEndDate, tmpErr := time.ParseInLocation(utils.FormatDate, endAData.DataTime, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if tmpEndDate.Before(endDate) {
|
|
|
+ endDate = tmpEndDate
|
|
|
+ }
|
|
|
+ endBData := bDataList[len(bDataList)-1]
|
|
|
+ tmpEndDate, tmpErr = time.ParseInLocation(utils.FormatDate, endBData.DataTime, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if tmpEndDate.Before(endDate) {
|
|
|
+ endDate = tmpEndDate
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var a, b float64
|
|
|
+ {
|
|
|
+ coordinateData := make([]utils.Coordinate, 0)
|
|
|
+ for i := startDate; i.Before(endDate) || i.Equal(endDate); i = i.AddDate(0, 0, 1) {
|
|
|
+ dateStr := i.Format(utils.FormatDate)
|
|
|
+ xValue, ok := aDataMap[dateStr]
|
|
|
+ if !ok {
|
|
|
+ err = errors.New("指标A日期:" + dateStr + "数据异常,导致计算线性方程公式失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ yValue, ok := bDataMap[dateStr]
|
|
|
+ if !ok {
|
|
|
+ err = errors.New("指标B日期:" + dateStr + "数据异常,导致计算线性方程公式失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tmpCoordinate := utils.Coordinate{
|
|
|
+ X: xValue,
|
|
|
+ Y: yValue,
|
|
|
+ }
|
|
|
+ coordinateData = append(coordinateData, tmpCoordinate)
|
|
|
+ }
|
|
|
+ a, b = utils.GetLinearResult(coordinateData)
|
|
|
+ }
|
|
|
+
|
|
|
+ if math.IsNaN(a) || math.IsNaN(b) {
|
|
|
+ err = errors.New("线性方程公式生成失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ newBDataMap = make(map[string]float64)
|
|
|
+ {
|
|
|
+
|
|
|
+ aDecimal := decimal.NewFromFloat(a)
|
|
|
+ bDecimal := decimal.NewFromFloat(b)
|
|
|
+ for _, aData := range aDataList {
|
|
|
+ xDecimal := decimal.NewFromFloat(aData.Value)
|
|
|
+ val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).RoundCeil(4).Float64()
|
|
|
+ newBDataMap[aData.DataTime] = val
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|