Beispiel #1
0
        private void SetupInterpolatedPredictions(
            IPollsProvider polls,
            ElectionResult previousElectionResult)
        {
            InterpolatedPredictions.Clear();
            if (!polls.PollsByDate.Any())
            {
                return;
            }

            // Make up a set of dummy polls from the interpolated values
            DateTime startDate = polls.PollsByDate.First().PublicationDate;
            DateTime lastDate  = polls.PollsByDate.Last().PublicationDate;
            int      numberOfInterpolatedValues = (lastDate - startDate).Days + 1;

            List <PartyPollingResultsSet> constituencyPredictors =
                PartyPollingSets.Where(x => x.IsConstituency).ToList();
            List <PartyPollingResultsSet> listPredictors =
                PartyPollingSets.Where(x => !x.IsConstituency).ToList();

            for (int i = 0; i < numberOfInterpolatedValues; i++)
            {
                OpinionPoll interpolationPoll =
                    GetInterpolationPoll(polls, startDate, i, constituencyPredictors, listPredictors);

                ElectionPrediction electionPrediction =
                    new ElectionPrediction(previousElectionResult, interpolationPoll);
                InterpolatedPredictions.Add(new PollingPrediction(electionPrediction, interpolationPoll));
            }
        }
Beispiel #2
0
        public ElectionPrediction(
            ElectionResult previousResult,
            OpinionPoll opinionPoll)
        {
            PreviousResult = previousResult;
            OpinionPoll    = opinionPoll;

            PartyPredictions = new List <PartyVoteSwing>();
            SetupPartyPredictions();
        }
Beispiel #3
0
        public ElectionPrediction(ElectionPrediction src)
        {
            PreviousResult  = src.PreviousResult;
            OpinionPoll     = new OpinionPoll(src.OpinionPoll);
            PredictedResult = src.PredictedResult;

            PartyPredictions = new List <PartyVoteSwing>();
            foreach (PartyVoteSwing partyPrediction in src.PartyPredictions)
            {
                PartyPredictions.Add(new PartyVoteSwing(partyPrediction));
            }
        }
Beispiel #4
0
        private static OpinionPoll GetInterpolationPoll(
            IPollsProvider polls,
            DateTime startDate,
            int daysSinceStart,
            List <PartyPollingResultsSet> constituencyPredictors,
            List <PartyPollingResultsSet> listPredictors)
        {
            DateTime interpolatedDate = startDate.AddDays(daysSinceStart);

            // Get the interpolated percentages
            List <PartyResult> constituencyPredictions =
                constituencyPredictors.Select(
                    constituencyPredictor => new PartyResult
            {
                PartyAbbreviation = constituencyPredictor.PartyAbbreviation,
                PercentageOfVotes = constituencyPredictor.GetInterploatedValue(interpolatedDate)
            }).ToList();

            List <PartyResult> listPredictions =
                listPredictors.Select(
                    listPredictor => new PartyResult
            {
                PartyAbbreviation = listPredictor.PartyAbbreviation,
                PercentageOfVotes = listPredictor.GetInterploatedValue(interpolatedDate)
            }).ToList();

            // Make up the poll
            OpinionPoll interpolationPoll = new OpinionPoll
            {
                Link                    = polls.PollsByDate.First().Link,
                PollingCompany          = "@Interpolation",
                PublicationDate         = interpolatedDate,
                ConstituencyPredictions = constituencyPredictions,
                ListPredictions         = listPredictions
            };

            return(interpolationPoll);
        }