private static IEnumerable <FactionVoteStatsViewModel> CalculateFactionStats(IEnumerable <Vote> votes, IEnumerable <Player> allPlayers)
        {
            var factionVoteStatsCollection = new List <FactionVoteStatsViewModel>();

            var allRecruitmens = allPlayers.SelectMany(p => p.Recruitments);
            var factionNames   = allRecruitmens.GroupBy(r => r.FactionName).Select(g => g.Key);

            foreach (var factionName in factionNames)
            {
                var factionVoteStats = new FactionVoteStatsViewModel();
                factionVoteStats.Name       = factionName;
                factionVoteStats.Allegiance = Allegiance.Unknown;

                var votesByFaction = votes.Where(v => string.Equals(v.GetVoteInfo(allPlayers).VoterFactionName, factionName));

                factionVoteStats.VotesCast = votesByFaction.Count();

                factionVoteStats.PercentageOfVotesOntoOwnFaction =
                    VoteAnalyser.CalculatePercentage(votesByFaction, (v) => v.TargetFactionName == factionName, allPlayers);

                var firstFactionVote = votesByFaction.FirstOrDefault();

                if (firstFactionVote != null)
                {
                    factionVoteStats.Allegiance = firstFactionVote.GetVoteInfo(allPlayers).VoterFactionAllegiance;
                }

                factionVoteStatsCollection.Add(factionVoteStats);
            }

            return(factionVoteStatsCollection);
        }
Example #2
0
        public ActionResult Index()
        {
            ViewBag.Message = DetermineHomepageMessage();

            HomeViewModel viewModel = new HomeViewModel();

            var players = this.repo.FindAllPlayers();
            var days    = this.repo.FindAllDays();

            // Get all players to display and their post counts and so forth
            viewModel.Players = this.DeterminePlayers(players);

            // Enumerate the list of player names for the drop down menu
            var playerNames = players.Select(player => new SelectListItem()
            {
                Value = player.Name, Text = player.Name
            }).ToList();

            playerNames.Add(new SelectListItem()
            {
                Value = string.Empty, Text = string.Empty
            });
            viewModel.PlayerNames = playerNames.OrderBy(p => p.Text).ToArray();

            // Find all current votes
            viewModel.VoteSituation = VoteAnalyser.DetermineCurrentVoteSituation(this.repo.FindAllVotes(), players, days);

            viewModel.LastUpdated = this.repo.FindLastUpdatedDateTime();

            viewModel.Days = days;

            return(this.View(viewModel));
        }
        private static void CalculateTotalStats(VoteStatsViewModel viewModel, IEnumerable <Vote> votes, IEnumerable <Player> allPlayers)
        {
            viewModel.NumberOfVotes = votes.Count();
            viewModel.PercentageOfVotesOntoMafia =
                VoteAnalyser.CalculatePercentage(votes, (v) => v.TargetAllegiance == Allegiance.Mafia, allPlayers);

            viewModel.PercentageOfVotesOntoTown =
                VoteAnalyser.CalculatePercentage(votes, (v) => v.TargetAllegiance == Allegiance.Town, allPlayers);

            viewModel.PercentageOfVotesOntoNonTown =
                VoteAnalyser.CalculatePercentage(votes, (v) => v.TargetAllegiance != Allegiance.Town, allPlayers);
        }
        private static IEnumerable <IndividualVoteStatsViewModel> CalculateIndividualStats(IEnumerable <Vote> votes, IEnumerable <Player> allPlayers)
        {
            var individualStats = new List <IndividualVoteStatsViewModel>();

            foreach (var player in allPlayers)
            {
                if (player.Participating)
                {
                    var stats = new IndividualVoteStatsViewModel();
                    stats.Name        = player.Name;
                    stats.FactionName = player.Recruitments.Last().FactionName;
                    stats.Character   = player.Character;

                    var individualVotes = votes.Where(v => string.Equals(v.Voter, player.Name));
                    stats.VotesCast = individualVotes.Count();

                    stats.PercentageOfVotesOntoMafia =
                        VoteAnalyser.CalculatePercentage(individualVotes, (v) => v.TargetAllegiance == Allegiance.Mafia, allPlayers);

                    stats.PercentageOfVotesOntoNonTown =
                        VoteAnalyser.CalculatePercentage(individualVotes, (v) => v.TargetAllegiance != Allegiance.Town, allPlayers);

                    stats.PercentageOfVotesOntoTown =
                        VoteAnalyser.CalculatePercentage(individualVotes, (v) => v.TargetAllegiance == Allegiance.Town, allPlayers);

                    stats.PercentageOfVotesOntoOwnAllegiance =
                        VoteAnalyser.CalculatePercentage(individualVotes, (v) => v.TargetAllegiance == v.VoterFactionAllegiance, allPlayers);

                    stats.PercentageOfVotesOntoOwnFaction =
                        VoteAnalyser.CalculatePercentage(individualVotes, (v) => v.TargetFactionName == v.VoterFactionName, allPlayers);

                    stats.TimesVotedFor = votes.Where(v => string.Equals(v.Recipient, player.Name)).Count();

                    individualStats.Add(stats);
                }
            }

            return(individualStats);
        }