123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- package model
- import (
- xtime "go-common/library/time"
- )
- const (
- DefaultAlgorithm = "default"
- WilsonLHRRAlgorithm = "wilsonLHRR"
- WilsonLHRRFluidAlgorithm = "wilsonLHRRFluid"
- OriginAlgorithm = "origin"
- LikeDescAlgorithm = "likeDesc"
- StateInactive = int(0)
- StateActive = int(1)
- StateDelete = int(2)
-
- StatisticActionRootReply = "rr"
- StatisticActionChildReply = "cr"
- StatisticActionLike = "l"
- StatisticActionHate = "h"
- StatisticActionReport = "r"
- StatisticKindTotal = "t"
- StatisticKindHot = "h"
- DatabusActionReply = "reply"
- DatabusActionReport = "report_add"
- DatabusActionLike = "like"
- DatabusActionCancelLike = "like_cancel"
- DatabusActionHate = "hate"
- DatabusActionCancelHate = "hate_cancel"
-
- DatabusActionDel = "reply_del"
-
- DatabusActionRptDel = "report_del"
-
- DatabusActionRecover = "reply_recover"
-
- DatabusActionTop = "top"
-
- DatabusActionUnTop = "untop"
- DatabusActionReIdx = "re_idx"
-
- MinLikeCount = 3
- MinRootReplyCount = 20
- SlotsNum = 100
- )
- var (
- StatisticActions = []string{StatisticActionRootReply, StatisticActionChildReply, StatisticActionLike, StatisticActionHate, StatisticActionReport}
- StatisticKinds = []string{StatisticKindTotal, StatisticKindHot}
- StatisticsDatabaseI = []string{"`name`", "`date`", "`hour`"}
- StatisticsDatabaseU = []string{"hot_like", "hot_hate", "hot_report", "hot_child", "total_like", "total_hate", "total_report", "total_root", "total_child"}
- StatisticsDatabaseS = []string{"hot_like_uv", "hot_hate_uv", "hot_report_uv", "hot_child_uv", "total_like_uv", "total_hate_uv", "total_report_uv", "total_child_uv", "total_root_uv"}
- )
- type ReplyScore struct {
- RpID int64
- Score float64
- }
- type ReplyStat struct {
- RpID int64 `json:"rpid"`
- Like int `json:"like"`
- Hate int `json:"hate"`
- Reply int `json:"reply"`
- Report int `json:"report"`
- SubjectTime xtime.Time `json:"subject_time"`
- ReplyTime xtime.Time `json:"reply_time"`
- }
- type ReplyResp struct {
- RpIDs []int64
-
- TestSetName string
- }
- type ReplyList struct {
- RpID []int64
- }
- type SlotStat struct {
- Name string
- Slot int
- Algorithm string
- Weight string
- }
- type SlotsStat struct {
- Name string
- Slots []int
- Algorithm string
- Weight string
- }
- type SlotsMapping struct {
- Name string
- Slots []int
- }
- type StatisticsStat struct {
-
- Slot int
-
- Name string
-
- HotLike int64
- HotHate int64
- HotChildReply int64
- HotReport int64
-
- TotalLike int64
- TotalHate int64
- TotalReport int64
- TotalRootReply int64
- TotalChildReply int64
- HotLikeUV int64
- HotHateUV int64
- HotReportUV int64
- HotChildUV int64
- TotalLikeUV int64
- TotalHateUV int64
- TotalReportUV int64
- TotalChildUV int64
- TotalRootUV int64
- }
- func (stat1 *StatisticsStat) Merge(stat2 *StatisticsStat) (stat3 *StatisticsStat) {
- stat3 = new(StatisticsStat)
- stat3.TotalLike = stat1.TotalLike + stat2.TotalLike
- stat3.TotalHate = stat1.TotalHate + stat2.TotalHate
- stat3.TotalReport = stat1.TotalReport + stat2.TotalReport
- stat3.TotalRootReply = stat1.TotalRootReply + stat2.TotalRootReply
- stat3.TotalChildReply = stat1.TotalChildReply + stat2.TotalChildReply
- stat3.HotLike = stat1.HotLike + stat2.HotLike
- stat3.HotHate = stat1.HotHate + stat2.HotHate
- stat3.HotReport = stat1.HotReport + stat2.HotReport
- stat3.HotChildReply = stat1.HotChildReply + stat2.HotChildReply
- stat3.HotLikeUV = stat1.HotLikeUV + stat2.HotLikeUV
- stat3.HotHateUV = stat1.HotHateUV + stat2.HotHateUV
- stat3.HotReportUV = stat1.HotReportUV + stat2.HotReportUV
- stat3.HotChildUV = stat1.HotChildUV + stat2.HotChildUV
- stat3.TotalLikeUV = stat1.TotalLikeUV + stat2.TotalLikeUV
- stat3.TotalHateUV = stat1.TotalHateUV + stat2.TotalHateUV
- stat3.TotalReportUV = stat1.TotalReportUV + stat2.TotalReportUV
- stat3.TotalRootUV = stat1.TotalRootUV + stat2.TotalRootUV
- stat3.TotalChildUV = stat1.TotalChildUV + stat2.TotalChildUV
- return
- }
- type StrategyStat struct {
- Name string `json:"name"`
- Percent int `json:"percent"`
- Algorithm string `json:"algorithm"`
- Args map[string]float64 `json:"args"`
- }
- type RefreshChecker struct {
- Oid int64
- Type int
- LastTimeStamp int64
- }
- type WilsonLHRRWeight struct {
- Like float64
- Hate float64
- Reply float64
- Report float64
- }
- type WilsonLHRRFluidWeight struct {
- Like float64
- Hate float64
- Reply float64
- Report float64
- Slope float64
- }
- type EventMsg struct {
- Action string `json:"action"`
- Oid int64 `json:"oid"`
- Tp int `json:"tp"`
- }
- type StatsMsg struct {
- Action string `json:"action"`
- Mid int64 `json:"mid"`
- Subject *Subject `json:"subject"`
- Reply *Reply `json:"reply"`
- Report *Report `json:"report,omitempty"`
- }
- func (r *StatsMsg) Sharding() int64 {
- return r.Mid % SlotsNum
- }
- func (r *StatsMsg) HotCondition() bool {
- if r.Action == DatabusActionReply && !r.Reply.IsRoot() {
- return true
- }
- if r.Reply.IsRoot() && r.Reply.Like >= MinLikeCount &&
- (r.Action == DatabusActionLike || r.Action == DatabusActionHate ||
- r.Action == DatabusActionCancelLike || r.Action == DatabusActionCancelHate || r.Action == DatabusActionReport) {
- return true
- }
- return false
- }
- type Reply struct {
- RpID int64 `json:"rpid"`
- Mid int64 `json:"mid"`
- Root int64 `json:"root"`
- Parent int64 `json:"parent"`
- RCount int `json:"rcount"`
- Floor int `json:"floor"`
- State int8 `json:"state"`
- Attr uint32 `json:"attr"`
- CTime xtime.Time `json:"ctime"`
- Like int `json:"like"`
- Hate int `json:"hate"`
- }
- func (r *Reply) Legal() bool {
-
- return r.State == 0 || r.State == 1 || r.State == 2 || r.State == 5 || r.State == 6
- }
- func (r *Reply) ShowAfterAudit() bool {
- return r.State == 11
- }
- func (r *Reply) AuditButShow() bool {
- return r.State == 5
- }
- func (r *Reply) IsRoot() bool {
- return r.Root == 0
- }
- func (r *Reply) Qualified() bool {
- return r.Like >= MinLikeCount
- }
- type Report struct {
- RpID int64 `json:"rpid"`
- Mid int64 `json:"mid"`
- Count int `json:"count"`
- Score int `json:"score"`
- State int8 `json:"state"`
- CTime xtime.Time `json:"ctime"`
- Attr uint32 `json:"attr"`
- }
- type Subject struct {
- Oid int64 `json:"oid"`
- Type int `json:"type"`
- Mid int64 `json:"mid"`
- RCount int `json:"rcount"`
- State int8 `json:"state"`
- Attr uint32 `json:"attr"`
- CTime xtime.Time `json:"ctime"`
- }
- func (s *Subject) ShowHotReply() bool {
- return s.RCount >= MinRootReplyCount
- }
|