private void LoadAgeProbabilities()
        {
            PartyPrediction given1824   = new PartyPrediction();
            PartyPrediction given2549   = new PartyPrediction();
            PartyPrediction given5064   = new PartyPrediction();
            PartyPrediction given65Plus = new PartyPrediction();

            using (var reader = new StreamReader(pollingDataPath))
            {
                reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');

                    var party = (Party)Enum.Parse(typeof(Party), values[0]);

                    given1824.Add(party, int.Parse(values[10]));
                    given2549.Add(party, int.Parse(values[11]));
                    given5064.Add(party, int.Parse(values[12]));
                    given65Plus.Add(party, int.Parse(values[13]));
                }
            }

            AgeProbabilities.Add(AgeGroup.A1824, given1824);
            AgeProbabilities.Add(AgeGroup.A2549, given2549);
            AgeProbabilities.Add(AgeGroup.A5064, given5064);
            AgeProbabilities.Add(AgeGroup.A65Plus, given65Plus);
        }
        private void LoadRegionProbabilities()
        {
            PartyPrediction givenLondon   = new PartyPrediction();
            PartyPrediction givenSouth    = new PartyPrediction();
            PartyPrediction givenMidlands = new PartyPrediction();
            PartyPrediction givenNorth    = new PartyPrediction();
            PartyPrediction givenScotland = new PartyPrediction();

            using (var reader = new StreamReader(pollingDataPath))
            {
                reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');

                    var party = (Party)Enum.Parse(typeof(Party), values[0]);

                    if (!containsScotland)
                    {
                        givenLondon.Add(party, int.Parse(values[16]));
                        givenSouth.Add(party, int.Parse(values[17]));
                        givenMidlands.Add(party, int.Parse(values[18]));
                        givenNorth.Add(party, int.Parse(values[19]));
                    }
                    else
                    {
                        givenScotland.Add(party, int.Parse(values[20]));
                    }
                }
            }

            if (!containsScotland)
            {
                RegionProbabilities.Add(Region.London, givenLondon);
                RegionProbabilities.Add(Region.South, givenSouth);
                RegionProbabilities.Add(Region.MidlandsWales, givenMidlands);
                RegionProbabilities.Add(Region.North, givenNorth);
            }
            else
            {
                RegionProbabilities.Add(Region.Scotland, givenScotland);
            }
        }
Example #3
0
        private void AddValuesToSeries(
            List <KeyValuePair <DateTime, PartyPrediction> > pollValues,
            List <KeyValuePair <string, LineSeries> > partiesLineSeries)
        {
            foreach (KeyValuePair <DateTime, PartyPrediction> pollValuePair in pollValues)
            {
                double          date            = DateTimeAxis.ToDouble(pollValuePair.Key);
                PartyPrediction partyPrediction = pollValuePair.Value;

                for (int i = 0; i < partiesLineSeries.Count; i++)
                {
                    string key = partiesLineSeries[i].Key;

                    double percentage =
                        partyPrediction.GetPartyValue(key);

                    partiesLineSeries[i].Value.Points.Add(new DataPoint(date, percentage));
                }
            }
        }
Example #4
0
        public List <KeyValuePair <DateTime, PartyPrediction> > GetPartyPredictionsByDate(
            bool usePolling = true)
        {
            List <KeyValuePair <DateTime, PartyPrediction> > pollValues =
                new List <KeyValuePair <DateTime, PartyPrediction> >();

            List <PollingPrediction> predictions =
                usePolling ? PollingPredictions:InterpolatedPredictions;

            foreach (PollingPrediction prediction in predictions)
            {
                PartyPrediction partyPredictionValues = GetPartyPredictionValues(prediction);

                pollValues.Add(
                    new KeyValuePair <DateTime, PartyPrediction>(
                        prediction.PublicationDate, partyPredictionValues));
            }

            return(pollValues);
        }
        private void LoadPreviousVoteProbabilities()
        {
            PartyPrediction givenVotedCon17    = new PartyPrediction();
            PartyPrediction givenVotedLab17    = new PartyPrediction();
            PartyPrediction givenVotedLibDem17 = new PartyPrediction();
            PartyPrediction givenVotedOther17  = new PartyPrediction();

            using (var reader = new StreamReader(pollingDataPath))
            {
                reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');

                    var party = (Party)Enum.Parse(typeof(Party), values[0]);

                    givenVotedCon17.Add(party, int.Parse(values[4]));
                    givenVotedLab17.Add(party, int.Parse(values[5]));
                    givenVotedLibDem17.Add(party, int.Parse(values[6]));

                    if (!String.IsNullOrWhiteSpace(values[7]))
                    {
                        givenVotedOther17.Add(party, int.Parse(values[7]));
                    }
                }
            }

            PreviousElectionProbabilities.Add(Party.Con, givenVotedCon17);
            PreviousElectionProbabilities.Add(Party.Lab, givenVotedLab17);
            PreviousElectionProbabilities.Add(Party.LibDem, givenVotedLibDem17);

            if (containsScotland)
            {
                PreviousElectionProbabilities.Add(Party.SNP, givenVotedOther17);
            }
        }
        private void LoadGenderProbabilities()
        {
            PartyPrediction givenMale   = new PartyPrediction();
            PartyPrediction givenFemale = new PartyPrediction();

            using (var reader = new StreamReader(pollingDataPath))
            {
                reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');

                    var party = (Party)Enum.Parse(typeof(Party), values[0]);

                    givenMale.Add(party, int.Parse(values[8]));
                    givenFemale.Add(party, int.Parse(values[9]));
                }
            }

            GenderProbabilities.Add(Gender.Male, givenMale);
            GenderProbabilities.Add(Gender.Female, givenFemale);
        }
        private void LoadReferendumProbabilities()
        {
            PartyPrediction givenRemain = new PartyPrediction();
            PartyPrediction givenLeave  = new PartyPrediction();

            using (var reader = new StreamReader(pollingDataPath))
            {
                reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');

                    var party = (Party)Enum.Parse(typeof(Party), values[0]);

                    givenRemain.Add(party, int.Parse(values[2]));
                    givenLeave.Add(party, int.Parse(values[3]));
                }
            }

            ReferendumProbabilities.Add(ReferendumResult.Remain, givenRemain);
            ReferendumProbabilities.Add(ReferendumResult.Leave, givenLeave);
        }
        private void LoadSocialGradeProbabilies()
        {
            PartyPrediction givenABC1 = new PartyPrediction();
            PartyPrediction givenC2DE = new PartyPrediction();

            using (var reader = new StreamReader(pollingDataPath))
            {
                reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');

                    var party = (Party)Enum.Parse(typeof(Party), values[0]);

                    givenABC1.Add(party, int.Parse(values[14]));
                    givenC2DE.Add(party, int.Parse(values[15]));
                }
            }

            SocialGradeProbabilities.Add(SocialGrade.ABC1, givenABC1);
            SocialGradeProbabilities.Add(SocialGrade.C2DE, givenC2DE);
        }