Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
spektor56 committed Sep 11, 2020
1 parent e4f7817 commit de578da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions LBGDBMetadata/LbgdbMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using LBGDBMetadata.Extensions;
using LBGDBMetadata.LaunchBox.Metadata;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Playnite.SDK.Metadata;
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
Expand All @@ -27,6 +28,18 @@ public LbgdbMetadataProvider(MetadataRequestOptions options, LbgdbMetadataPlugin
_plugin = plugin;
}

private int GetWeightedRating(double communityRatingCount, double communityRating )
{
double positiveVotes = Math.Floor((communityRating / 100) * communityRatingCount);
double negativeVotes = communityRatingCount - positiveVotes;

double totalVotes = positiveVotes + negativeVotes;
double average = totalVotes < 1 ? 0 : positiveVotes / totalVotes;
double score = average - (average - 0.5) * Math.Pow(2, -Math.Log10(totalVotes + 1));

return (int)(score * 100);
}

private GameImage GetBestImage(List<GameImage> images, HashSet<string> imageTypes)
{
if (images.Count < 1)
Expand Down Expand Up @@ -187,9 +200,9 @@ public override string GetDescription()

if (game != null)
{
if (game.CommunityRating != null)
if (game.CommunityRating != null && game.CommunityRatingCount > 0)
{
return (int)game.CommunityRating;
return GetWeightedRating(game.CommunityRatingCount, (double)game.CommunityRating);
}
}

Expand Down
2 changes: 1 addition & 1 deletion LBGDBMetadata/extension.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: LBGDB metadata provider
Author: Spektor
Version: 1.1
Version: 1.2
Module: LBGDBMetadata.dll
Type: MetadataProvider
Icon: Resources\launchbox.ico

0 comments on commit de578da

Please sign in to comment.