123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package service
- //func SetOptionSummary() {
- //
- // now := time.Now()
- // //查出当天的所有用户登录数据
- //
- // fmt.Println(time.Since(now))
- // userLoginCount := len(userLogin)
- // //查询出所有的事件选项
- // var actionOption []struct {
- // model.UserActionOption
- // UserId int `json:"userId" gorm:"not null;column:userId;"`
- // }
- //
- // err = global.App.DB.Table("user_action_option").
- // LeftJoin("user_action", "user_action.id = user_action_option.UserActionId").
- // Where("user_action.actionId", form.ActionId).
- // Where("user_action.gid", form.Gid).
- // Where("user_action.createdAt", ">=", form.StartTime).
- // Where("user_action.createdAt", "<=", form.EndTime).
- // Select("user_action_option.*", "user_action.userId").
- // Scan(&actionOption).Error
- // if err != nil {
- // response.Fail(c, 1004, err.Error())
- // return
- // }
- // fmt.Println(time.Since(now))
- // //循环得出选项
- // optionList := make(map[string]int)
- // for _, v := range actionOption {
- // optionList[v.OptionId+"|"+v.Value]++
- // }
- //
- // //根据人数进行比对
- // //计算事件的触发总数和触发用户数
- // actionSumMap := make(map[string]int)
- // actionUserSumMap := make(map[string]map[int]bool)
- //
- // for _, action := range actionOption {
- // if actionUserSumMap[action.OptionId+"|"+action.Value] == nil {
- // actionUserSumMap[action.OptionId+"|"+action.Value] = make(map[int]bool)
- // }
- // actionSumMap[action.OptionId+"|"+action.Value]++
- // actionUserSumMap[action.OptionId+"|"+action.Value][action.UserId] = true
- // }
- //
- // //根据事件触发和活跃用户数量进行比对得出其他数据
- // activeUser := make(map[int]bool)
- // var activeUserSlice []int
- // for _, users := range userLogin {
- // activeUser[users.UserId] = true
- // }
- // for k := range activeUser {
- // activeUserSlice = append(activeUserSlice, k)
- // }
- //
- // type responses struct {
- // Id int `json:"id"`
- // ActionId int `json:"actionId"`
- // ActionName string `json:"actionName"`
- // ActionCount int `json:"actionCount"`
- // ActionUserCount int `json:"actionUserCount"`
- // ActiveUserRate float64 `json:"activeUserRate"`
- // LoginActiveRate float64 `json:"loginActiveRate"`
- // }
- //
- // var res []responses
- //
- // var optionName []model.GameActionOption
- // optionIdToName := make(map[string]string)
- // global.App.DB.Table("game_action_option").
- // LeftJoin("game_action", "game_action.id = game_action_option.actionId").
- // Where("gid", form.Gid).Scan(&optionName)
- // for _, v := range optionName {
- // optionIdToName[v.OptionId] = v.OptionName
- // }
- // fmt.Println(time.Since(now))
- // for k, v := range optionList {
- // var ActiveUserRate float64
- // var LoginActiveRate float64
- // if userLoginCount > 0 {
- // ActiveUserRate = DivideWithPrecision(actionSumMap[k], userLoginCount)
- // LoginActiveRate = DivideWithPrecision(len(actionUserSumMap[k]), userLoginCount)
- // }
- //
- // optionId := strings.Split(k, "|")[0]
- // value := strings.Split(k, "|")[1]
- // valueInt, _ := strconv.Atoi(value)
- //
- // res = append(res, responses{
- // ActionId: valueInt,
- // ActionName: optionIdToName[optionId] + ":" + value,
- // ActionCount: v,
- // ActionUserCount: len(actionUserSumMap[k]),
- // ActiveUserRate: ActiveUserRate,
- // LoginActiveRate: LoginActiveRate,
- // })
- // }
- //
- // sort.Slice(res, func(i, j int) bool {
- // return res[i].ActionId < res[j].ActionId // 正序规则:i的Age小于j时返回true
- // })
- //}
|