|
@@ -8,6 +8,7 @@ import (
|
|
|
"hongze/hongze_chart_lib/models"
|
|
|
"hongze/hongze_chart_lib/models/data_manage"
|
|
|
"hongze/hongze_chart_lib/utils"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -30,9 +31,9 @@ func GetChartPredictEdbInfoDataListByRule1(edbInfoId int, dataValue float64, sta
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 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。
|
|
|
+// 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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -161,9 +162,9 @@ func TbzDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 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
|
|
|
+// 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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -286,9 +287,9 @@ func TczDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 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
|
|
|
+// 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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -352,9 +353,9 @@ func HbzDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetChartPredictEdbInfoDataListByRuleHc 根据环差值规则获取预测数据
|
|
|
-// 2.4 环差:在未来某一个时间段内,给定一个固定的环比增加值a,用上一期值X加上环比增加值a,得到预测值Y=X+a
|
|
|
-// 例: 最近1期值为100,给定环比增加值a=10,则未来3期预测值为: 100+10=110,110+10=120,120+10=130
|
|
|
+// 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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -412,9 +413,9 @@ func HczDiv(a, b float64) (result float64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 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依次类推。
|
|
|
+// 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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -470,11 +471,11 @@ func GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(edbInfoId int, nValue in
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetChartPredictEdbInfoDataListByRuleNLinearRegression 根据N期移动均值规则获取预测数据
|
|
|
-// 2.6N期段线性外推值:给出过去N期值所确定的线性回归方程(Y=aX+b)在未来一段时间内的推算值。回归方程虽然比较复杂,但各种编程语言应该都有现成的模块或函数,应该无需自己编写。
|
|
|
-// 例1:过去5期值(N=5)分别为:3,5,7,9,11(每两期值之间的时间间隔相等)。那么按照线性回归方程推算,未来三期的预测值是:13,15,17。
|
|
|
+// GetChartPredictEdbInfoDataListByRuleNLinearRegression 根据N期移动均值规则获取预测数据
|
|
|
+// 2.6N期段线性外推值:给出过去N期值所确定的线性回归方程(Y=aX+b)在未来一段时间内的推算值。回归方程虽然比较复杂,但各种编程语言应该都有现成的模块或函数,应该无需自己编写。
|
|
|
+// 例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的区别在于,多加了一期数据,导致回归方程发生改变,从而预测值不同。
|
|
|
+// 例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) {
|
|
|
//var errMsg string
|
|
|
//defer func() {
|
|
@@ -587,17 +588,18 @@ func getLinearResult(s []Coordinate) (gradient, intercept float64) {
|
|
|
}
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByRuleTrendsHC 根据动态环比增加值的计算规则获取预测数据
|
|
|
+//
|
|
|
// 研究员有对预测指标进行动态环差计算的需求,即预测指标使用环差规则进行预测时,环比增加值不是固定值,而是由几个预测指标计算得出的动态变化的值;
|
|
|
-//需求说明:
|
|
|
-//1、增加“动态环差”预测规则;
|
|
|
-//2、环比增加值在弹窗设置;
|
|
|
-//3、动态环差预测举例:
|
|
|
-//指标A实际最新数据为2022-10-27(100);
|
|
|
-//预测指标B预测数据为2022-10-28(240)、2022-10-29(300);
|
|
|
-//预测指标C预测数据为2022-10-28(260)、2022-10-29(310);
|
|
|
-//计算公式为B-C;
|
|
|
-//则指标A至2022-10-29的预测值为2022-10-28(100+(240-260)=80)、2022-10-29(80+(300-310)=90);
|
|
|
-//注:动态环比增加值的计算遵从计算指标的计算规则,即用于计算的指标若有部分指标缺少部分日期数据,则这部分日期数据不做计算,为空;若动态环比增加值某一天为空,则往前追溯最近一期有值的环比增加值作为该天的数值参与计算;
|
|
|
+// 需求说明:
|
|
|
+// 1、增加“动态环差”预测规则;
|
|
|
+// 2、环比增加值在弹窗设置;
|
|
|
+// 3、动态环差预测举例:
|
|
|
+// 指标A实际最新数据为2022-10-27(100);
|
|
|
+// 预测指标B预测数据为2022-10-28(240)、2022-10-29(300);
|
|
|
+// 预测指标C预测数据为2022-10-28(260)、2022-10-29(310);
|
|
|
+// 计算公式为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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -659,14 +661,15 @@ func GetChartPredictEdbInfoDataListByRuleTrendsHC(edbInfoId, configId int, start
|
|
|
}
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByRuleFinalValueHc 根据 给定终值后插值 规则获取预测数据
|
|
|
+//
|
|
|
// 项目背景:
|
|
|
-//假设螺纹产量在2023年1月1号的预测值是255万吨,从当下到2023年1月1号,螺纹产量将会线性变化,那么每一期的螺纹产量是多少?
|
|
|
-//算法:从当下(2022/10/28)到2023/1/1号,一共65天,从当前值(305.02)到255,差值-50.02,
|
|
|
-//则每日环差为-50.02/65=-0.7695。因为数据点是周度频率,每周环差为,-0.3849*7=-5.3868。
|
|
|
-//从以上计算过程可看出,“给定终值后差值”的算法,是在“环差”算法的基础上,做的一个改动。即这个”环差值”=【(终值-最新值)/终值与最新值得日期差】*数据频率
|
|
|
-//需求说明:
|
|
|
-//1、增加一个预测规则,名为“给定终值后插值”,给定预测截止日期和预测终值,计算最新数据日期至预测截止日期的时间差T,计算最新数据和预测终值的数据差S,数据频率与指标频度有关,日度=1,周度=7,旬度=10,月度=30,季度=90,年度=365,环差值=S/T*频率,预测数值=前一天数值+环差值;
|
|
|
-//2、最新数据值和日期改动后,需重新计算环差值和预测数值;
|
|
|
+// 假设螺纹产量在2023年1月1号的预测值是255万吨,从当下到2023年1月1号,螺纹产量将会线性变化,那么每一期的螺纹产量是多少?
|
|
|
+// 算法:从当下(2022/10/28)到2023/1/1号,一共65天,从当前值(305.02)到255,差值-50.02,
|
|
|
+// 则每日环差为-50.02/65=-0.7695。因为数据点是周度频率,每周环差为,-0.3849*7=-5.3868。
|
|
|
+// 从以上计算过程可看出,“给定终值后差值”的算法,是在“环差”算法的基础上,做的一个改动。即这个”环差值”=【(终值-最新值)/终值与最新值得日期差】*数据频率
|
|
|
+// 需求说明:
|
|
|
+// 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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|
|
@@ -733,31 +736,39 @@ type SeasonConf struct {
|
|
|
}
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByRuleSeason 根据 季节性 规则获取预测数据
|
|
|
+//
|
|
|
// ETA预测规则:季节性
|
|
|
-//已知选定指标A最近更新日期: 2022-12-6 200
|
|
|
-//设置预测截止日期2023-01-06
|
|
|
-//1、选择过去N年,N=3
|
|
|
-//则过去N年为2021、2020、2019
|
|
|
-//指标A日期 实际值 指标A日期
|
|
|
-//2019/12/5 150 2019/12/6
|
|
|
-//2020/12/5 180 2020/12/6
|
|
|
-//2021/12/5 210 2021/12/6
|
|
|
-//2019/12/31 200 2020/1/1
|
|
|
-//2020/12/31 210 2021/1/1
|
|
|
-//2021/12/31 250 2022/1/1
|
|
|
+// 已知选定指标A最近更新日期: 2022-12-6 200
|
|
|
+// 设置预测截止日期2023-01-06
|
|
|
+// 1、选择过去N年,N=3
|
|
|
+// 则过去N年为2021、2020、2019
|
|
|
+// 指标A日期 实际值 指标A日期
|
|
|
+// 2019/12/5 150 2019/12/6
|
|
|
+// 2020/12/5 180 2020/12/6
|
|
|
+// 2021/12/5 210 2021/12/6
|
|
|
+// 2019/12/31 200 2020/1/1
|
|
|
+// 2020/12/31 210 2021/1/1
|
|
|
+// 2021/12/31 250 2022/1/1
|
|
|
//
|
|
|
-//计算12.7预测值,求过去N年环差均值=[(100-150)+(160-180)+(250-210)]/3=-10
|
|
|
-//则12.7预测值=12.6值+过去N年环差均值=200-10=190
|
|
|
-//以此类推...
|
|
|
+// 计算12.7预测值,求过去N年环差均值=[(100-150)+(160-180)+(250-210)]/3=-10
|
|
|
+// 则12.7预测值=12.6值+过去N年环差均值=200-10=190
|
|
|
+// 以此类推...
|
|
|
//
|
|
|
-//计算2023.1.2预测值,求过去N年环差均值=[(300-200)+(220-210)+(260-250)]/3=40
|
|
|
-//则2023.1.2预测值=2023.1.1值+过去N年环差均值
|
|
|
+// 计算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) {
|
|
|
allDataList := make([]*models.EdbDataList, 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) // 每个年份的春节公历
|
|
|
{
|
|
@@ -806,13 +817,18 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
//获取后面的预测数据
|
|
|
predictEdbInfoData = make([]*models.EdbDataList, 0)
|
|
|
for k, currentDate := range dayList {
|
|
|
+ // 如果遇到闰二月,如2.29,去掉该天数据
|
|
|
+ if strings.Contains(currentDate.Format(utils.FormatDate), "02-29") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
tmpHistoryVal := decimal.NewFromFloat(0) //往期的差值总和
|
|
|
tmpHistoryValNum := 0 // 往期差值计算的数量
|
|
|
|
|
|
tmpLenAllDataList := len(allDataList)
|
|
|
- tmpK := tmpLenAllDataList - 1 //上1期数据的下标
|
|
|
- lastDayStr := allDataList[tmpK].DataTime
|
|
|
- lastDayVal := allDataList[tmpK].Value
|
|
|
+ tmpK := tmpLenAllDataList - 1 //上1期数据的下标
|
|
|
+ lastDayData := allDataList[tmpK] // 上1期的数据
|
|
|
+ lastDayStr := lastDayData.DataTime
|
|
|
+ lastDayVal := lastDayData.Value
|
|
|
lastDay, tmpErr := time.ParseInLocation(utils.FormatDate, lastDayStr, time.Local)
|
|
|
if tmpErr != nil {
|
|
|
err = errors.New("获取上期日期转换失败:" + tmpErr.Error())
|
|
@@ -823,16 +839,16 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
var isFindHistoryCurrent, isFindHistoryLast bool //是否找到前几年的数据
|
|
|
|
|
|
//前几年当日的日期
|
|
|
- tmpHistoryCurrentDate := currentDate.AddDate(year-currentDate.Year(), 0, moveDay)
|
|
|
+ tmpHistoryCurrentDate := currentDate.AddDate(year-currentDate.Year(), 0, -moveDay)
|
|
|
for i := 0; i <= 35; i++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找
|
|
|
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
|
|
@@ -841,16 +857,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++ { // 前后35天找数据,找到最近的值,先向后面找,再往前面找
|
|
|
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
|
|
@@ -876,16 +892,24 @@ func GetChartPredictEdbInfoDataListByRuleSeason(edbInfoId int, yearsList []int,
|
|
|
|
|
|
currentDateStr := currentDate.Format(utils.FormatDate)
|
|
|
tmpData := &models.EdbDataList{
|
|
|
- EdbDataId: edbInfoId + 10000000000 + index + k,
|
|
|
- EdbInfoId: edbInfoId,
|
|
|
- DataTime: currentDateStr,
|
|
|
- Value: val,
|
|
|
- DataTimestamp: (currentDate.UnixNano() / 1e6) + 1000, //前端需要让加1s,说是2022-09-01 00:00:00 这样的整点不合适
|
|
|
+ EdbDataId: edbInfoId + 10000000000 + index + k,
|
|
|
+ //EdbInfoId: edbInfoId,
|
|
|
+ DataTime: currentDateStr,
|
|
|
+ Value: val,
|
|
|
+ //DataTimestamp: (currentDate.UnixNano() / 1e6) + 1000, //前端需要让加1s,说是2022-09-01 00:00:00 这样的整点不合适
|
|
|
}
|
|
|
newPredictEdbInfoData = append(newPredictEdbInfoData, tmpData)
|
|
|
allDataList = append(allDataList, tmpData)
|
|
|
existMap[currentDateStr] = val
|
|
|
|
|
|
+ // 继续使用插值法补充新预测日期的数据之间的值
|
|
|
+ err = HandleDataByLinearRegression([]*models.EdbDataList{
|
|
|
+ lastDayData, tmpData,
|
|
|
+ }, handleDataMap)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 最大最小值
|
|
|
if val < minValue {
|
|
|
minValue = val
|
|
@@ -904,21 +928,22 @@ type MoveAverageConf struct {
|
|
|
}
|
|
|
|
|
|
// GetChartPredictEdbInfoDataListByRuleMoveAverageTb 根据 移动平均同比 规则获取预测数据
|
|
|
+//
|
|
|
// ETA预测规则:季节性
|
|
|
-//2、选择指定N年,N=3
|
|
|
-//指定N年为2012、2015、2018
|
|
|
-//指标A日期 实际值 指标A日期 实际值
|
|
|
-//2012/12/5 150 2012/12/6 130
|
|
|
-//2015/12/5 180 2015/12/6 150
|
|
|
-//2018/12/5 210 2018/12/6 260
|
|
|
-//2012/12/31 200 2013/1/1 200
|
|
|
-//2015/12/31 210 2016/1/1 250
|
|
|
-//2018/12/31 250 2019/1/1 270
|
|
|
-//计算12.7预测值,求过去N年环差均值=[(130-150)+(150-180)+(290-210)]/3=10
|
|
|
-//则12.7预测值=12.6值+过去N年环差均值=200+10=210
|
|
|
-//以此类推...
|
|
|
-//计算2023.1.2预测值,求过去N年环差均值=[(200-200)+(250-210)+(270-250)]/3=16.67
|
|
|
-//则2023.1.2预测值=2023.1.1值+过去N年环差均值
|
|
|
+// 2、选择指定N年,N=3
|
|
|
+// 指定N年为2012、2015、2018
|
|
|
+// 指标A日期 实际值 指标A日期 实际值
|
|
|
+// 2012/12/5 150 2012/12/6 130
|
|
|
+// 2015/12/5 180 2015/12/6 150
|
|
|
+// 2018/12/5 210 2018/12/6 260
|
|
|
+// 2012/12/31 200 2013/1/1 200
|
|
|
+// 2015/12/31 210 2016/1/1 250
|
|
|
+// 2018/12/31 250 2019/1/1 270
|
|
|
+// 计算12.7预测值,求过去N年环差均值=[(130-150)+(150-180)+(290-210)]/3=10
|
|
|
+// 则12.7预测值=12.6值+过去N年环差均值=200+10=210
|
|
|
+// 以此类推...
|
|
|
+// 计算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) {
|
|
|
allDataList := make([]*models.EdbDataList, 0)
|
|
|
allDataList = append(allDataList, realPredictEdbInfoData...)
|