/// <summary> /// Calculate the cars that are in the lead based on the current ballots /// </summary> /// <param name="exclude">Optionally remove any cars in the exclude box, eg cars that won other awards</param> private void TallyCurrentBallots([Optional] bool exclude) { // generate a list of votes descending CurrentOrderedTally = _ballots.SelectMany(a => a.Top10).GroupBy(b => b).OrderByDescending(c => c.Count()).Select(d => d.Key).ToList(); CurrentOrderedTally.RemoveAll(m => m == 0); // remove any cars in the exclude box, eg cars that won other awards if (exclude) { WonOtherAward = Array.ConvertAll(txt_Exclude.Text.Split(), int.Parse).ToList(); CurrentOrderedTally = CurrentOrderedTally.Except(WonOtherAward).ToList(); } // Get the top 20 string top20display = ""; for (int i = 0; i < CurrentOrderedTally.Count; i++) { //add to the string top20display += CurrentOrderedTally[i] + ", "; // insert a special character to denote that 20 cars have been selected. // Sometimes things are changed after calculation and it helps to have more than 10 cars displayed if (i == 10) { top20display += " | "; } } // add strings to the interface txt_curWinners.Text = top20display.Substring(0, top20display.Length - 2); }
/// <summary> /// Calculate the cars that are in the lead based on the current ballots /// </summary> private void TallyCurrentBallots() { // Get Bests/non top 10 votes List <int> bestInShowList = Ballots.Select(i => i.BestInShow).ToList() .GroupBy(j => j) .OrderByDescending(k => k.Count()) .Select(l => l.Key) .ToList(); bestInShowList.RemoveAll(m => m == 0); if (bestInShowList.Count() > 2) { BestInShow = bestInShowList[0]; ReserveInShow = bestInShowList[1]; } BestStreetRod = GetTopValue(Ballots.Select(i => i.StreetRod).ToList()); BestModern = GetTopValue(Ballots.Select(i => i.Modern).ToList()); BestImport = GetTopValue(Ballots.Select(i => i.Import).ToList()); BestRatRod = GetTopValue(Ballots.Select(i => i.RatRod).ToList()); BestClassicTruck = GetTopValue(Ballots.Select(i => i.ClassicTruck).ToList()); BestBike = GetTopValue(Ballots.Select(i => i.Bike).ToList()); BestClassicCar = GetTopValue(Ballots.Select(i => i.ClassicCar).ToList()); BestFourWD = GetTopValue(Ballots.Select(i => i.FourWD).ToList()); // calculate car that is in the lead for general vote CurrentOrderedTally = Ballots.SelectMany(a => a.Top10).GroupBy(b => b).OrderByDescending(c => c.Count()).Select(d => d.Key).ToList(); CurrentOrderedTally.RemoveAll(m => m == 0); string top10display = ""; for (int i = 0; i < CurrentOrderedTally.Count; i++) { // check to see if the current car has already won something, skip if true if (new int[] { BestInShow, ReserveInShow, BestStreetRod, BestModern, BestImport, BestRatRod, BestClassicTruck, BestBike, BestClassicCar, BestFourWD }.Contains(CurrentOrderedTally[i])) { continue; } //add to the string top10display += CurrentOrderedTally[i] + ", "; } // add strings to the interface txt_curWinners.Text = top10display.Substring(0, top10display.Length - 2); txt_StreetRodWinner.Text = BestStreetRod.ToString(); txt_ModernWinner.Text = BestModern.ToString(); txt_ImportWinner.Text = BestImport.ToString(); txt_RatRodWinner.Text = BestRatRod.ToString(); txt_ClassicTruckWinner.Text = BestClassicTruck.ToString(); txt_BikeWinner.Text = BestBike.ToString(); txt_ClassicCarWinner.Text = BestClassicCar.ToString(); txt_FourWDWinner.Text = BestFourWD.ToString(); txt_BestInShowWinner.Text = BestInShow.ToString(); txt_ReserveInShowWinner.Text = ReserveInShow.ToString(); }