|
@@ -3,6 +3,7 @@ package stl
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
+ "eta/eta_api/models/data_manage/stl"
|
|
|
"eta/eta_api/models/data_manage/stl/request"
|
|
|
"eta/eta_api/models/data_manage/stl/response"
|
|
|
"eta/eta_api/services/data/data_manage_permission"
|
|
@@ -27,7 +28,11 @@ const (
|
|
|
RANGE_DATE_TO_NOW
|
|
|
)
|
|
|
|
|
|
-func GenerateStlEdbData(req *request.STLReq, adminId int) (resp *response.StlPreviewResp, msg string, err error) {
|
|
|
+var EDB_DATA_CALCULATE_STL_TREND_CACHE = `eta:stl_decompose:trend:config_id:`
|
|
|
+var EDB_DATA_CALCULATE_STL_SEASONAL_CACHE = `eta:stl_decompose:seasonal:config_id:`
|
|
|
+var EDB_DATA_CALCULATE_STL_RESIDUAL_CACHE = `eta:stl_decompose:residual:config_id:`
|
|
|
+
|
|
|
+func GenerateStlEdbData(req *request.StlConfigReq, adminId int) (resp *response.StlPreviewResp, msg string, err error) {
|
|
|
edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
@@ -124,12 +129,10 @@ func GenerateStlEdbData(req *request.STLReq, adminId int) (resp *response.StlPre
|
|
|
defer os.Remove(loadFilePath)
|
|
|
|
|
|
saveFilePath := exPath + "/" + strconv.Itoa(adminId) + "_" + time.Now().Format(utils.FormatDateTimeUnSpace) + "_res" + ".xlsx"
|
|
|
- t1 := time.Now()
|
|
|
result, err := execStlPythonCode(loadFilePath, saveFilePath, req.Period, req.Seasonal, req.Trend, req.TrendDeg, req.SeasonalDeg, req.LowPassDeg, req.Fraction, req.Robust)
|
|
|
if err != nil {
|
|
|
msg = "计算失败,请重新选择指标和参数后计算"
|
|
|
}
|
|
|
- fmt.Println("stl计算耗时:", time.Since(t1))
|
|
|
trendChart, seasonalChart, residualChart, err := ParseStlExcel(saveFilePath)
|
|
|
if err != nil {
|
|
|
msg = "解析Excel失败"
|
|
@@ -158,6 +161,10 @@ func GenerateStlEdbData(req *request.STLReq, adminId int) (resp *response.StlPre
|
|
|
resp.EvaluationResult.AdfPValue = strconv.FormatFloat(result.AdfPValue, 'f', -1, 64)
|
|
|
resp.EvaluationResult.LjungBoxPValue = strconv.FormatFloat(result.LbTestPValue, 'f', -1, 64)
|
|
|
|
|
|
+ utils.Rc.Put(EDB_DATA_CALCULATE_STL_TREND_CACHE+strconv.Itoa(req.CalculateStlConfigId)+":"+resp.TrendChartInfo.Title, trendChart, time.Hour)
|
|
|
+ utils.Rc.Put(EDB_DATA_CALCULATE_STL_TREND_CACHE+strconv.Itoa(req.CalculateStlConfigId)+":"+resp.SeasonalChartInfo.Title, seasonalChart, time.Hour)
|
|
|
+ utils.Rc.Put(EDB_DATA_CALCULATE_STL_TREND_CACHE+strconv.Itoa(req.CalculateStlConfigId)+":"+resp.ResidualChartInfo.Title, residualChart, time.Hour)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -354,6 +361,17 @@ print(output)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func SaveStlConfig(req *request.StlConfigReq, adminId int) (insertId int64, err error) {
|
|
|
+ conf := new(stl.CalculateStlConfig)
|
|
|
+ b, _ := json.Marshal(req)
|
|
|
+ conf.Config = string(b)
|
|
|
+ conf.SysUserId = adminId
|
|
|
+ conf.CreateTime = time.Now()
|
|
|
+ conf.ModifyTime = time.Now()
|
|
|
+ insertId, err = conf.Insert()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func SearchEdbInfoWithStl(adminId int, keyWord string, currentIndex, pageSize int) (resp data_manage.EdbInfoFilterDataResp, msg string, err error) {
|
|
|
var edbInfoList []*data_manage.EdbInfoList
|
|
|
|