Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude level author's relations from cool levels #606

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Refresh.GameServer/Database/GameDatabaseContext.Relations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public bool UnfavouriteLevel(GameLevel level, GameUser user)
return true;
}

public int GetFavouriteCountForLevel(GameLevel level) => this.FavouriteLevelRelations
.Count(r => r.Level == level);
public int GetFavouriteCountForLevel(GameLevel level, bool includingAuthor = true) => this.FavouriteLevelRelations
.Count(r => r.Level == level && (includingAuthor || r.User != level.Publisher));

#endregion

#region Favouriting Users
Expand Down Expand Up @@ -301,8 +301,11 @@ public bool RateLevel(GameLevel level, GameUser user, RatingType type)
return true;
}

public int GetTotalRatingsForLevel(GameLevel level, RatingType type) =>
this.RateLevelRelations.Count(r => r.Level == level && r._RatingType == (int)type);
public int GetTotalRatingsForLevel(GameLevel level, RatingType type, bool includingAuthor = true) =>
this.RateLevelRelations.Count(r =>
r.Level == level &&
r._RatingType == (int)type &&
(includingAuthor || r.User != level.Publisher));

/// <summary>
/// Adds a review to the database, deleting any old ones by the user on that level.
Expand Down Expand Up @@ -408,8 +411,8 @@ public int GetTotalPlaysForLevel(GameLevel level) =>
public int GetTotalPlaysForLevelByUser(GameLevel level, GameUser user) =>
this.GetAllPlaysForLevelByUser(level, user).Sum(playLevelRelation => playLevelRelation.Count);

public int GetUniquePlaysForLevel(GameLevel level) =>
this.UniquePlayLevelRelations.Count(r => r.Level == level);
public int GetUniquePlaysForLevel(GameLevel level, bool includingAuthor = true) =>
this.UniquePlayLevelRelations.Count(r => r.Level == level && (includingAuthor || r.User != level.Publisher));

#endregion

Expand Down
10 changes: 5 additions & 5 deletions Refresh.GameServer/Workers/CoolLevelsWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ private static float CalculatePositiveScore(GameLevel level, DataContext context
if (level.TeamPicked)
score += 50;

int positiveRatings = context.Database.GetTotalRatingsForLevel(level, RatingType.Yay);
int negativeRatings = context.Database.GetTotalRatingsForLevel(level, RatingType.Boo);
int uniquePlays = context.Database.GetUniquePlaysForLevel(level);
int positiveRatings = context.Database.GetTotalRatingsForLevel(level, RatingType.Yay, false);
int negativeRatings = context.Database.GetTotalRatingsForLevel(level, RatingType.Boo, false);
int uniquePlays = context.Database.GetUniquePlaysForLevel(level, false);

score += positiveRatings * positiveRatingPoints;
score += uniquePlays * uniquePlayPoints;
score += context.Database.GetFavouriteCountForLevel(level) * heartPoints;
score += context.Database.GetFavouriteCountForLevel(level, false) * heartPoints;

// Reward for a good ratio between plays and yays
float ratingRatio = (positiveRatings - negativeRatings) / (float)uniquePlays;
Expand All @@ -143,7 +143,7 @@ private static float CalculateNegativeScore(GameLevel level, DataContext context
// The percentage of how much penalty should be applied at the end of the calculation.
const float penaltyMultiplier = 0.75f;

penalty += context.Database.GetTotalRatingsForLevel(level, RatingType.Boo) * negativeRatingPenalty;
penalty += context.Database.GetTotalRatingsForLevel(level, RatingType.Boo, false) * negativeRatingPenalty;

if (level.Publisher == null)
penalty += noAuthorPenalty;
Expand Down
Loading