(createdAt time.Time, weightExp string)
| 85 | } |
| 86 | |
| 87 | func (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 | |
| 106 | func (rc *RecomComponent) calcDownloadsScore(downloads int64, weightExp string) float64 { |
| 107 | // TODO:cache compiled script |
no test coverage detected