rating.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package model
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. const (
  7. // TotalScore of up rating
  8. TotalScore = 600
  9. // LowerBoundScore ...
  10. LowerBoundScore = 240
  11. )
  12. // Rating of up
  13. type Rating struct {
  14. Score *Score `json:"score"`
  15. Rank *Rank `json:"rank"`
  16. Prize *Prize `json:"prize"`
  17. Privileges []*Privilege `json:"privileges"`
  18. }
  19. // Score of rating
  20. type Score struct {
  21. MID int64 `json:"mid"`
  22. Magnetic int `json:"magnetic"` // 电磁力
  23. Creative int `json:"creative"` // 创作力
  24. Influence int `json:"influence"` // 影响力
  25. Credit int `json:"credit"` // 信用分
  26. CDate time.Time `json:"c_date"` // 统计月
  27. StatStart time.Time `json:"stat_start"` // 统计周期开始日
  28. StatEnd time.Time `json:"stat_end"` // 统计周期结束日
  29. }
  30. // Rank of rating
  31. type Rank struct {
  32. Level RankLevel `json:"level"`
  33. Desc string `json:"desc"`
  34. }
  35. // RankLevel of rank
  36. type RankLevel int8
  37. // RankLevel list
  38. const (
  39. RankLevelSuper RankLevel = 10 * (1 + iota)
  40. RankLevelStrong
  41. RankLevelStandout
  42. RankLevelNormal
  43. RankLevelNone
  44. )
  45. // Ranks list all levels of rank
  46. var Ranks = []RankLevel{
  47. RankLevelSuper,
  48. RankLevelStrong,
  49. RankLevelStandout,
  50. RankLevelNormal,
  51. RankLevelNone,
  52. }
  53. // rank meta info
  54. var rankMeta = map[RankLevel]struct {
  55. score int
  56. desc string
  57. }{
  58. RankLevelSuper: {int(0.9 * TotalScore), "超能力"},
  59. RankLevelStrong: {int(0.75 * TotalScore), "强能力"},
  60. RankLevelStandout: {int(0.6 * TotalScore), "异能力"},
  61. RankLevelNormal: {int(0.3 * TotalScore), "常能力"},
  62. RankLevelNone: {0, "新能力"},
  63. }
  64. // Score of rankLevel
  65. func (r RankLevel) Score() int {
  66. if m, ok := rankMeta[r]; ok {
  67. return m.score
  68. }
  69. return RankLevelNone.Score()
  70. }
  71. // Rank content of rankLevel
  72. func (r RankLevel) Rank() *Rank {
  73. if m, ok := rankMeta[r]; ok {
  74. return &Rank{
  75. Level: r,
  76. Desc: m.desc,
  77. }
  78. }
  79. return RankLevelNone.Rank()
  80. }
  81. // Prize of rating
  82. type Prize struct {
  83. Level PrizeLevel `json:"level"`
  84. Desc string `json:"desc"`
  85. Content string `json:"content"`
  86. }
  87. // PrizeLevel of prize
  88. type PrizeLevel int8
  89. // Prize Level List
  90. const (
  91. PrizeLevelOne PrizeLevel = 10 * (1 + iota)
  92. PrizeLevelTwo
  93. PrizeLevelThree
  94. PrizeLevelFour
  95. PrizeLevelFive
  96. )
  97. // Prizes list prize levels by priority
  98. var Prizes = []PrizeLevel{
  99. PrizeLevelOne,
  100. PrizeLevelTwo,
  101. PrizeLevelThree,
  102. PrizeLevelFour,
  103. PrizeLevelFive,
  104. }
  105. var prizeMeta = map[PrizeLevel]struct {
  106. desc string
  107. content func(arg ...interface{}) string
  108. }{
  109. PrizeLevelOne: {desc: "睥睨众生奖", content: func(...interface{}) string {
  110. return "恭喜你获得超高的电磁力,那可真是会当临绝顶,一览众山小吖"
  111. }},
  112. PrizeLevelTwo: {desc: "稳如泰山奖", content: func(...interface{}) string {
  113. return "稳如泰山是你的优点,也可能是你的天花板,试着努力突破一下吧"
  114. }},
  115. PrizeLevelThree: {desc: "飞速进步奖", content: func(arg ...interface{}) string {
  116. return fmt.Sprintf("本月电磁力上升%d分,真是付出了超级多努力呢,请继续加油吧", arg[0])
  117. }},
  118. PrizeLevelFour: {desc: "特别有趣奖", content: func(...interface{}) string {
  119. return "看来你是被2233娘选中的孩子,希望这样的幸运能够继续支撑你努力"
  120. }},
  121. PrizeLevelFive: {desc: "全村希望奖", content: func(...interface{}) string {
  122. return "作为全村的希望,未来的你一定会感谢现在持续努力的自己"
  123. }},
  124. }
  125. // Prize constructor
  126. func (p PrizeLevel) Prize(arg ...interface{}) *Prize {
  127. if meta, ok := prizeMeta[p]; ok {
  128. return &Prize{
  129. Level: p,
  130. Desc: meta.desc,
  131. Content: meta.content(arg...),
  132. }
  133. }
  134. return PrizeLevelFive.Prize(arg...)
  135. }
  136. // Privilege of rating
  137. type Privilege struct{}