|
@@ -7,6 +7,7 @@ import (
|
|
|
"github.com/shopspring/decimal"
|
|
|
"hongze/hongze_edb_lib/utils"
|
|
|
"math"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -27,9 +28,9 @@ func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, sta
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -156,9 +157,9 @@ func PredictTbzDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -279,9 +280,9 @@ func PredictTczDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -343,9 +344,9 @@ func PredictHbzDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -401,9 +402,9 @@ func PredictHczDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*EdbInfoSearchData, existMap map[string]float64) (newPredictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -457,11 +458,11 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
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) {
|
|
|
|
|
|
|
|
@@ -575,17 +576,18 @@ 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) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -647,14 +649,15 @@ 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) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -721,31 +724,39 @@ 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) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
|
newPredictEdbInfoData = predictEdbInfoData
|
|
|
|
|
|
+
|
|
|
+ handleDataMap := make(map[string]float64)
|
|
|
+ err = HandleDataByLinearRegression(allDataList, handleDataMap)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
moveDayMap := make(map[int]int, 0)
|
|
|
{
|
|
@@ -794,13 +805,18 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
|
|
|
predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
+
|
|
|
+ if strings.Contains(currentDate.Format(utils.FormatDate), "02-29") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
tmpHistoryVal := decimal.NewFromFloat(0)
|
|
|
tmpHistoryValNum := 0
|
|
|
|
|
|
tmpLenAllDataList := len(allDataList)
|
|
|
- tmpK := tmpLenAllDataList - 1
|
|
|
- lastDayStr := allDataList[tmpK].DataTime
|
|
|
- lastDayVal := allDataList[tmpK].Value
|
|
|
+ tmpK := tmpLenAllDataList - 1
|
|
|
+ lastDayData := allDataList[tmpK]
|
|
|
+ lastDayStr := lastDayData.DataTime
|
|
|
+ lastDayVal := lastDayData.Value
|
|
|
lastDay, tmpErr := time.ParseInLocation(utils.FormatDate, lastDayStr, time.Local)
|
|
|
if tmpErr != nil {
|
|
|
err = errors.New("获取上期日期转换失败:" + tmpErr.Error())
|
|
@@ -814,13 +830,13 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
tmpHistoryCurrentDate := currentDate.AddDate(year-currentDate.Year(), 0, -moveDay)
|
|
|
for i := 0; i <= 35; i++ {
|
|
|
tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, i)
|
|
|
- if val, ok := existMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
+ if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
tmpHistoryCurrentVal = val
|
|
|
isFindHistoryCurrent = true
|
|
|
break
|
|
|
} else {
|
|
|
tmpDate := tmpHistoryCurrentDate.AddDate(0, 0, -i)
|
|
|
- if val, ok := existMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
+ if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
tmpHistoryCurrentVal = val
|
|
|
isFindHistoryCurrent = true
|
|
|
break
|
|
@@ -829,16 +845,16 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
}
|
|
|
|
|
|
|
|
|
- tmpHistoryLastDate := lastDay.AddDate(year-lastDay.Year(), 0, moveDay)
|
|
|
+ tmpHistoryLastDate := lastDay.AddDate(year-lastDay.Year(), 0, -moveDay)
|
|
|
for i := 0; i <= 35; i++ {
|
|
|
tmpDate := tmpHistoryLastDate.AddDate(0, 0, i)
|
|
|
- if val, ok := existMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
+ if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
tmpHistoryLastVal = val
|
|
|
isFindHistoryLast = true
|
|
|
break
|
|
|
} else {
|
|
|
tmpDate := tmpHistoryLastDate.AddDate(0, 0, -i)
|
|
|
- if val, ok := existMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
+ if val, ok := handleDataMap[tmpDate.Format(utils.FormatDate)]; ok {
|
|
|
tmpHistoryLastVal = val
|
|
|
isFindHistoryLast = true
|
|
|
break
|
|
@@ -874,6 +890,14 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
allDataList = append(allDataList, tmpData)
|
|
|
existMap[currentDateStr] = val
|
|
|
|
|
|
+
|
|
|
+ err = HandleDataByLinearRegression([]*EdbInfoSearchData{
|
|
|
+ lastDayData, tmpData,
|
|
|
+ }, handleDataMap)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if val < minValue {
|
|
|
minValue = val
|
|
@@ -892,21 +916,22 @@ 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) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|