Skip to content

Commit

Permalink
Merge pull request #1085 from amvanbaren/log-relevance-calculation
Browse files Browse the repository at this point in the history
Log relevance score calculation
  • Loading branch information
amvanbaren authored Jan 27, 2025
2 parents 9a3cb9c + 95cc743 commit e56f7e1
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,39 @@ private double calculateRating(Extension extension, SearchStats stats) {
}

private double calculateRelevance(Extension extension, ExtensionVersion latest, SearchStats stats, ExtensionSearch entry) {
var extensionId = NamingUtil.toExtensionId(extension);
logger.info(">> [{}] CALCULATE RELEVANCE", extensionId);
var ratingValue = 0.0;
if (extension.getAverageRating() != null) {
logger.info("[{}] INCLUDE AVG RATING", extensionId);
var reviewCount = extension.getReviewCount();
// Reduce the rating relevance if there are only few reviews
var countRelevance = saturate(reviewCount, 0.25);
ratingValue = (extension.getAverageRating() / 5.0) * countRelevance;
logger.info("[{}] {} = {} * {} | {}", extensionId, ratingValue, extension.getAverageRating() / 5.0, countRelevance, reviewCount);
}
var downloadsValue = entry.getDownloadCount() / stats.downloadRef;
var timestamp = latest.getTimestamp();
var timestampValue = Duration.between(stats.oldest, timestamp).toSeconds() / stats.timestampRef;
var relevance = ratingRelevance * limit(ratingValue) + downloadsRelevance * limit(downloadsValue)
+ timestampRelevance * limit(timestampValue);
logger.info("[{}] RELEVANCE: {} = {} * {} + {} * {} + {} * {}", extensionId, relevance, ratingRelevance, limit(ratingValue), downloadsRelevance, limit(downloadsValue), timestampRelevance, limit(timestampValue));
logger.info("[{}] VALUES: {} | {} | {}", extensionId, ratingValue, downloadsValue, timestampValue);

// Reduce the relevance value of unverified extensions
if (!isVerified(latest)) {
relevance *= unverifiedRelevance;
logger.info("[{}] UNVERIFIED: {} * {}", extensionId, relevance, unverifiedRelevance);
}

// Reduce the relevance value of deprecated extensions
if (extension.isDeprecated()) {
relevance *= deprecatedRelevance;
logger.info("[{}] DEPRECATED: {} * {}", extensionId, relevance, deprecatedRelevance);
}

if (Double.isNaN(entry.getRelevance()) || Double.isInfinite(entry.getRelevance())) {
if (Double.isNaN(relevance) || Double.isInfinite(relevance)) {
logger.info("[{}] INVALID RELEVANCE", extensionId);
var message = "Invalid relevance for entry " + NamingUtil.toExtensionId(entry);
try {
message += " " + new ObjectMapper().writeValueAsString(stats);
Expand All @@ -105,6 +114,7 @@ private double calculateRelevance(Extension extension, ExtensionVersion latest,
relevance = 0.0;
}

logger.info("<< [{}] CALCULATE RELEVANCE: {}", extensionId, relevance);
return relevance;
}

Expand Down

0 comments on commit e56f7e1

Please sign in to comment.