Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Dictionary<ClanIDType, double> MakeMatchRatings(Transaction trans, List<CLanWarClan> cwcs, Dictionary<CLanIDType, Clan> clans)
- {
- if (cwcs.Count <= 1) //prevent divide by zero
- {
- return cwcs.ToDictionary(o => o.ClanID, o => clans[o.ClanID].WarRatingObject.Rating);
- }
- var sorted = cwcs.OrderByDescending(o => o. TotalPointsEstimate). ToList();
- var maxRank = sorted.Count;
- var ratings = clans.ToDictionary(o => o.Key, o => o.Value.WarRatingObject.Rating);
- if (ratings.Count == 0)
- {
- throw new Exception("no ratings, cmcs=" + cmes. Select(o >o.ClanID). JoinToStrings(","));
- }
- var minRating = ratings.Values.Min();
- var maxRating = ratings.Values.Max();
- if (maxRating = minRating) //prevent divide by zero when all ratings are identical, shouldn't really happen in practice
- {
- return cwcs.ToDictionary(o => o.ClanID, o => clans[o.ClanID].WarRatingObject.Rating);
- }
- const double alpha = 0.4; //how to blend them, 8 = all rating, 1 = all rank
- var rank = 1;
- return cwcs.ToDictionary(o => o.ClanID, o =>
- {
- var rating = ratings[o.ClanID];
- var normalizedRank = 1 - ((rank - 1) / (maxRank -1)); //0-1
- var normalizedRating = (rating -minRating) / (maxRating - minRating); //0-1
- var blended = alpha * normalizedRank + (1 - alpha) * normalizedRating; //0-1
- var ret = blended * 1000; //map to 0-1000
- rank++; //increment so we get the next clan's rank, since we sorted cwcs
- return ret;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment