MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / calcFreshnessScore

Method calcFreshnessScore

component/recom.go:87–104  ·  view source on GitHub ↗
(createdAt time.Time, weightExp string)

Source from the content-addressed store, hash-verified

85}
86
87func (rc *RecomComponent) calcFreshnessScore(createdAt time.Time, weightExp string) float64 {
88 // TODO:cache compiled script
89 hours := time.Since(createdAt).Hours()
90 scriptFreshness := tengo.NewScript([]byte(weightExp))
91 scriptFreshness.Add("score", 0.0)
92 scriptFreshness.Add("hours", 0)
93 sc, err := scriptFreshness.Compile()
94 if err != nil {
95 panic(err)
96 }
97 sc.Set("hours", hours)
98 err = sc.Run()
99 if err != nil {
100 panic(err)
101 }
102
103 return sc.Get("score").Float()
104}
105
106func (rc *RecomComponent) calcDownloadsScore(downloads int64, weightExp string) float64 {
107 // TODO:cache compiled script

Callers 1

calcTotalScoreMethod · 0.95

Calls 4

SetMethod · 0.65
RunMethod · 0.65
AddMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected