Esempio n. 1
0
        private IEnumerable <RankingEntry> MapInfoListToEntries(
            IReadOnlyCollection <string> entryIds,
            IDictionary <string, JamEntry> entriesDictionary,
            IDictionary <string, EntryRatingsInfo> ratingsDictionary,
            RatingCriteriaOverview criteria
            )
        {
            foreach (var entryId in entryIds)
            {
                if (!entriesDictionary.TryGetValue(entryId, out var jamEntry))
                {
                    continue;
                }

                var ratingsInfo = ratingsDictionary.TryGetValue(entryId, out var foundRatingsInfo) ? foundRatingsInfo : null;

                yield return(MapInfoToEntry(jamEntry, ratingsInfo, criteria));
            }
        }
Esempio n. 2
0
        private RankingEntry MapInfoToEntry(JamEntry jamEntry, EntryRatingsInfo?ratingsInfo, RatingCriteriaOverview criteria)
        {
            // building the list of entries
            var ratings           = criteria.Criteria.Select(criterion => criterion.CreateRating()).ToList();
            var ratingsDictionary = ratings.ToDictionary(rating => rating.Id, StringComparer.OrdinalIgnoreCase);

            // applying the rating values stored for the entry
            var infoRatings = ratingsInfo?.Ratings ?? Enumerable.Empty <RatingInfo>();

            foreach (var ratingsInfoEntry in infoRatings)
            {
                if (!ratingsDictionary.TryGetValue(ratingsInfoEntry.Id, out var rating))
                {
                    continue;
                }

                rating.Value = ratingsInfoEntry.Value;
            }

            // building and returning the ranking entry
            return(new RankingEntry
            {
                JamEntry = jamEntry,
                Ratings = ratings,
                Comment = ratingsInfo?.Comment ?? string.Empty,
            });
        }
Esempio n. 3
0
        // -----------------
        // Loading from info
        // -----------------

        public RankingOverview MapInfoToRanking(JamRankingInfo rankingInfo, JamOverview jam, RatingCriteriaOverview criteria)
        {
            var entriesDictionary      = jam.Entries.ToDictionary(entry => entry.Id, StringComparer.OrdinalIgnoreCase);
            var ratingsDictionary      = rankingInfo.EntryRatings.ToDictionary(entry => entry.EntryId, StringComparer.OrdinalIgnoreCase);
            var blankRatingsDictionary = new Dictionary <string, EntryRatingsInfo>();

            var pendingIds = jam.Entries
                             .Select(entry => entry.Id)
                             .Except(rankingInfo.RankedEntries, StringComparer.OrdinalIgnoreCase)
                             .Except(rankingInfo.UnrankedEntries, StringComparer.OrdinalIgnoreCase)
                             .ToList();
            var pendingEntries = MapInfoListToEntries(pendingIds, entriesDictionary, blankRatingsDictionary, criteria).ToList();

            var rankedEntries   = MapInfoListToEntries(rankingInfo.RankedEntries, entriesDictionary, ratingsDictionary, criteria).ToList();
            var unrankedEntries = MapInfoListToEntries(rankingInfo.UnrankedEntries, entriesDictionary, ratingsDictionary, criteria).ToList();

            return(new RankingOverview
            {
                PendingEntries = pendingEntries,
                RankedEntries = rankedEntries,
                UnrankedEntries = unrankedEntries,
            });
        }