|
@@ -21,7 +21,12 @@ func UserActionList(c *gin.Context) {
|
|
|
|
|
|
//查询出所有的事件
|
|
|
var actionList []model.GameAction
|
|
|
- err := global.App.DB.Table("game_action").
|
|
|
+
|
|
|
+ query := global.App.DB.Table("game_action")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query = query.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err := query.
|
|
|
Where("gid", form.Gid).
|
|
|
Select("id", "actionId", "actionName").
|
|
|
Order("id desc").Scan(&actionList).Error
|
|
@@ -31,7 +36,11 @@ func UserActionList(c *gin.Context) {
|
|
|
}
|
|
|
//查询出时间段内的活跃用户,登录次数
|
|
|
var userLogin []model.UserLogin
|
|
|
- err = global.App.DB.Table("user_login").
|
|
|
+ query1 := global.App.DB.Table("user_login")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query1 = query1.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err = query1.
|
|
|
Where("gid", form.Gid).
|
|
|
Where("loginTime", ">=", form.StartTime).
|
|
|
Where("loginTime", "<=", form.EndTime).
|
|
@@ -45,7 +54,11 @@ func UserActionList(c *gin.Context) {
|
|
|
|
|
|
//查询出时间段内事件触发数量,以及触发人的ID
|
|
|
var userAction []model.UserAction
|
|
|
- err = global.App.DB.Table("user_action").
|
|
|
+ query2 := global.App.DB.Table("user_action")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query2 = query2.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err = query2.
|
|
|
Where("gid", form.Gid).
|
|
|
Where("createdAt", ">=", form.StartTime).
|
|
|
Where("createdAt", "<=", form.EndTime).
|
|
@@ -58,6 +71,7 @@ func UserActionList(c *gin.Context) {
|
|
|
//计算事件的触发总数和触发用户数
|
|
|
actionSumMap := make(map[string]int)
|
|
|
actionUserSumMap := make(map[string][]int)
|
|
|
+ fmt.Println(userAction)
|
|
|
for _, action := range userAction {
|
|
|
actionSumMap[action.ActionId]++
|
|
|
actionUserSumMap[action.ActionId] = append(actionUserSumMap[action.ActionId], action.UserId)
|
|
@@ -199,10 +213,11 @@ func UserActionDetail(c *gin.Context) {
|
|
|
|
|
|
func UserActionDetailDistribution(c *gin.Context) {
|
|
|
form := request.Check(c, &struct {
|
|
|
- Id int `form:"id" binding:"required"`
|
|
|
- StartTime string `form:"startTime" binding:"required"`
|
|
|
- EndTime string `form:"endTime" binding:"required"`
|
|
|
- Type int `form:"type" binding:"required"`
|
|
|
+ Id int `form:"id" binding:"required"`
|
|
|
+ Pf []string `form:"pf" binding:""`
|
|
|
+ StartTime string `form:"startTime" binding:"required"`
|
|
|
+ EndTime string `form:"endTime" binding:"required"`
|
|
|
+ Type int `form:"type" binding:"required"`
|
|
|
}{})
|
|
|
|
|
|
var action model.GameAction
|
|
@@ -219,7 +234,11 @@ func UserActionDetailDistribution(c *gin.Context) {
|
|
|
UserId int `json:"userId" gorm:"not null;column:userId;"`
|
|
|
CreatedAt string `json:"createdAt" gorm:"not null;column:createdAt;"`
|
|
|
}
|
|
|
- err = global.App.DB.Table("user_action").
|
|
|
+ query := global.App.DB.Table("user_action")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query = query.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err = query.
|
|
|
Where("gid", action.Gid).
|
|
|
Where("actionId", action.ActionId).
|
|
|
Select("userId", "DATE_FORMAT(createdAt, '%Y-%m-%d') as createdAt").
|
|
@@ -238,9 +257,6 @@ func UserActionDetailDistribution(c *gin.Context) {
|
|
|
for _, v := range days {
|
|
|
res[v] = activeCount[v]
|
|
|
}
|
|
|
- //fmt.Print(len(userAction) / len(days))
|
|
|
-
|
|
|
- //response.Success(c, gin.H{"data": res, "avg": fmt.Sprintf("%.2f", float64(len(userAction))/float64(len(days)))})
|
|
|
|
|
|
response.Success(c, gin.H{
|
|
|
"data": map[string]interface{}{
|
|
@@ -254,7 +270,11 @@ func UserActionDetailDistribution(c *gin.Context) {
|
|
|
UserId int `json:"userId" gorm:"not null;column:userId;"`
|
|
|
CreatedAt string `json:"createdAt" gorm:"not null;column:createdAt;"`
|
|
|
}
|
|
|
- err = global.App.DB.Table("user_action").
|
|
|
+ query := global.App.DB.Table("user_action")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query = query.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err = query.
|
|
|
Where("gid", action.Gid).
|
|
|
Where("actionId", action.ActionId).
|
|
|
Select("userId", "DATE_FORMAT(createdAt, '%Y-%m-%d') as createdAt").
|
|
@@ -284,31 +304,85 @@ func UserActionDetailDistribution(c *gin.Context) {
|
|
|
},
|
|
|
})
|
|
|
} else if form.Type == 3 {
|
|
|
- var userAction []struct {
|
|
|
- UserId int `json:"userId" gorm:"not null;column:userId;"`
|
|
|
- CreatedAt string `json:"createdAt" gorm:"not null;column:createdAt;"`
|
|
|
+ //活跃设备发生率
|
|
|
+ var userAction []string
|
|
|
+ query := global.App.DB.Table("user_action")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query = query.WhereIn("gid", form.Pf)
|
|
|
}
|
|
|
- err = global.App.DB.Table("user_action").
|
|
|
+ err = query.
|
|
|
Where("gid", action.Gid).
|
|
|
Where("actionId", action.ActionId).
|
|
|
- Select("userId", "DATE_FORMAT(createdAt, '%Y-%m-%d') as createdAt").
|
|
|
- Scan(&userAction).Error
|
|
|
+ Pluck("DATE_FORMAT(createdAt, '%Y-%m-%d') as createdAt", &userAction).Error
|
|
|
if err != nil {
|
|
|
response.Fail(c, 1002, err.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- activeCount := make(map[string]map[int]bool)
|
|
|
+ actionCount := make(map[string]int)
|
|
|
for _, v := range userAction {
|
|
|
- if activeCount[v.CreatedAt] == nil {
|
|
|
- activeCount[v.CreatedAt] = make(map[int]bool)
|
|
|
- }
|
|
|
- activeCount[v.CreatedAt][v.UserId] = true
|
|
|
+ actionCount[v]++
|
|
|
}
|
|
|
- //查询活跃用户
|
|
|
|
|
|
- } else if form.Type == 4 {
|
|
|
+ //var userOnline model.UserOnline
|
|
|
+ //query = global.App.DB.Table("user_online")
|
|
|
+ //if len(form.Pf) > 0 {
|
|
|
+ // query = query.WhereIn("gid", form.Pf)
|
|
|
+ //}
|
|
|
+ //err = query.
|
|
|
+ // Where("gid", action.Gid).
|
|
|
+ // Error
|
|
|
+ //if err != nil {
|
|
|
+ // response.Fail(c, 1002, err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //userCount := make(map[string]map[int]bool)
|
|
|
+ //for _, v := range userOnline {
|
|
|
+ //
|
|
|
+ //}
|
|
|
|
|
|
+ } else if form.Type == 4 {
|
|
|
+ //每次启动发生率
|
|
|
+ var userLogin []string
|
|
|
+ query := global.App.DB.Table("user_login")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query = query.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err = query.
|
|
|
+ Where("gid", action.Gid).
|
|
|
+ Pluck("DATE_FORMAT(createdAt, '%Y-%m-%d') as createdAt", &userLogin).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ loginCount := make(map[string]int)
|
|
|
+ for _, v := range userLogin {
|
|
|
+ loginCount[v]++
|
|
|
+ }
|
|
|
+ var userAction []string
|
|
|
+ query = global.App.DB.Table("user_action")
|
|
|
+ if len(form.Pf) > 0 {
|
|
|
+ query = query.WhereIn("gid", form.Pf)
|
|
|
+ }
|
|
|
+ err = query.
|
|
|
+ Where("gid", action.Gid).
|
|
|
+ Where("actionId", action.ActionId).
|
|
|
+ Pluck("DATE_FORMAT(createdAt, '%Y-%m-%d') as createdAt", &userAction).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1002, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ actionCount := make(map[string]int)
|
|
|
+ for _, v := range userAction {
|
|
|
+ actionCount[v]++
|
|
|
+ }
|
|
|
+ days := utils.GetTimeDayDateFormat(form.StartTime, form.EndTime)
|
|
|
+ for _, v := range days {
|
|
|
+ if loginCount[v] > 0 {
|
|
|
+ res[v] = float64(actionCount[v]) / float64(loginCount[v])
|
|
|
+ } else {
|
|
|
+ res[v] = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
response.Fail(c, 1003, errors.New("type 错误"))
|
|
|
return
|