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

Method calcTotalScore

component/recom.go:66–85  ·  view source on GitHub ↗
(ctx context.Context, repo *database.Repository, weights map[string]string)

Source from the content-addressed store, hash-verified

64}
65
66func (rc *RecomComponent) calcTotalScore(ctx context.Context, repo *database.Repository, weights map[string]string) float64 {
67 score := float64(0)
68
69 if freshness, ok := weights["freshness"]; ok {
70 score += rc.calcFreshnessScore(repo.CreatedAt, freshness)
71 }
72
73 if downloads, ok := weights["downloads"]; ok {
74 score += rc.calcDownloadsScore(repo.DownloadCount, downloads)
75 }
76
77 qualityScore, err := rc.calcQualityScore(ctx, repo)
78 if err != nil {
79 slog.Error("failed to calculate quality score", slog.Any("error", err))
80 } else {
81 score += qualityScore
82 }
83
84 return score
85}
86
87func (rc *RecomComponent) calcFreshnessScore(createdAt time.Time, weightExp string) float64 {
88 // TODO:cache compiled script

Callers 2

TestCalculateRecomScoreFunction · 0.95
CalculateRecomScoreMethod · 0.95

Calls 4

calcFreshnessScoreMethod · 0.95
calcDownloadsScoreMethod · 0.95
calcQualityScoreMethod · 0.95
ErrorMethod · 0.80

Tested by 1

TestCalculateRecomScoreFunction · 0.76