印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

157 lines
4.2 KiB

package statistics
import (
"server/modules/backend/app"
"server/modules/backend/models"
utils "server/modules/backend/util"
"server/modules/backend/values"
"strconv"
"github.com/gin-gonic/gin"
"github.com/olivere/elastic/v7"
)
func RoomGameAnalysis(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.RoomGameAnalysisReq)
if !a.S(req) {
return
}
resp := values.RoomGameAnalysisResp{}
su, eu := utils.GetQueryUnix(req.Start, req.End)
var oneDay int64 = 24 * 60 * 60
for i := su; i < eu; i += oneDay {
s := i
e := i + oneDay
resp.List = append(resp.List, getRoomGameAnalysisInfo(&s, &e, req.IsNew))
}
a.Data = resp
}
func getRoomGameAnalysisInfo(s, e *int64, isNew *bool) values.RoomGameAnalysisInfo {
var roomGameAnalysisInfo values.RoomGameAnalysisInfo
// 时间
roomGameAnalysisInfo.Date = *s
// 新增用户
roomGameAnalysisInfo.NewPlayerCount = models.GetNewPlayerCountBySql(nil, *s, *e)
// 老用户数
roomGameAnalysisInfo.OldPlayerCount = models.GetOldPlayerCountBySql(nil, *s, *e)
// 玩游戏数量
// roomGameAnalysisInfo.PlayerCount = models.GetPlayGameUserCount(s, e, nil, nil, nil, isNew)
// 房间游戏数据
gameCountDetail := make(map[string]int64)
// for i := 0; i < len(common.RoomGameIDs); i++ {
// gameCountDetail[strconv.Itoa(common.RoomGameIDs[i])] = models.GetGameCount(s, e, &common.RoomGameIDs[i], nil, nil, isNew)
// roomGameAnalysisInfo.GameCount += gameCountDetail[strconv.Itoa(common.RoomGameIDs[i])]
// }
// 百人游戏数据
// for i := 0; i < len(common.MillionGameIDs); i++ {
// millionGameID := common.MillionGameIDs[i].(int)
// gameCountDetail[strconv.Itoa(millionGameID)] = models.GetGameCount(s, e, &millionGameID, nil, nil, isNew)
// roomGameAnalysisInfo.GameCount += gameCountDetail[strconv.Itoa(millionGameID)]
// }
// 游戏数据
roomGameAnalysisInfo.GameCountDetail = gameCountDetail
// 平均游戏局数
var PlayerCount int64
if isNew == nil {
PlayerCount = roomGameAnalysisInfo.NewPlayerCount + roomGameAnalysisInfo.OldPlayerCount
} else {
if *isNew == true {
PlayerCount = roomGameAnalysisInfo.NewPlayerCount
} else {
PlayerCount = roomGameAnalysisInfo.OldPlayerCount
}
}
roomGameAnalysisInfo.AverageGameCount = utils.GetPoint(roomGameAnalysisInfo.GameCount, PlayerCount)
playerGameDetail := make(map[string]int64)
for i := 0; i < 12; i++ {
playerGameDetail[strconv.Itoa(i)] = 0
}
// 0局
if isNew != nil {
if *isNew {
playerGameDetail[strconv.Itoa(0)] = roomGameAnalysisInfo.NewPlayerCount - roomGameAnalysisInfo.PlayerCount
} else {
playerGameDetail[strconv.Itoa(0)] = roomGameAnalysisInfo.OldPlayerCount - roomGameAnalysisInfo.PlayerCount
}
} else {
playerGameDetail[strconv.Itoa(0)] = roomGameAnalysisInfo.OldPlayerCount + roomGameAnalysisInfo.NewPlayerCount - roomGameAnalysisInfo.PlayerCount
}
q := elastic.NewBoolQuery()
if isNew != nil {
q.Must(elastic.NewMatchQuery("IsNew", *isNew))
}
q.Filter(elastic.NewRangeQuery("Time").Gte(*s))
q.Filter(elastic.NewRangeQuery("Time").Lt(*e))
ret := new(ESBucket)
// err := db.ES().GroupSumBy(common.ESIndexBackPlayerStats, "UID", q, ret, "", false, int(models.GetPlayGameUserCount(s, e, nil, nil, nil, nil)), "PlayCount")
// if err != nil {
// log.Error(err.Error())
// }
for _, v := range ret.Buckets {
if v.PlayCount.Value <= 10 {
switch int(v.PlayCount.Value) {
case 1:
playerGameDetail[strconv.Itoa(1)]++
case 2:
playerGameDetail[strconv.Itoa(2)]++
case 3:
playerGameDetail[strconv.Itoa(3)]++
case 4:
playerGameDetail[strconv.Itoa(4)]++
case 5:
playerGameDetail[strconv.Itoa(5)]++
case 6:
playerGameDetail[strconv.Itoa(6)]++
case 7:
playerGameDetail[strconv.Itoa(7)]++
case 8:
playerGameDetail[strconv.Itoa(8)]++
case 9:
playerGameDetail[strconv.Itoa(9)]++
case 10:
playerGameDetail[strconv.Itoa(10)]++
}
} else {
playerGameDetail[strconv.Itoa(11)]++
}
}
roomGameAnalysisInfo.PlayerGameDetail = playerGameDetail
return roomGameAnalysisInfo
}
type ESBucket struct {
Buckets []struct {
Key interface{}
Doc_count int
PlayCount struct {
Value float64
}
Top struct {
Hits struct {
Hits []struct {
// Source common.ESPlayerStats `json:"_source"`
}
}
}
}
}