score.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package service
  2. import (
  3. "math"
  4. "time"
  5. "go-common/app/job/main/up-rating/model"
  6. xtime "go-common/library/time"
  7. )
  8. // Copy copy data from month to month
  9. func (s *Service) Copy(rch chan []*model.Rating, wch chan []*model.Rating, past map[int64]*model.Past, params *model.RatingParameter) {
  10. defer close(wch)
  11. for rs := range rch {
  12. for _, r := range rs {
  13. if _, ok := past[r.MID]; !ok {
  14. continue
  15. }
  16. r.MetaCreativityScore = 0
  17. csr := past[r.MID].MetaCreativityScore
  18. if csr == 0 {
  19. r.CreativityScore = 0
  20. } else {
  21. r.CreativityScore = int64(math.Min(float64(params.WCS)*math.Log(float64(csr)), float64(params.WCSR)))
  22. }
  23. r.MetaInfluenceScore = 0
  24. isr := past[r.MID].MetaInfluenceScore
  25. if isr == 0 {
  26. r.InfluenceScore = 0
  27. } else {
  28. r.InfluenceScore = int64(math.Min(float64(params.WIS)*math.Log(float64(isr)), float64(params.WISR)))
  29. }
  30. r.Date = xtime.Time(time.Date(r.Date.Time().Year(), r.Date.Time().Month()+1, 1, 0, 0, 0, 0, time.Local).Unix())
  31. r.MagneticScore = r.CreativityScore + r.InfluenceScore + r.CreditScore
  32. }
  33. wch <- rs
  34. }
  35. }
  36. // CalScore cal rating score
  37. func (s *Service) CalScore(rch chan []*model.BaseInfo,
  38. wch chan []*model.Rating,
  39. params *model.RatingParameter,
  40. past map[int64]*model.Past, date time.Time) {
  41. defer close(wch)
  42. for bs := range rch {
  43. m := make([]*model.Rating, 0)
  44. for _, b := range bs {
  45. if !b.Date.Time().Equal(date) {
  46. continue
  47. }
  48. r := &model.Rating{
  49. MID: b.MID,
  50. TagID: b.TagID,
  51. MetaCreativityScore: calCreativetyMetaScore(b, params),
  52. CreativityScore: calCreativityScore(b, params, past),
  53. MetaInfluenceScore: calInfluenceMetaScore(b, params),
  54. InfluenceScore: calInfluenceScore(b, params, past),
  55. CreditScore: calCreditScore(b, params, past),
  56. Date: b.Date,
  57. }
  58. r.MagneticScore = r.CreativityScore + r.InfluenceScore + r.CreditScore
  59. m = append(m, r)
  60. }
  61. wch <- m
  62. }
  63. }
  64. func calCreativetyMetaScore(b *model.BaseInfo, params *model.RatingParameter) int64 {
  65. // ps: 当月播放分
  66. ps := params.WDP*b.PlayIncr + params.WDC*b.CoinIncr
  67. // ubs: 当月投稿低保分
  68. ubs := params.WDV * int64(math.Min(float64(b.Avs), float64(params.WMDV)))
  69. // csm: 当月创作力得分
  70. csm := ps + ubs
  71. return csm
  72. }
  73. func calCreativityScore(b *model.BaseInfo, params *model.RatingParameter, past map[int64]*model.Past) int64 {
  74. csm := calCreativetyMetaScore(b, params)
  75. // csr: csm + past 创作力原始分
  76. var csr int64
  77. if _, ok := past[b.MID]; ok {
  78. csr = csm + past[b.MID].MetaCreativityScore
  79. } else {
  80. csr = csm
  81. }
  82. if csr < 1 {
  83. return 0
  84. }
  85. // cs: 创作力总分
  86. cs := math.Min(float64(params.WCS)*math.Log(float64(csr)), float64(params.WCSR))
  87. return int64(cs)
  88. }
  89. func calInfluenceMetaScore(b *model.BaseInfo, params *model.RatingParameter) int64 {
  90. // mfans: 当月活跃粉丝数
  91. mfans := params.WMAAFans*(b.MAAFans+b.MAHFans) + params.WMAHFans*b.MAHFans
  92. return mfans
  93. }
  94. func calInfluenceScore(b *model.BaseInfo, params *model.RatingParameter, past map[int64]*model.Past) int64 {
  95. mfans := calInfluenceMetaScore(b, params)
  96. // isr: 影响力原始分
  97. var isr int64
  98. if _, ok := past[b.MID]; ok {
  99. isr = mfans + past[b.MID].MetaInfluenceScore
  100. } else {
  101. isr = mfans
  102. }
  103. if isr < 1 {
  104. return 0
  105. }
  106. // is: up主影响力分
  107. is := math.Min(float64(params.WIS)*math.Log(float64(isr)), float64(params.WISR))
  108. return int64(is)
  109. }
  110. func calCreditScore(b *model.BaseInfo, params *model.RatingParameter, past map[int64]*model.Past) int64 {
  111. addScore := min(b.OpenAvs*params.HV, params.HVM)
  112. minusScore := min(b.LockedAvs*params.HL, params.HLM)
  113. var cs int64
  114. if _, ok := past[b.MID]; ok {
  115. cs = past[b.MID].CreditScore + addScore - minusScore
  116. } else {
  117. cs = params.HBASE + addScore - minusScore
  118. }
  119. if cs < 0 {
  120. cs = 0
  121. }
  122. return min(cs, params.HR)
  123. }
  124. func min(x, y int64) int64 {
  125. if x > y {
  126. return y
  127. }
  128. return x
  129. }