|
@@ -15,10 +15,9 @@ import (
|
|
|
)
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByRule1 根据规则1获取预测数据
|
|
|
-func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList) {
|
|
|
+func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, dayList []time.Time, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList) {
|
|
|
newPredictEdbInfoData = predictEdbInfoData
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*models.EdbDataList, 0)
|
|
|
for k, v := range dayList {
|
|
|
newPredictEdbInfoData = append(newPredictEdbInfoData, &models.EdbDataList{
|
|
@@ -36,7 +35,7 @@ func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, sta
|
|
|
// GetChartPredictEdbInfoDataListByRuleTb 根据同比值规则获取预测数据
|
|
|
// 2.1 同比: 在未来某一个时间段内,给定一个固定的同比增速a,用去年同期值X乘以同比增速(1+a),得到预测值Y=X(1+a)
|
|
|
// 例: 今年1-3月值,100,100,120。给定同比增速a=0.1,则明年1-3月预测值为: 100*1.1=110,100*1.1=110,120*1.1=132。
|
|
|
-func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -44,7 +43,6 @@ func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*models.EdbDataList, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
@@ -163,7 +161,7 @@ func TbzDiv(a, b float64) (result float64) {
|
|
|
// GetChartPredictEdbInfoDataListByRuleTc 根据同差值规则获取预测数据
|
|
|
// 2.2 同差: 在未来某一个时间段内,给定一个固定的同比增加值a,用去年同期值X加上同比增加值A,得到预测值Y=X+a
|
|
|
// 例: 今年1-3月值,100,100,120。给定同比增加值a=10,则明年1-3月预测值为: 100+10=110,100+10=110,120+10=130
|
|
|
-func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -171,7 +169,6 @@ func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*models.EdbDataList, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
@@ -288,7 +285,7 @@ func TczDiv(a, b float64) (result float64) {
|
|
|
// GetChartPredictEdbInfoDataListByRuleHb 根据环比值规则获取预测数据
|
|
|
// 环比:在未来某一个时间段内,给定一个固定的环比增速a,用上一期值X乘以环比增速(1+a),得到预测值Y=X(1+a)
|
|
|
// 例: 最近1期值为100,给定环比增速a=0.2,则未来3期预测值为: 100*1.2=120,120*1.2=144,144*1.2=172.8
|
|
|
-func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -296,7 +293,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 //上1期的值
|
|
|
|
|
@@ -354,7 +350,7 @@ func HbzDiv(a, b float64) (result float64) {
|
|
|
// GetChartPredictEdbInfoDataListByRuleHc 根据环差值规则获取预测数据
|
|
|
// 2.4 环差:在未来某一个时间段内,给定一个固定的环比增加值a,用上一期值X加上环比增加值a,得到预测值Y=X+a
|
|
|
// 例: 最近1期值为100,给定环比增加值a=10,则未来3期预测值为: 100+10=110,110+10=120,120+10=130
|
|
|
-func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -362,7 +358,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 //上1期的值
|
|
|
|
|
@@ -414,7 +409,7 @@ func HczDiv(a, b float64) (result float64) {
|
|
|
// GetChartPredictEdbInfoDataListByRuleNMoveMeanValue 根据N期移动均值规则获取预测数据
|
|
|
// 2.5 N期移动均值:在未来某一个时间段内,下一期值等于过去N期值得平均值。
|
|
|
// 例:最近3期值(N=3),为95,98,105则未来第1期值为 1/3*(95+98+105)=99.33, 未来第2期值为 1/3*(98+105+99.33)=100.78依次类推。
|
|
|
-func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -431,7 +426,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 //上1期的值
|
|
|
|
|
@@ -474,7 +468,7 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
|
|
|
// 例1:过去5期值(N=5)分别为:3,5,7,9,11(每两期值之间的时间间隔相等)。那么按照线性回归方程推算,未来三期的预测值是:13,15,17。
|
|
|
//
|
|
|
// 例2:过去6期值(N=6)分别为:3,3,5,7,9,11(每两期值之间的时间间隔相等)。那么按照线性回归方程推算,未来三期的预测值是:12.33,14.05,15.76。例1和例2的区别在于,多加了一期数据,导致回归方程发生改变,从而预测值不同。
|
|
|
-func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
//var errMsg string
|
|
|
//defer func() {
|
|
|
// if errMsg != `` {
|
|
@@ -509,7 +503,6 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
|
|
|
a, b := getLinearResult(coordinateData)
|
|
|
//fmt.Println("a:", a, ";======b:", b)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpK := nValue + k + 1
|
|
|
|
|
@@ -598,7 +591,7 @@ func getLinearResult(s []Coordinate) (gradient, intercept float64) {
|
|
|
// 计算公式为B-C;
|
|
|
// 则指标A至2022-10-29的预测值为2022-10-28(100+(240-260)=80)、2022-10-29(80+(300-310)=90);
|
|
|
// 注:动态环比增加值的计算遵从计算指标的计算规则,即用于计算的指标若有部分指标缺少部分日期数据,则这部分日期数据不做计算,为空;若动态环比增加值某一天为空,则往前追溯最近一期有值的环比增加值作为该天的数值参与计算;
|
|
|
-func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, startDate, endDate time.Time, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -619,7 +612,6 @@ func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, start
|
|
|
for _, v := range tmpPredictEdbRuleDataList {
|
|
|
hcDataMap[v.DataTime] = v.Value
|
|
|
}
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
// 最近一条数据
|
|
|
tmpLenAllDataList := len(allDataList)
|
|
@@ -668,7 +660,7 @@ func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, start
|
|
|
// 需求说明:
|
|
|
// 1、增加一个预测规则,名为“给定终值后插值”,给定预测截止日期和预测终值,计算最新数据日期至预测截止日期的时间差T,计算最新数据和预测终值的数据差S,数据频率与指标频度有关,日度=1,周度=7,旬度=10,月度=30,季度=90,年度=365,环差值=S/T*频率,预测数值=前一天数值+环差值;
|
|
|
// 2、最新数据值和日期改动后,需重新计算环差值和预测数值;
|
|
|
-func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue float64, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -676,7 +668,6 @@ func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue
|
|
|
|
|
|
index := len(allDataList)
|
|
|
//获取后面的预测日期
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
lenDay := len(dayList)
|
|
|
if lenDay <= 0 {
|
|
|
return
|
|
@@ -754,7 +745,7 @@ type SeasonConf struct {
|
|
|
//
|
|
|
// 计算2023.1.2预测值,求过去N年环差均值=[(300-200)+(220-210)+(260-250)]/3=40
|
|
|
// 则2023.1.2预测值=2023.1.1值+过去N年环差均值
|
|
|
-func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int, calendar string, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int, calendar string, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -809,8 +800,6 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
}
|
|
|
|
|
|
index := len(allDataList)
|
|
|
- //获取后面的预测日期
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
|
|
|
//获取后面的预测数据
|
|
|
predictEdbInfoData = make([]*models.EdbDataList, 0)
|
|
@@ -942,7 +931,7 @@ type MoveAverageConf struct {
|
|
|
// 以此类推...
|
|
|
// 计算2023.1.2预测值,求过去N年环差均值=[(200-200)+(250-210)+(270-250)]/3=16.67
|
|
|
// 则2023.1.2预测值=2023.1.1值+过去N年环差均值
|
|
|
-func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, year int, startDate, endDate time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, year int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*models.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*models.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -959,7 +948,6 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
decimalN := decimal.NewFromInt(int64(nValue))
|
|
|
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
if len(dayList) <= 0 {
|
|
|
return
|
|
|
}
|