Det er et par dage siden, jeg oprettede mit spørgsmål. I mellemtiden har jeg faktisk lavet et lille test eksempel, jeg gerne vil have review'et.
Jeg gør brug af bayesian average formlen, som tager udgangspunkt i
http://www.frontendjunkie.com/2011/02/using-bayesian-average-to-rank-content.htmlHvad synes du om denne fremgangsmåde?
public class Item
{
public string Name { get; set; }
public string Size { get; set; }
public decimal Rank { get; set; }
public decimal Votes { get; set; }
public decimal Points { get; set; }
public decimal Favorites { get; set; }
public decimal Likes { get; set; }
public decimal Followers { get; set; }
public decimal AveragePoints { get; set; }
}
namespace BayesianAverageExample
{
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var items = new List<Item>
{
new Item
{
Name = "Item A", Size = "SizeA", Votes = 15, Points = 57, Likes = 55, Favorites = 14, Followers = 5
},
new Item
{
Name = "Item B", Size = "SizeB", Votes = 20, Points = 64, Likes = 45, Favorites = 24, Followers = 11
},
new Item
{
Name = "Item C", Size = "SizeC", Votes = 300, Points = 1015, Likes = 581, Favorites = 470, Followers = 531
},
new Item
{
Name = "Item D", Size = "SizeD", Votes = 250, Points = 938, Likes = 45, Favorites = 24, Followers = 11
},
new Item
{
Name = "Item E", Size = "SizeE", Votes = 400, Points = 1020, Likes = 450, Favorites = 350, Followers = 111
},
new Item
{
Name = "Item F", Size = "SizeF", Votes = 292, Points = 1188, Likes = 75, Favorites = 71, Followers = 91
},
new Item
{
Name = "Item G", Size = "SizeG", Votes = 35, Points = 147, Likes = 45, Favorites = 14, Followers = 10
},
new Item
{
Name = "Item H", Size = "SizeH", Votes = 100, Points = 300, Likes = 55, Favorites = 64, Followers = 71
},
new Item
{
Name = "Item I", Size = "SizeI", Votes = 2, Points = 8, Likes = 39, Favorites = 26, Followers = 31
}
};
var rankedItems = GetBayesianAverageList(items);
}
private static List<Item> GetBayesianAverageList(List<Item> items)
{
var totalVotes = items.Select(x => x.Votes).Sum();
var totalPoints = items.Select(x => x.Points).Sum();
var memberPopulation = 1500; // GetMembers();
var totalFavorites = items.Select(x => x.Favorites).Sum();
var totalLikes = items.Select(x => x.Likes).Sum();
var totalFollowers = items.Select(x => x.Followers).Sum();
foreach (var item in items)
{
item.AveragePoints = Math.Round(item.Points / item.Votes, 5);
var bayesianPoints = BayesianAverage(totalVotes, totalPoints, item.Votes, item.Points);
var bayesianFavorites = BayesianAverage(memberPopulation, totalFavorites, item.Favorites, item.Favorites);
var bayesianLikes = BayesianAverage(memberPopulation, totalLikes, item.Likes, item.Likes);
var bayesianFollowers = BayesianAverage(memberPopulation, totalFollowers, item.Followers, item.Followers);
item.Rank = bayesianPoints + bayesianFavorites + bayesianLikes + bayesianFollowers;
}
return items.OrderByDescending(x => x.Rank).ToList();
}
private static decimal BayesianAverage(decimal a, decimal b, decimal c, decimal d)
{
//
http://www.frontendjunkie.com/2011/02/using-bayesian-average-to-rank-content.html var bayesian = Math.Round(((a * (b / a)) + (c * d)) / (a + c), 5);
return bayesian;
}
}
}