statistic_analysis.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/data_manage"
  5. "eta/eta_hub/utils"
  6. "fmt"
  7. )
  8. // StatisticAnalysisController 统计分析
  9. type StatisticAnalysisController struct {
  10. BaseAuthController
  11. }
  12. // ClassifyList
  13. // @Title 统计分析-分类列表
  14. // @Description 统计分析-分类列表
  15. // @Param SourceType query int false "分类类型: 1-相关性分析; 2-拟合方程曲线; 3-统计特征"
  16. // @Success 200 {object} data_manage.ChartClassifyItem
  17. // @router /classify/list [get]
  18. func (this *StatisticAnalysisController) ClassifyList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sourceType, _ := this.GetInt("SourceType", 0)
  25. if sourceType <= 0 {
  26. sourceType = 1
  27. }
  28. sourceMap := map[int]int{
  29. 1: utils.CHART_SOURCE_CORRELATION,
  30. 2: utils.CHART_SOURCE_LINE_EQUATION,
  31. 3: utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION,
  32. }
  33. source := sourceMap[sourceType]
  34. if source <= 0 {
  35. br.Msg = "分类来源有误"
  36. return
  37. }
  38. cond := ` AND source = ?`
  39. pars := make([]interface{}, 0)
  40. pars = append(pars, source)
  41. // 获取所有分类
  42. classifyOb := new(data_manage.ChartClassify)
  43. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC")
  44. if e != nil {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "ChartClassifyList GetItemsByCondition err: " + e.Error()
  47. return
  48. }
  49. resp := make([]*data_manage.ChartClassifyItem, 0)
  50. for _, v := range classifies {
  51. resp = append(resp, data_manage.FormatChartClassify2Item(v))
  52. }
  53. br.Data = resp
  54. br.Ret = 200
  55. br.Msg = "获取成功"
  56. }
  57. // ChartList
  58. // @Title 统计分析-图表列表
  59. // @Description 统计分析-图表列表
  60. // @Param ClassifyId query int true "图表分类ID"
  61. // @Param CorrelationType query int false "相关性图表类型: 1-相关性图表; 2-滚动相关性"
  62. // @Success 200 {object} data_manage.ChartInfoItem
  63. // @router /chart/list [get]
  64. func (this *StatisticAnalysisController) ChartList() {
  65. br := new(models.BaseResponse).Init()
  66. defer func() {
  67. this.Data["json"] = br
  68. this.ServeJSON()
  69. }()
  70. classifyId, _ := this.GetInt("ClassifyId")
  71. if classifyId <= 0 {
  72. br.Msg = "参数有误"
  73. return
  74. }
  75. cond := ` AND chart_classify_id = ?`
  76. pars := make([]interface{}, 0)
  77. pars = append(pars, classifyId)
  78. // 相关性图表类型
  79. correlationType, _ := this.GetInt("CorrelationType")
  80. if correlationType > 0 {
  81. correlationMap := map[int]int{
  82. 1: utils.CHART_SOURCE_CORRELATION,
  83. 2: utils.CHART_SOURCE_ROLLING_CORRELATION,
  84. }
  85. source := correlationMap[correlationType]
  86. if source <= 0 {
  87. br.Msg = "相关性图表类型有误"
  88. return
  89. }
  90. cond += ` AND source = ?`
  91. pars = append(pars, source)
  92. } else {
  93. // 默认统计分析的图表
  94. sourceArr := []int{
  95. utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION, utils.CHART_SOURCE_LINE_EQUATION,
  96. utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY,
  97. }
  98. cond += fmt.Sprintf(` AND source IN (%s)`, utils.GetOrmInReplace(len(sourceArr)))
  99. pars = append(pars, sourceArr)
  100. }
  101. chartOb := new(data_manage.ChartInfo)
  102. charts, e := chartOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC")
  103. if e != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "ClassifyChart GetItemsByCondition err: " + e.Error()
  106. return
  107. }
  108. resp := make([]*data_manage.ChartInfoItem, 0)
  109. for _, v := range charts {
  110. resp = append(resp, data_manage.FormatChartInfo2Item(v))
  111. }
  112. br.Data = resp
  113. br.Ret = 200
  114. br.Msg = "获取成功"
  115. }