service/apollostruct/streamer_score_formula.go

52 lines
1.5 KiB
Go

package apollostruct
import "sort"
type FormulaParam struct {
Param string `json:"param"`
Maximum float64 `json:"maximum"`
Proportion float64 `json:"proportion"`
}
type ByProportion []*FormulaParam
func (b ByProportion) Len() int {
return len(b)
}
func (b ByProportion) Less(i, j int) bool {
if b[i].Proportion < b[j].Proportion {
return true
} else {
return false
}
}
func (b ByProportion) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}
type StreamerScoreFormulaCfg struct {
ZoneMomentCountInThreeDays *FormulaParam `json:"zone_moment_count_in_three_days"`
ZoneMomentCountInAMonth *FormulaParam `json:"zone_moment_count_in_a_month"`
IncomeInAWeek *FormulaParam `json:"income_in_a_week"`
NewZoneMemberCountInThreeDays *FormulaParam `json:"new_zone_member_count_in_three_days"`
NewZoneMemberCountInAMonth *FormulaParam `json:"new_zone_member_count_in_a_month"`
MomentCountInThreeDays *FormulaParam `json:"moment_count_in_three_days"`
Priority []string
}
func (s *StreamerScoreFormulaCfg) CalPriority() {
list := make(ByProportion, 0)
list = append(list, s.ZoneMomentCountInThreeDays)
list = append(list, s.ZoneMomentCountInAMonth)
list = append(list, s.IncomeInAWeek)
list = append(list, s.NewZoneMemberCountInThreeDays)
list = append(list, s.NewZoneMemberCountInAMonth)
list = append(list, s.MomentCountInThreeDays)
sort.Sort(list)
s.Priority = make([]string, 0)
for _, formula := range list {
s.Priority = append(s.Priority, formula.Param)
}
}