package models import ( mhayaTime "github.com/mhaya/extend/time" "github.com/mhaya/game/game_cluster/internal/data" ) type PlayerLevelStat struct { Platform string `bson:"platform" json:"platform"` // platform: 用户所在的平台,例如“Android”或“IOS” Channel string `bson:"channel" json:"channel"` // channel: 用户来源渠道 ServerLevel map[string]int `json:"serverLevel" bson:"serverLevel"` UpdateTime int64 `bson:"updateTime" json:"updateTime"` } type PlayerServerLoadStat struct { Name string `bson:"name" json:"name"` TotalUser int64 `bson:"totalUser" json:"totalUser"` Load map[string]string `bson:"load" json:"load"` UpdateTime int64 `bson:"updateTime" json:"updateTime"` } type PlayerCountryStat struct { Daily int64 `bson:"daily" json:"daily"` //日期 Platform string `bson:"platform" json:"platform"` // platform: 用户所在的平台,例如“Android”或“IOS” Channel string `bson:"channel" json:"channel"` // channel: 用户来源渠道 PlayerRegisterCountry map[string]int `bson:"playerRegisterCountry" json:"playerRegisterCountry"` // playerRegisterCountry 玩家注册国家 UpdateTime int64 `bson:"updateTime" json:"updateTime"` } type Preserve struct { ID int64 `json:"id"` Num int `json:"num"` Ratio float64 `json:"ratio"` } var preserveConfig = []int64{2, 3, 7, 15, 30} // GetPlayerPreserve 获取用户留存 func GetPlayerPreserve(startTime, EndTime int64) { if startTime > mhayaTime.Now().Unix() || EndTime > mhayaTime.Now().Unix() { return } sTime := mhayaTime.CreateFromTimestamp(startTime).DailyTOTimeStamp() if EndTime > mhayaTime.Now().Unix() { EndTime = mhayaTime.Now().Unix() } eTime := mhayaTime.CreateFromTimestamp(EndTime).DailyTOTimeStamp() mhayaTime.CreateFromTimestamp(sTime).DiffInDays(mhayaTime.CreateFromTimestamp(eTime)) } func PlayerPreserve(startTime, day int64) { var preserve []*Preserve _, curNum := GetNewPlayerMap(startTime, DailyRecordNewRegistered) if curNum < 1 { return } preserve = append(preserve, &Preserve{ID: 1, Num: curNum, Ratio: 100}) for _, v := range preserveConfig { if day < v { preserve = append(preserve, &Preserve{ID: v, Num: 0, Ratio: 0}) } else { // nextTime := mhayaTime.CreateFromTimestamp(startTime).AddDays(int(v) - 1) //next, nextNum := GetNewPlayerMap(startTime, DailyRecordOldLogin) preserve = append(preserve, &Preserve{ID: v, Num: 1, Ratio: 0}) } } } func GetNewPlayerMap(startTime int64, op int) (map[string]struct{}, int) { var user = make(map[string]struct{}) platformConfig := data.PlatformConfig.GatMap() channelConfig := data.ChannelConfig.GatMap() for _, v := range platformConfig { for _, v2 := range channelConfig { ret, err := GetAppointDailyRecordUserHash(v.Name, v2.Name, startTime, op) if err != nil { continue } for k, _ := range ret { if _, ok := user[k]; !ok { user[k] = struct{}{} } } } } return user, len(user) }