option.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package service
  2. //func SetOptionSummary() {
  3. //
  4. // now := time.Now()
  5. // //查出当天的所有用户登录数据
  6. //
  7. // fmt.Println(time.Since(now))
  8. // userLoginCount := len(userLogin)
  9. // //查询出所有的事件选项
  10. // var actionOption []struct {
  11. // model.UserActionOption
  12. // UserId int `json:"userId" gorm:"not null;column:userId;"`
  13. // }
  14. //
  15. // err = global.App.DB.Table("user_action_option").
  16. // LeftJoin("user_action", "user_action.id = user_action_option.UserActionId").
  17. // Where("user_action.actionId", form.ActionId).
  18. // Where("user_action.gid", form.Gid).
  19. // Where("user_action.createdAt", ">=", form.StartTime).
  20. // Where("user_action.createdAt", "<=", form.EndTime).
  21. // Select("user_action_option.*", "user_action.userId").
  22. // Scan(&actionOption).Error
  23. // if err != nil {
  24. // response.Fail(c, 1004, err.Error())
  25. // return
  26. // }
  27. // fmt.Println(time.Since(now))
  28. // //循环得出选项
  29. // optionList := make(map[string]int)
  30. // for _, v := range actionOption {
  31. // optionList[v.OptionId+"|"+v.Value]++
  32. // }
  33. //
  34. // //根据人数进行比对
  35. // //计算事件的触发总数和触发用户数
  36. // actionSumMap := make(map[string]int)
  37. // actionUserSumMap := make(map[string]map[int]bool)
  38. //
  39. // for _, action := range actionOption {
  40. // if actionUserSumMap[action.OptionId+"|"+action.Value] == nil {
  41. // actionUserSumMap[action.OptionId+"|"+action.Value] = make(map[int]bool)
  42. // }
  43. // actionSumMap[action.OptionId+"|"+action.Value]++
  44. // actionUserSumMap[action.OptionId+"|"+action.Value][action.UserId] = true
  45. // }
  46. //
  47. // //根据事件触发和活跃用户数量进行比对得出其他数据
  48. // activeUser := make(map[int]bool)
  49. // var activeUserSlice []int
  50. // for _, users := range userLogin {
  51. // activeUser[users.UserId] = true
  52. // }
  53. // for k := range activeUser {
  54. // activeUserSlice = append(activeUserSlice, k)
  55. // }
  56. //
  57. // type responses struct {
  58. // Id int `json:"id"`
  59. // ActionId int `json:"actionId"`
  60. // ActionName string `json:"actionName"`
  61. // ActionCount int `json:"actionCount"`
  62. // ActionUserCount int `json:"actionUserCount"`
  63. // ActiveUserRate float64 `json:"activeUserRate"`
  64. // LoginActiveRate float64 `json:"loginActiveRate"`
  65. // }
  66. //
  67. // var res []responses
  68. //
  69. // var optionName []model.GameActionOption
  70. // optionIdToName := make(map[string]string)
  71. // global.App.DB.Table("game_action_option").
  72. // LeftJoin("game_action", "game_action.id = game_action_option.actionId").
  73. // Where("gid", form.Gid).Scan(&optionName)
  74. // for _, v := range optionName {
  75. // optionIdToName[v.OptionId] = v.OptionName
  76. // }
  77. // fmt.Println(time.Since(now))
  78. // for k, v := range optionList {
  79. // var ActiveUserRate float64
  80. // var LoginActiveRate float64
  81. // if userLoginCount > 0 {
  82. // ActiveUserRate = DivideWithPrecision(actionSumMap[k], userLoginCount)
  83. // LoginActiveRate = DivideWithPrecision(len(actionUserSumMap[k]), userLoginCount)
  84. // }
  85. //
  86. // optionId := strings.Split(k, "|")[0]
  87. // value := strings.Split(k, "|")[1]
  88. // valueInt, _ := strconv.Atoi(value)
  89. //
  90. // res = append(res, responses{
  91. // ActionId: valueInt,
  92. // ActionName: optionIdToName[optionId] + ":" + value,
  93. // ActionCount: v,
  94. // ActionUserCount: len(actionUserSumMap[k]),
  95. // ActiveUserRate: ActiveUserRate,
  96. // LoginActiveRate: LoginActiveRate,
  97. // })
  98. // }
  99. //
  100. // sort.Slice(res, func(i, j int) bool {
  101. // return res[i].ActionId < res[j].ActionId // 正序规则:i的Age小于j时返回true
  102. // })
  103. //}