public ElectionResults GetResults()
        {
            var result = new ElectionResults(Election);

            foreach (var district in Election.Districts)
            {
                var districtElectoralLists = Election.ElectoralLists.Where(e => e.Districts.Any(d => d == district));
                var listResultsList        = new List <ElectoralListResults>();

                // Recuento de votos
                foreach (var list in districtElectoralLists)
                {
                    var listResults = new ElectoralListResults(list, VoteCounter.CountVotes(list, district));
                    listResultsList.Add(listResults);
                }

                // Asignación de escaños (por el método D'Hondt)
                var orderedElectoralLists = listResultsList.OrderByDescending(l => l.Votes).ToList();
                for (int i = 1; i <= district.Seats; i++)
                {
                    var maxCoefficientElectoralList = orderedElectoralLists[0];
                    foreach (var list in orderedElectoralLists)
                    {
                        if ((list.Votes / (list.Seats + 1)) > (maxCoefficientElectoralList.Votes / (maxCoefficientElectoralList.Seats + 1)))
                        {
                            maxCoefficientElectoralList = list;
                        }
                    }
                    maxCoefficientElectoralList.AssignSeat();
                }

                var districtResults = new DistrictResults(district, listResultsList);
                result.AddResult(districtResults);
            }

            return(result);
        }
Esempio n. 2
0
 public int CountVotes(ElectoralList list, District district)
 {
     return(VoteCounter.CountVotes(list, district));
 }
Esempio n. 3
0
 public bool Vote(Elector elector, ElectoralList list)
 {
     return(VoteCounter.Vote(elector, list));
 }