package controllers import ( "eta/eta_hub/models" "eta/eta_hub/models/data_manage" "eta/eta_hub/utils" "fmt" ) // StatisticAnalysisController 统计分析 type StatisticAnalysisController struct { BaseAuthController } // ClassifyList // @Title 统计分析-分类列表 // @Description 统计分析-分类列表 // @Param SourceType query int false "分类类型: 1-相关性分析; 2-拟合方程曲线; 3-统计特征" // @Success 200 {object} data_manage.ChartClassifyItem // @router /classify/list [get] func (this *StatisticAnalysisController) ClassifyList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sourceType, _ := this.GetInt("SourceType", 0) if sourceType <= 0 { sourceType = 1 } sourceMap := map[int]int{ 1: utils.CHART_SOURCE_CORRELATION, 2: utils.CHART_SOURCE_LINE_EQUATION, 3: utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, } source := sourceMap[sourceType] if source <= 0 { br.Msg = "分类来源有误" return } cond := ` AND source = ?` pars := make([]interface{}, 0) pars = append(pars, source) // 获取所有分类 classifyOb := new(data_manage.ChartClassify) classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC") if e != nil { br.Msg = "获取失败" br.ErrMsg = "ChartClassifyList GetItemsByCondition err: " + e.Error() return } resp := make([]*data_manage.ChartClassifyItem, 0) for _, v := range classifies { resp = append(resp, data_manage.FormatChartClassify2Item(v)) } br.Data = resp br.Ret = 200 br.Msg = "获取成功" } // ChartList // @Title 统计分析-图表列表 // @Description 统计分析-图表列表 // @Param ClassifyId query int true "图表分类ID" // @Param CorrelationType query int false "相关性图表类型: 1-相关性图表; 2-滚动相关性" // @Success 200 {object} data_manage.ChartInfoItem // @router /chart/list [get] func (this *StatisticAnalysisController) ChartList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyId, _ := this.GetInt("ClassifyId") if classifyId <= 0 { br.Msg = "参数有误" return } cond := ` AND chart_classify_id = ?` pars := make([]interface{}, 0) pars = append(pars, classifyId) // 相关性图表类型 correlationType, _ := this.GetInt("CorrelationType") if correlationType > 0 { correlationMap := map[int]int{ 1: utils.CHART_SOURCE_CORRELATION, 2: utils.CHART_SOURCE_ROLLING_CORRELATION, } source := correlationMap[correlationType] if source <= 0 { br.Msg = "相关性图表类型有误" return } cond += ` AND source = ?` pars = append(pars, source) } else { // 默认统计分析的图表 sourceArr := []int{ utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION, utils.CHART_SOURCE_LINE_EQUATION, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY, } cond += fmt.Sprintf(` AND source IN (%s)`, utils.GetOrmInReplace(len(sourceArr))) pars = append(pars, sourceArr) } chartOb := new(data_manage.ChartInfo) charts, e := chartOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC") if e != nil { br.Msg = "获取失败" br.ErrMsg = "ClassifyChart GetItemsByCondition err: " + e.Error() return } resp := make([]*data_manage.ChartInfoItem, 0) for _, v := range charts { resp = append(resp, data_manage.FormatChartInfo2Item(v)) } br.Data = resp br.Ret = 200 br.Msg = "获取成功" }