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 // }) //}