| 64 | } |
| 65 | |
| 66 | func (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 | |
| 87 | func (rc *RecomComponent) calcFreshnessScore(createdAt time.Time, weightExp string) float64 { |
| 88 | // TODO:cache compiled script |