Browse Source

Merge branch 'bzq1/stl' of eta_server/eta_api into debug

baoziqiang 4 months ago
parent
commit
d250bed262

+ 1 - 1
models/data_manage/stl/request/stl.go

@@ -6,7 +6,7 @@ type StlConfigReq struct {
 	DataRangeType        int     `description:"数据时间类型:1-全部时间,2-最近N年,3-区间设置,4-区间设置(至今)"`
 	StartDate            string  `description:"开始日期"`
 	EndDate              string  `description:"结束日期"`
-	LastNYear            int     `description:"最近N年"`
+	LastNYear            string  `description:"最近N年"`
 	Period               int     `description:"数据的周期,根据频率设置"`
 	Seasonal             int     `description:"季节性成分窗口大小,一般为period+1,可以设置为大于period的正奇数"`
 	Trend                int     `description:"趋势成分窗口大小,一般为period+1,可以设置为大于period的正奇数"`

+ 1 - 1
models/data_manage/stl/response/stl.go

@@ -49,7 +49,7 @@ type StlConfigResp struct {
 	DataRangeType        int     `description:"数据时间类型:1-全部时间,2-最近N年,3-区间设置,4-区间设置(至今)"`
 	StartDate            string  `description:"开始日期"`
 	EndDate              string  `description:"结束日期"`
-	LastNYear            int     `description:"最近N年"`
+	LastNYear            string  `description:"最近N年"`
 	Period               int     `description:"数据的周期,根据频率设置"`
 	Seasonal             int     `description:"季节性成分窗口大小,一般为period+1,可以设置为大于period的正奇数"`
 	Trend                int     `description:"趋势成分窗口大小,一般为period+1,可以设置为大于period的正奇数"`

+ 29 - 6
services/data/stl/stl.go

@@ -66,7 +66,13 @@ func GenerateStlEdbData(req *request.StlConfigReq, adminId int) (resp *response.
 	case LAST_N_YEARS:
 		condition += " AND data_time >=?"
 		year := time.Now().Year()
-		lastDate := time.Date(year-confReq.LastNYear, 1, 1, 0, 0, 0, 0, time.Local)
+		lastNyear, er := strconv.Atoi(req.LastNYear)
+		if er != nil {
+			msg = "最近N年输入不合法"
+			err = er
+			return
+		}
+		lastDate := time.Date(year-lastNyear, 1, 1, 0, 0, 0, 0, time.Local)
 		pars = append(pars, lastDate)
 	case RANGE_DATE:
 		condition = " AND data_time >=? AND data_time <=?"
@@ -211,10 +217,20 @@ func GenerateStlEdbData(req *request.StlConfigReq, adminId int) (resp *response.
 	bTrend, _ := json.Marshal(trendChart.DataList)
 	bSeasonal, _ := json.Marshal(seasonalChart.DataList)
 	bResidual, _ := json.Marshal(residualChart.DataList)
-	utils.Rc.Put(EDB_DATA_CALCULATE_STL_TREND_CACHE+strconv.Itoa(config.CalculateStlConfigId), bTrend, time.Hour*2)
-	utils.Rc.Put(EDB_DATA_CALCULATE_STL_SEASONAL_CACHE+strconv.Itoa(config.CalculateStlConfigId), bSeasonal, time.Hour*2)
+	err = utils.Rc.Put(EDB_DATA_CALCULATE_STL_TREND_CACHE+strconv.Itoa(config.CalculateStlConfigId), bTrend, time.Hour*2)
+	if err != nil {
+		msg = "计算失败,请重新计算"
+		return
+	}
+	err = utils.Rc.Put(EDB_DATA_CALCULATE_STL_SEASONAL_CACHE+strconv.Itoa(config.CalculateStlConfigId), bSeasonal, time.Hour*2)
+	if err != nil {
+		msg = "计算失败,请重新计算"
+		return
+	}
 	utils.Rc.Put(EDB_DATA_CALCULATE_STL_RESIDUAL_CACHE+strconv.Itoa(config.CalculateStlConfigId), bResidual, time.Hour*2)
-
+	if err != nil {
+		msg = "计算失败,请重新计算"
+	}
 	return
 }
 
@@ -455,7 +471,8 @@ print(output)
 	}
 
 	pythonCode = fmt.Sprintf(pythonCode, path, period, seasonal, trend, fraction, seasonalDeg, trendDeg, lowPassDeg, robustStr, toPath)
-	cmd := exec.Command(`python3`, "-c", pythonCode)
+	// cmd := exec.Command(`python3`, "-c", pythonCode)
+	cmd := exec.Command(`D:\conda\envs\py311\python`, "-c", pythonCode)
 	output, err := cmd.CombinedOutput()
 	if err != nil {
 		return
@@ -484,7 +501,13 @@ func SaveStlConfig(req *request.StlConfigReq, adminId int) (configId int64, msg
 	case LAST_N_YEARS:
 		condition += " AND data_time >=?"
 		year := time.Now().Year()
-		lastDate := time.Date(year-req.LastNYear, 1, 1, 0, 0, 0, 0, time.Local)
+		lastNyear, er := strconv.Atoi(req.LastNYear)
+		if er != nil {
+			msg = "最近N年输入不合法"
+			err = er
+			return
+		}
+		lastDate := time.Date(year-lastNyear, 1, 1, 0, 0, 0, 0, time.Local)
 		pars = append(pars, lastDate)
 	case RANGE_DATE:
 		condition = " AND data_time >=? AND data_time <=?"