|
@@ -16,10 +16,9 @@ import (
|
|
|
)
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByRule1 根据规则1获取预测数据
|
|
|
-func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, startDate, endDate time.Time, frequency string, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList) {
|
|
|
+func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, dayList []time.Time, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList) {
|
|
|
newPredictEdbInfoData = predictEdbInfoData
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*edbDataModel.EdbDataList, 0)
|
|
|
for k, v := range dayList {
|
|
|
newPredictEdbInfoData = append(newPredictEdbInfoData, &edbDataModel.EdbDataList{
|
|
@@ -37,7 +36,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -45,7 +44,6 @@ func GetChartPredictEdbInfoDataListByRuleTb(edbInfoId int, tbValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*edbDataModel.EdbDataList, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
@@ -164,7 +162,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, dayList []time.Time, frequency string, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -172,7 +170,6 @@ func GetChartPredictEdbInfoDataListByRuleTc(edbInfoId int, tcValue float64, star
|
|
|
|
|
|
index := len(allDataList)
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
predictEdbInfoData = make([]*edbDataModel.EdbDataList, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
|
|
@@ -289,7 +286,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleHb(edbInfoId int, hbValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -297,7 +294,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期的值
|
|
|
|
|
@@ -355,7 +351,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleHc(edbInfoId int, hcValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -363,7 +359,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期的值
|
|
|
|
|
@@ -415,7 +410,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -432,7 +427,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期的值
|
|
|
|
|
@@ -475,7 +469,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
//var errMsg string
|
|
|
//defer func() {
|
|
|
// if errMsg != `` {
|
|
@@ -514,7 +508,6 @@ func GetChartPredictEdbInfoDataListByRuleNLinearRegression(edbInfoId int, nValue
|
|
|
}
|
|
|
//fmt.Println("a:", a, ";======b:", b)
|
|
|
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
for k, currentDate := range dayList {
|
|
|
tmpK := nValue + k + 1
|
|
|
|
|
@@ -603,7 +596,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, startDate, endDate time.Time, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -624,7 +617,7 @@ func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, start
|
|
|
for _, v := range tmpPredictEdbRuleDataList {
|
|
|
hcDataMap[v.DataTime.Format(utils.FormatDate)] = v.Value
|
|
|
}
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
+
|
|
|
for k, currentDate := range dayList {
|
|
|
// 最近一条数据
|
|
|
tmpLenAllDataList := len(allDataList)
|
|
@@ -673,15 +666,14 @@ 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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleFinalValueHc(edbInfoId int, finalValue float64, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
|
newPredictEdbInfoData = predictEdbInfoData
|
|
|
|
|
|
index := len(allDataList)
|
|
|
- //获取后面的预测日期
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
+
|
|
|
lenDay := len(dayList)
|
|
|
if lenDay <= 0 {
|
|
|
return
|
|
@@ -759,7 +751,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int, calendar string, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -814,8 +806,6 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
}
|
|
|
|
|
|
index := len(allDataList)
|
|
|
- //获取后面的预测日期
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
|
|
|
//获取后面的预测数据
|
|
|
predictEdbInfoData = make([]*edbDataModel.EdbDataList, 0)
|
|
@@ -947,7 +937,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 []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
+func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, year int, dayList []time.Time, realPredictEdbInfoData, predictEdbInfoData []*edbDataModel.EdbDataList, existMap map[string]float64) (newPredictEdbInfoData []*edbDataModel.EdbDataList, minValue, maxValue float64, err error) {
|
|
|
allDataList := make([]*edbDataModel.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
|
allDataList = append(allDataList, predictEdbInfoData...)
|
|
@@ -964,7 +954,6 @@ func GetChartPredictEdbInfoDataListByRuleMoveAverageTb(edbInfoId int, nValue, ye
|
|
|
decimalN := decimal.NewFromInt(int64(nValue))
|
|
|
|
|
|
//获取后面的预测数据
|
|
|
- dayList := getPredictEdbDayList(startDate, endDate, frequency)
|
|
|
if len(dayList) <= 0 {
|
|
|
return
|
|
|
}
|