public PartyVote(PartyVote src) { Abbreviation = src.Abbreviation; FullName = src.FullName; TotalConstituencyVote = src.TotalConstituencyVote; TotalListVote = src.TotalListVote; PercentageConstituencyVote = src.PercentageConstituencyVote; PercentageListVote = src.PercentageListVote; }
private void SetupPartyPredictions() { // Copy over the year and notes to the predicted result. PredictedResult = new ElectionResult { Parties = PreviousResult.Parties, Year = PublishedDate.Year }; // Get the party swings. SetupPartyVoteSwings(); // Get the constituency swings. Dictionary <string, float> constituencySwingsByParty = PartyPredictions.ToDictionary( party => party.Abbreviation, party => party.PercentageConstituencyVoteSwing); // Copy over the constituency results from the previous and apply the swings. PredictedResult.FirstVotes = GetConstituencyResultProviderWithSwings(PreviousResult.FirstVotes, constituencySwingsByParty); // Get the list swings. Dictionary <string, float> listSwingsByParty = PartyPredictions.ToDictionary( party => party.Abbreviation, party => party.PercentageListVoteSwing); // Copy over the list results from the previous and apply the swings. PredictedResult.SecondVotes = GetConstituencyResultProviderWithSwings(PreviousResult.SecondVotes, listSwingsByParty); // Update the parties seats. for (int i = 0; i < PartyPredictions.Count; i++) { string partyAbbreviation = PartyPredictions[i].Abbreviation; PartyVote predictedResultPartyVote = PredictedResult.PartyVotes.FirstOrDefault(x => x.Abbreviation == partyAbbreviation); if (predictedResultPartyVote != null) { PartyPredictions[i].ConstituencySeats = predictedResultPartyVote.ConstituencySeats; PartyPredictions[i].ListSeats = predictedResultPartyVote.ListSeats; } } }
public PartyVoteSwing(PartyVote partyVote, ElectionResult previousResult) : base(partyVote) { // See if this party stood in the previous election. PartyVote previousVote = previousResult.PartyVotes.FirstOrDefault(x => x.Abbreviation == partyVote.Abbreviation); if (previousVote != null) { // Set up the swings based on the previous PercentageConstituencyVoteSwing = partyVote.PercentageConstituencyVote - previousVote.PercentageConstituencyVote; PercentageListVoteSwing = partyVote.PercentageListVote - previousVote.PercentageListVote; } else { // Otherwise the swing is the current predicted vote PercentageConstituencyVoteSwing = partyVote.PercentageConstituencyVote; PercentageListVoteSwing = partyVote.PercentageListVote; } }