PlayerStat.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package models
  2. import (
  3. mhayaTime "github.com/mhaya/extend/time"
  4. "github.com/mhaya/game/game_cluster/internal/data"
  5. )
  6. type PlayerLevelStat struct {
  7. Platform string `bson:"platform" json:"platform"` // platform: 用户所在的平台,例如“Android”或“IOS”
  8. Channel string `bson:"channel" json:"channel"` // channel: 用户来源渠道
  9. ServerLevel map[string]int `json:"serverLevel" bson:"serverLevel"`
  10. UpdateTime int64 `bson:"updateTime" json:"updateTime"`
  11. }
  12. type PlayerServerLoadStat struct {
  13. Name string `bson:"name" json:"name"`
  14. TotalUser int64 `bson:"totalUser" json:"totalUser"`
  15. Load map[string]string `bson:"load" json:"load"`
  16. UpdateTime int64 `bson:"updateTime" json:"updateTime"`
  17. }
  18. type PlayerCountryStat struct {
  19. Daily int64 `bson:"daily" json:"daily"` //日期
  20. Platform string `bson:"platform" json:"platform"` // platform: 用户所在的平台,例如“Android”或“IOS”
  21. Channel string `bson:"channel" json:"channel"` // channel: 用户来源渠道
  22. PlayerRegisterCountry map[string]int `bson:"playerRegisterCountry" json:"playerRegisterCountry"` // playerRegisterCountry 玩家注册国家
  23. UpdateTime int64 `bson:"updateTime" json:"updateTime"`
  24. }
  25. type Preserve struct {
  26. ID int64 `json:"id"`
  27. Num int `json:"num"`
  28. Ratio float64 `json:"ratio"`
  29. }
  30. var preserveConfig = []int64{2, 3, 7, 15, 30}
  31. // GetPlayerPreserve 获取用户留存
  32. func GetPlayerPreserve(startTime, EndTime int64) {
  33. if startTime > mhayaTime.Now().Unix() || EndTime > mhayaTime.Now().Unix() {
  34. return
  35. }
  36. sTime := mhayaTime.CreateFromTimestamp(startTime).DailyTOTimeStamp()
  37. if EndTime > mhayaTime.Now().Unix() {
  38. EndTime = mhayaTime.Now().Unix()
  39. }
  40. eTime := mhayaTime.CreateFromTimestamp(EndTime).DailyTOTimeStamp()
  41. mhayaTime.CreateFromTimestamp(sTime).DiffInDays(mhayaTime.CreateFromTimestamp(eTime))
  42. }
  43. func PlayerPreserve(startTime, day int64) {
  44. var preserve []*Preserve
  45. _, curNum := GetNewPlayerMap(startTime, DailyRecordNewRegistered)
  46. if curNum < 1 {
  47. return
  48. }
  49. preserve = append(preserve, &Preserve{ID: 1, Num: curNum, Ratio: 100})
  50. for _, v := range preserveConfig {
  51. if day < v {
  52. preserve = append(preserve, &Preserve{ID: v, Num: 0, Ratio: 0})
  53. } else {
  54. // nextTime := mhayaTime.CreateFromTimestamp(startTime).AddDays(int(v) - 1)
  55. //next, nextNum := GetNewPlayerMap(startTime, DailyRecordOldLogin)
  56. preserve = append(preserve, &Preserve{ID: v, Num: 1, Ratio: 0})
  57. }
  58. }
  59. }
  60. func GetNewPlayerMap(startTime int64, op int) (map[string]struct{}, int) {
  61. var user = make(map[string]struct{})
  62. platformConfig := data.PlatformConfig.GatMap()
  63. channelConfig := data.ChannelConfig.GatMap()
  64. for _, v := range platformConfig {
  65. for _, v2 := range channelConfig {
  66. ret, err := GetAppointDailyRecordUserHash(v.Name, v2.Name, startTime, op)
  67. if err != nil {
  68. continue
  69. }
  70. for k, _ := range ret {
  71. if _, ok := user[k]; !ok {
  72. user[k] = struct{}{}
  73. }
  74. }
  75. }
  76. }
  77. return user, len(user)
  78. }