Example #1
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Current Month Pages Read by Author Nationality", TitlePadding = 15
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Current Month Pages Read by Author Nationality");

            Dictionary <string, int> pagesPerCountry = new Dictionary <string, int>();

            foreach (var book in BooksReadProvider.SelectedMonthTally.BooksRead)
            {
                if (pagesPerCountry.ContainsKey(book.Nationality))
                {
                    pagesPerCountry[book.Nationality] += book.Pages;
                }
                else
                {
                    pagesPerCountry.Add(book.Nationality, book.Pages);
                }
            }

            List <KeyValuePair <string, int> > sortedCountryTotals = pagesPerCountry.OrderByDescending(x => x.Value).ToList();

            return(OxyPlotUtilities.CreatePieSeriesModelForResultsSet(
                       sortedCountryTotals, "Current Month Pages Read by Author Nationality", 128));
        }
Example #2
0
        private PlotModel SetupOverallBookAndPageTalliesPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Overall Book And Pages Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Overall Book And Pages Plot");
            SetupOverallBookAndPagesVsTimeAxes(newPlot);

            // create series and add them to the plot
            LineSeries booksReadSeries;
            LineSeries booksReadTrendlineSeries;

            OxyPlotUtilities.CreateLineSeries(out booksReadSeries, ChartAxisKeys.DateKey, ChartAxisKeys.BooksReadKey, "Total Books Read", 1);
            OxyPlotUtilities.CreateLineSeries(out booksReadTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.BooksReadKey, "Books Read Trendline", 4);
            double yinterceptBooks;
            double slopeBooks;

            GetBooksLinearTrendlineParameters(out yinterceptBooks, out slopeBooks);


            LineSeries pagesReadSeries;
            LineSeries pagesReadTrendlineSeries;

            OxyPlotUtilities.CreateLineSeries(out pagesReadSeries, ChartAxisKeys.DateKey, ChartAxisKeys.PagesReadKey, "Total Pages Read", 0);
            OxyPlotUtilities.CreateLineSeries(out pagesReadTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.PagesReadKey, "Pages Read Trendline", 3
                                              );
            double yinterceptPages;
            double slopePages;

            GetPagesLinearTrendlineParameters(out yinterceptPages, out slopePages);


            foreach (var delta in _mainModel.BookDeltas)
            {
                double trendBooks = yinterceptBooks + (slopeBooks * delta.DaysSinceStart);
                double trendPages = yinterceptPages + (slopePages * delta.DaysSinceStart);

                booksReadSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.OverallTally.TotalBooks));
                booksReadTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendBooks));

                pagesReadSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.OverallTally.TotalPages));
                pagesReadTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendPages));
            }


            OxyPlotUtilities.AddLineSeriesToModel(newPlot,
                                                  new LineSeries[] { booksReadSeries, booksReadTrendlineSeries,
                                                                     pagesReadSeries, pagesReadTrendlineSeries }
                                                  );


            // finally update the model with the new plot
            return(newPlot);
        }
        private static void AddLineSeriesForMonthlyTallies(PlotModel newPlot, 
            Dictionary<int, List<MonthOfYearTally>> bookListsByMonthOfYear)
        {
            int colourIndex = 1;
            var colours = OxyPlotUtilities.SetupStandardColourSet();
            foreach (var year in bookListsByMonthOfYear.Keys.ToList().OrderBy(x => x))
            {
                LineSeries booksReadSeries;
                LineSeries pagesReadSeries;
                GetBooksAndPagesReadLineSeries(colourIndex, colours, year, out booksReadSeries, out pagesReadSeries);

                // add the points for the days of this year
                foreach (var tally in bookListsByMonthOfYear[year])
                {
                    booksReadSeries.Points.Add(
                        new DataPoint(tally.MonthOfYear, tally.BooksReadThisMonth));
                    pagesReadSeries.Points.Add(
                        new DataPoint(tally.MonthOfYear, tally.PagesReadThisMonth));
                }

                // then add them to the model
                OxyPlotUtilities.AddLineSeriesToModel(newPlot, new[] { booksReadSeries, pagesReadSeries });
                colourIndex++;
            }
        }
Example #4
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Percentage Books Read by Country With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Percentage Books Read by Country With Time Plot");
            SetupPercentageBooksReadKeyVsTimeAxes(newPlot);

            // get the countries (in order)
            BooksDelta.DeltaTally latestTally = BooksReadProvider.BookDeltas.Last().OverallTally;
            List <string>         countries   = (from item in latestTally.CountryTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > countriesSeries =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < countries.Count; i++)
            {
                LineSeries countrySeries;
                OxyPlotUtilities.CreateLongLineSeries(
                    out countrySeries,
                    ChartAxisKeys.DateKey,
                    ChartAxisKeys.PercentageBooksReadKey,
                    countries[i],
                    i);
                countriesSeries.Add(new KeyValuePair <string, LineSeries>(countries[i], countrySeries));
            }

            // loop through the deltas adding points for each of the items
            foreach (BooksDelta delta in BooksReadProvider.BookDeltas)
            {
                double date = DateTimeAxis.ToDouble(delta.Date);
                foreach (KeyValuePair <string, LineSeries> countryLine in countriesSeries)
                {
                    double percentage = 0.0;
                    foreach (Tuple <string, uint, double, uint, double> countryTotal in delta.OverallTally.CountryTotals)
                    {
                        if (countryTotal.Item1 == countryLine.Key)
                        {
                            percentage = countryTotal.Item3;
                        }
                    }

                    countryLine.Value.Points.Add(new DataPoint(date, percentage));
                }
            }

            // add them to the plot
            foreach (KeyValuePair <string, LineSeries> countryItems in countriesSeries)
            {
                newPlot.Series.Add(countryItems.Value);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Total Books Read by Language With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Total Books Read by Language With Time Plot");
            SetupTotalBooksReadKeyVsTimeAxes(newPlot);

            // get the languages (in order)
            BooksDelta.DeltaTally latestTally = BooksReadProvider.BookDeltas.Last().OverallTally;
            List <string>         countries   = (from item in latestTally.CountryTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > lineSeriesSet =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < countries.Count; i++)
            {
                LineSeries series;
                OxyPlotUtilities.CreateLongLineSeries(out series,
                                                      ChartAxisKeys.DateKey, ChartAxisKeys.TotalBooksReadKey, countries[i], i, 128);
                lineSeriesSet.Add(
                    new KeyValuePair <string, LineSeries>(countries[i], series));
            }

            // loop through the deltas adding points for each of the items to the lines
            foreach (var delta in BooksReadProvider.BookDeltas)
            {
                var date = DateTimeAxis.ToDouble(delta.Date);
                foreach (var line in lineSeriesSet)
                {
                    double ttl = 0.0;
                    foreach (var langTotal in delta.OverallTally.CountryTotals)
                    {
                        if (langTotal.Item1 == line.Key)
                        {
                            ttl = langTotal.Item2;
                        }
                    }
                    line.Value.Points.Add(new DataPoint(date, ttl));
                }
            }

            IList <LineSeries> lineSeries =
                (from item in lineSeriesSet select item.Value).ToList();
            var stackSeries = OxyPlotUtilities.StackLineSeries(lineSeries);

            // add them to the plot
            foreach (var areaSeries in stackSeries)
            {
                newPlot.Series.Add(areaSeries);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
        private PlotModel SetupCurrentPagesReadByCountryPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Current Month Pages Read By Language"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Current Month Pages Read By Language");

            Dictionary <string, int> pagesPerLanguage = new Dictionary <string, int>();

            foreach (var book in _mainModel.SelectedMonthTally.BooksRead)
            {
                if (pagesPerLanguage.ContainsKey(book.OriginalLanguage))
                {
                    pagesPerLanguage[book.OriginalLanguage] += book.Pages;
                }
                else
                {
                    pagesPerLanguage.Add(book.OriginalLanguage, book.Pages);
                }
            }

            var sortedCountryTotals = pagesPerLanguage.OrderByDescending(x => x.Value).ToList();

            return(OxyPlotUtilities.CreatePieSeriesModelForResultsSet(
                       sortedCountryTotals, "Current Month Pages Read By Language", 128));
        }
Example #7
0
        private PlotModel SetupCountryLocationsBooksReadPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Countries in Location with Books Read Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Countries in Location with Books Read Plot");
            SetupLatitudeAndLongitudeAxes(newPlot);

            // create series and add them to the plot
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (var authorCountry in _mainModel.AuthorCountries)
            {
                var name    = authorCountry.Country;
                var country = _mainModel.WorldCountries.Where(w => w.Country == name).FirstOrDefault();
                if (country != null)
                {
                    var pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    ScatterPoint point =
                        new ScatterPoint(country.Longitude, country.Latitude, pointSize,
                                         authorCountry.TotalBooksReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }

            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotal Books {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (var color in OxyPalettes.Jet(200).Colors)
            {
                var faintColor = OxyColor.FromArgb(128, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read"
            });

            return(newPlot);
        }
        private PlotModel SetupPercentageBooksReadByLanguagePlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Percentage Books Read by Language With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Percentage Books Read by Language With Time Plot");
            SetupPercentageBooksReadKeyVsTimeAxes(newPlot);

            // get the languages (in order)
            BooksDelta.DeltaTally latestTally = _mainModel.BookDeltas.Last().OverallTally;
            List <string>         languages   = (from item in latestTally.LanguageTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > languagesSeries =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < languages.Count; i++)
            {
                LineSeries languageSeries;
                OxyPlotUtilities.CreateLongLineSeries(out languageSeries,
                                                      ChartAxisKeys.DateKey, ChartAxisKeys.PercentageBooksReadKey, languages[i], i);
                languagesSeries.Add(
                    new KeyValuePair <string, LineSeries>(languages[i], languageSeries));
            }

            // loop through the deltas adding points for each of the items
            foreach (var delta in _mainModel.BookDeltas)
            {
                var date = DateTimeAxis.ToDouble(delta.Date);
                foreach (var languageLine in languagesSeries)
                {
                    double percentage = 0.0;
                    foreach (var langTotal in delta.OverallTally.LanguageTotals)
                    {
                        if (langTotal.Item1 == languageLine.Key)
                        {
                            percentage = langTotal.Item3;
                        }
                    }
                    languageLine.Value.Points.Add(new DataPoint(date, percentage));
                }
            }

            // add them to the plot
            foreach (var languagesItems in languagesSeries)
            {
                newPlot.Series.Add(languagesItems.Value);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
Example #9
0
        public override void UpdateModel(ref PlotModel newPlot)
        {
            OxyPlotUtilities.SetupPlotLegend(newPlot, PlotTitle);
            SetupTotalSeatsVsTimeAxes(newPlot);

            // if no data stop
            if (ElectionPredictions?.PollingPredictions == null ||
                !ElectionPredictions.PollingPredictions.Any())
            {
                return;
            }

            // Get the polls by date.
            List <KeyValuePair <DateTime, PartyPrediction> > pollValues =
                GetPartyPredictionsByDate();

            // Get the party names.
            string[] partiesNames = PartyPrediction.PartiesList;

            // Add a line and a scatter series per party
            List <KeyValuePair <string, LineSeries> > partiesLineSeries =
                new List <KeyValuePair <string, LineSeries> >();

            SetupPartiesSeries(partiesNames, partiesLineSeries);

            // loop through the polls adding points for each of the items to the lines
            AddValuesToSeries(pollValues, partiesLineSeries);

            // Get the area stack series
            IEnumerable <AreaSeries> stackedSeatsSeries =
                OxyPlotUtilities.StackLineSeries(partiesLineSeries.Select(x => x.Value).ToList());

            // add them to the plot
            foreach (AreaSeries series in stackedSeatsSeries)
            {
                newPlot.Series.Add(series);
            }

            // add a line annotation
            double X = 5D;
            double Y = 65D;

            LineAnnotation lineAnnotation = new LineAnnotation()
            {
                StrokeThickness = 3,
                Color           = OxyColors.Crimson,
                Type            = LineAnnotationType.Horizontal,
                Text            = "Majority",
                TextColor       = OxyColors.Crimson,
                X = X,
                Y = Y
            };

            newPlot.Annotations.Add(lineAnnotation);
        }
Example #10
0
        private PlotModel SetupAverageDaysPerBookPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Average Days Per Book Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Average Days Per Book Plot");
            SetupDaysPerBookVsTimeAxes(newPlot);

            // create series and add them to the plot
            LineSeries overallSeries;
            LineSeries lastTenSeries;
            LineSeries overallTrendlineSeries;
            LineSeries lastTenTrendlineSeries;

            OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.DateKey, ChartAxisKeys.DaysPerBookKey, "Overall", 1);
            OxyPlotUtilities.CreateLineSeries(out overallTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.DaysPerBookKey, "Overall Trendline", 4);
            OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.DateKey, ChartAxisKeys.DaysPerBookKey, "Last 10", 0);
            OxyPlotUtilities.CreateLineSeries(out lastTenTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.DaysPerBookKey, "Last 10 Trendline", 3);

            ICurveFitter lastTenCurveFitter;
            ICurveFitter overallCurveFitter;

            GetAverageDaysPerBookCurveFitters(out lastTenCurveFitter, out overallCurveFitter);


            foreach (var delta in _mainModel.BookDeltas)
            {
                double trendOverallDaysPerBook =
                    overallCurveFitter.EvaluateYValueAtPoint(delta.DaysSinceStart);
                double trendLastTenDaysPerBook =
                    lastTenCurveFitter.EvaluateYValueAtPoint(delta.DaysSinceStart);

                overallSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.OverallTally.DaysPerBook));
                lastTenSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.LastTenTally.DaysPerBook));

                overallTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendOverallDaysPerBook));
                lastTenTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendLastTenDaysPerBook));
            }


            OxyPlotUtilities.AddLineSeriesToModel(newPlot,
                                                  new LineSeries[] { overallSeries, lastTenSeries, overallTrendlineSeries, lastTenTrendlineSeries }
                                                  );


            // finally update the model with the new plot
            return(newPlot);
        }
        private void AddBooksAndPagesScatterSeries(PlotModel newPlot)
        {
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries)
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    int pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    PolygonPoint latLong = new PolygonPoint()
                    {
                        Latitude = country.Latitude, Longitude = country.Longitude
                    };
                    double x, y;
                    latLong.GetCoordinates(out x, out y);

                    ScatterPoint point =
                        new ScatterPoint(x, y, pointSize,
                                         authorCountry.TotalPagesReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }
            pointsSeries.RenderInLegend      = false;
            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotalPages {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (OxyColor color in OxyPalettes.Jet(200).Colors)
            {
                OxyColor faintColor = OxyColor.FromArgb(128, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Total Pages"
            });
        }
Example #12
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Countries in Location with Books Read Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Countries in Location with Books Read Plot");
            SetupLatitudeAndLongitudeAxes(newPlot);

            // create series and add them to the plot
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries)
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    var pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    ScatterPoint point =
                        new ScatterPoint(country.Longitude, country.Latitude, pointSize,
                                         authorCountry.TotalBooksReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }

            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotal Books {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors =
                OxyPalettes.Jet(200).Colors.Select(color => OxyColor.FromArgb(128, color.R, color.G, color.B)).ToList();

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read"
            });

            return(newPlot);
        }
Example #13
0
        private PlotModel SetupBooksAndPagesLastTenPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Last 10 Books Time vs Pages Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Last 10 Books Time vs Pages Plot");
            SetupPagesPerDayWithTimeVsTimeAxes(newPlot);

            // create series and add them to the plot
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.DaysTakenKey, ChartAxisKeys.TotalPagesReadKey, "Time Taken Vs Pages");

            List <BooksDelta> deltasSet = new List <BooksDelta>();

            foreach (var delta in _mainModel.BookDeltas)
            {
                deltasSet.Add(delta);
                if (deltasSet.Count < 10)
                {
                    continue;
                }

                BooksDelta end = deltasSet.Last();

                double daysTaken = end.LastTenTally.DaysInTally;
                double pagesRead = end.LastTenTally.TotalPages;

                double translated = end.LastTenTally.PercentageInTranslation;

                ScatterPoint point =
                    new ScatterPoint(daysTaken, pagesRead, 5, translated)
                {
                    Tag = end.Date.ToString("ddd d MMM yyy")
                };
                pointsSeries.Points.Add(point);

                deltasSet.RemoveAt(0);
            }
            pointsSeries.TrackerFormatString = "{Tag}\n{1}: {2:0.###}\n{3}: {4:0.###}\nTranslated % {6}";
            newPlot.Series.Add(pointsSeries);
            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = OxyPalettes.Jet(200), Title = "Percentage Translated"
            });

            // finally update the model with the new plot
            return(newPlot);
        }
Example #14
0
        public override void UpdateModel(ref PlotModel newPlot)
        {
            OxyPlotUtilities.SetupPlotLegend(newPlot, PlotTitle);
            SetupListVotesVsTimeAxes(newPlot);

            // if no data stop
            if (PollingPredictions == null || !PollingPredictions.Any())
            {
                return;
            }

            // Get the data vales by date.
            List <KeyValuePair <DateTime, PartyPrediction> > pollValues =
                GetPartyPredictionsByDate();

            List <KeyValuePair <DateTime, PartyPrediction> > interpolationValues =
                GetPartyPredictionsByDate(false);

            // Get the party names.
            string[] partiesNames = PartyPrediction.PartiesList;

            // Add a line and a scatter series per party
            List <KeyValuePair <string, LineSeries> > partiesLineSeries =
                new List <KeyValuePair <string, LineSeries> >();
            List <KeyValuePair <string, LineSeries> > partiesLineInterpolationSeries =
                new List <KeyValuePair <string, LineSeries> >();
            List <KeyValuePair <string, ScatterSeries> > partiesScatterSeries =
                new List <KeyValuePair <string, ScatterSeries> >();

            SetupPartiesSeries(partiesNames, partiesLineSeries, partiesScatterSeries);
            SetupPartiesLineSeries(partiesNames, partiesLineInterpolationSeries);

            // loop through the polls adding points for each of the items to the lines
            AddPercentageValuesToSeries(pollValues, partiesLineSeries, partiesScatterSeries);
            AddPercentageValuesToSeries(interpolationValues, partiesLineInterpolationSeries);

            // add the series to the plot
            foreach (KeyValuePair <string, LineSeries> partyLines in partiesLineInterpolationSeries)
            {
                newPlot.Series.Add(partyLines.Value);
            }

            //foreach (KeyValuePair<string, LineSeries> partyLines in partiesLineSeries)
            //{
            //    newPlot.Series.Add(partyLines.Value);
            //}

            foreach (KeyValuePair <string, ScatterSeries> partyScatters in partiesScatterSeries)
            {
                newPlot.Series.Add(partyScatters.Value);
            }
        }
        private void GetPageRateLinearTrendlineParameters(out double yintercept, out double slope)
        {
            double rsquared;

            List <double> overallDays     = new List <double>();
            List <double> overallPageRate = new List <double>();

            foreach (var delta in _mainModel.BookDeltas)
            {
                overallDays.Add(delta.DaysSinceStart);
                overallPageRate.Add(delta.OverallTally.PageRate);
            }
            OxyPlotUtilities.LinearRegression(overallDays, overallPageRate, out rsquared, out yintercept, out slope);
        }
Example #16
0
        private void GetDaysPerBookLinearTrendlineParameters(out double yintercept, out double slope)
        {
            double rsquared;

            List <double> overallDays        = new List <double>();
            List <double> overallDaysPerBook = new List <double>();

            foreach (var delta in BooksReadProvider.BookDeltas)
            {
                overallDays.Add(delta.DaysSinceStart);
                overallDaysPerBook.Add(delta.OverallTally.DaysPerBook);
            }
            OxyPlotUtilities.LinearRegression(overallDays, overallDaysPerBook, out rsquared, out yintercept, out slope);
        }
        private void GetLongitudeLinearTrendlineParameters(out double yintercept, out double slope)
        {
            double rsquared;

            List <double> overallDays      = new List <double>();
            List <double> overallLongitude = new List <double>();

            foreach (var delta in _mainModel.BookLocationDeltas)
            {
                overallDays.Add(delta.DaysSinceStart);
                overallLongitude.Add(delta.AverageLongitudeLastTen);
            }
            OxyPlotUtilities.LinearRegression(overallDays, overallLongitude, out rsquared, out yintercept, out slope);
        }
Example #18
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Countries in Location with Books and Pages Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Countries in Location with Books and Pages Plot");
            SetupLatitudeAndLongitudeAxes(newPlot);

            // create series and add them to the plot
            AddBooksAndPagesScatterSeries(newPlot);

            return(newPlot);
        }
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Current Books Read by Country"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Current Books Read by Country");

            List <KeyValuePair <string, int> > sortedCountryTotals =
                BookTotalsUtilities.SortedSortedBooksReadByCountryTotals(BooksReadProvider);

            return(OxyPlotUtilities.CreatePieSeriesModelForResultsSet(
                       sortedCountryTotals, "Current Books Read by Country", 128));
        }
        private static void GetBooksAndPagesReadLineSeries(int colourIndex, List <OxyColor> colours, int year,
                                                           out LineSeries booksReadSeries, out LineSeries pagesReadSeries)
        {
            var colour = colours[colourIndex];

            OxyPlotUtilities.CreateLineSeries(out booksReadSeries, ChartAxisKeys.DayOfYearKey,
                                              ChartAxisKeys.BooksReadKey, "Total Books Read in " + year.ToString(), colourIndex);
            booksReadSeries.StrokeThickness++;
            booksReadSeries.Color = colour;

            OxyPlotUtilities.CreateLineSeries(out pagesReadSeries, ChartAxisKeys.DayOfYearKey,
                                              ChartAxisKeys.PagesReadKey, "Total Pages Read in " + year.ToString(), colourIndex);
            pagesReadSeries.LineStyle = LineStyle.Dash;
            pagesReadSeries.Color     = colour;
        }
Example #21
0
        private void AddBooksAndPagesScatterSeries(PlotModel newPlot)
        {
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (var authorCountry in _mainModel.AuthorCountries)
            {
                var name    = authorCountry.Country;
                var country = _mainModel.WorldCountries.Where(w => w.Country == name).FirstOrDefault();
                if (country != null)
                {
                    var pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    ScatterPoint point =
                        new ScatterPoint(country.Longitude, country.Latitude, pointSize,
                                         authorCountry.TotalPagesReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }

            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotalPages {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (var color in OxyPalettes.Jet(200).Colors)
            {
                var faintColor = OxyColor.FromArgb(128, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Total Pages"
            });
        }
        private void SetupPagesByCountryModel()
        {
            Model3DGroup modelGroup = new Model3DGroup();

            // get the range of colours for the for the countries

            // set up lookups of the countries with numbers read
            int maxBooksPages;
            int maxBooksLogPages;
            Dictionary <string, long> countryToReadLookUp;
            Dictionary <string, uint> countryToPagesLookUp;
            Dictionary <string, uint> countryToLogPagesLookUp;

            SetupCountyPagesLookups(out maxBooksPages, out maxBooksLogPages,
                                    out countryToReadLookUp, out countryToPagesLookUp, out countryToLogPagesLookUp);
            _countryToLogPagesLookUp = countryToLogPagesLookUp;

            // set up a palette based on this
            List <OxyColor> colors;
            OxyPalette      faintPalette;
            uint            numColours = 1 + countryToLogPagesLookUp.Values.OrderByDescending(x => x).FirstOrDefault();

            OxyPlotUtilities.SetupFaintPaletteForRange((int)numColours, out colors, out faintPalette, 128);

            List <OxyColor> stdColors      = OxyPlotUtilities.SetupStandardColourSet();
            int             geographyIndex = 0;

            foreach (var authorCountry in _mainModel.AuthorCountries.OrderByDescending(x => x.TotalBooksReadFromCountry))
            {
                var name    = authorCountry.Country;
                var country = _mainModel.Nations.Where(w => w.Name == name).FirstOrDefault();
                if (country != null)
                {
                    AddNationPagesPins(modelGroup, colors, authorCountry, name, country);
                }

                if (_mainModel.Nations != null && _mainModel.Nations.Count > 0)
                {
                    geographyIndex = AddNationsCountryGeographyPlane(modelGroup, stdColors, geographyIndex, name);
                }
            }

            AddGeographiesForNationsWithoutBooksRead(modelGroup);

            PagesByCountryModel = modelGroup;
        }
Example #23
0
        private PlotModel SetupCurrentBooksReadByCountryPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Current Books Read by Country"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Current Books Read by Country");

            var currentResults = _mainModel.BookDeltas.Last();

            List <KeyValuePair <string, int> > countryTotals = new List <KeyValuePair <string, int> >();

            // Country, ttl books, ttl books %, ttl pages, ttl pages%
            //Tuple<string, UInt32, double, UInt32, double>

            int    ttlOtherBooks      = 0;
            double ttlOtherPercentage = 0;

            foreach (var country in currentResults.OverallTally.CountryTotals)
            {
                string countryName       = country.Item1;
                int    ttlBooks          = (int)country.Item2;
                double countryPercentage = country.Item3;
                if (countryPercentage > 1.0)
                {
                    countryTotals.Add(new KeyValuePair <string, int>(countryName, ttlBooks));
                }
                else
                {
                    ttlOtherPercentage += countryPercentage;
                    ttlOtherBooks      += ttlBooks;
                }
            }

            var sortedCountryTotals = countryTotals.OrderByDescending(x => x.Value).ToList();

            if (ttlOtherPercentage > 1.0)
            {
                sortedCountryTotals.Add(new KeyValuePair <string, int>("Other", ttlOtherBooks));
            }

            return(OxyPlotUtilities.CreatePieSeriesModelForResultsSet(
                       sortedCountryTotals, "Current Books Read by Country", 128));
        }
        private PlotModel SetupPagesPerBookPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Pages Per Book Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Pages Per Book Plot");
            SetupPagesPerBookVsTimeAxes(newPlot);

            // create series and add them to the plot
            LineSeries overallSeries;
            LineSeries lastTenSeries;
            LineSeries overallTrendlineSeries;

            OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.DateKey, ChartAxisKeys.PagesPerBookKey, "Overall", 1);
            OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.DateKey, ChartAxisKeys.PagesPerBookKey, "Last 10", 0);
            OxyPlotUtilities.CreateLineSeries(out overallTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.PagesPerBookKey, "Overall Trendline", 4);

            double yintercept;
            double slope;

            GetPagesPerBookLinearTrendlineParameters(out yintercept, out slope);

            foreach (var delta in _mainModel.BookDeltas)
            {
                double trendPageRate = yintercept + (slope * delta.DaysSinceStart);

                overallSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.OverallTally.PagesPerBook));
                lastTenSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.LastTenTally.PagesPerBook));
                overallTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendPageRate));
            }


            OxyPlotUtilities.AddLineSeriesToModel(newPlot,
                                                  new LineSeries[] { overallSeries, lastTenSeries, overallTrendlineSeries }
                                                  );


            // finally update the model with the new plot
            return(newPlot);
        }
Example #25
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "% Books In Translation"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "% Books In Translation");
            SetupBooksInTranslationVsTimeAxes(newPlot);

            // create series and add them to the plot
            LineSeries overallSeries;
            LineSeries lastTenSeries;
            LineSeries overallTrendlineSeries;

            OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.DateKey, ChartAxisKeys.BooksInTranslationKey, "Overall", 1);
            OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.DateKey, ChartAxisKeys.BooksInTranslationKey, "Last 10", 0);
            OxyPlotUtilities.CreateLineSeries(out overallTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.BooksInTranslationKey, "Overall Trendline", 4);
            double yintercept;
            double slope;

            GetBooksInTranslationLinearTrendlineParameters(out yintercept, out slope);


            foreach (var delta in BooksReadProvider.BookDeltas)
            {
                double trendDaysPerBook = yintercept + (slope * delta.DaysSinceStart);

                overallSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.OverallTally.PercentageInTranslation));
                lastTenSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.LastTenTally.PercentageInTranslation));
                overallTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendDaysPerBook));
            }


            OxyPlotUtilities.AddLineSeriesToModel(newPlot,
                                                  new[] { overallSeries, lastTenSeries, overallTrendlineSeries }
                                                  );


            // finally update the model with the new plot
            return(newPlot);
        }
        private void AddColumnSeriesForMonthlyTallies(PlotModel newPlot,
                                                      Dictionary <int, List <MonthOfYearTally> > bookListsByMonthOfYear)
        {
            int colourIndex = 1;
            var colours     = OxyPlotUtilities.SetupStandardColourSet();

            foreach (var year in bookListsByMonthOfYear.Keys.ToList().OrderBy(x => x))
            {
                int    index  = colourIndex % colours.Count;
                var    colour = colours[index];
                string title  = (_chartType == ChartType.PagesAsColumns)
                    ? "Pages read in " + year.ToString()
                    : "Books read in " + year.ToString();

                var yKey = (_chartType == ChartType.PagesAsColumns)
                    ? ChartAxisKeys.PagesReadKey
                    : ChartAxisKeys.BooksReadKey;

                ColumnSeries booksReadSeries = new ColumnSeries
                {
                    Title       = title,
                    XAxisKey    = ChartAxisKeys.MonthOfYearKey,
                    YAxisKey    = yKey,
                    FillColor   = colour,
                    ColumnWidth = 13,
                };

                var monthTallies = bookListsByMonthOfYear[year];
                foreach (var monthTally in monthTallies)
                {
                    booksReadSeries.Items.Add(
                        new ColumnItem()
                    {
                        CategoryIndex = monthTally.MonthOfYear - 1,
                        Value         = (_chartType == ChartType.PagesAsColumns)
                                ? monthTally.PagesReadThisMonth
                                : monthTally.BooksReadThisMonth
                    });
                }

                newPlot.Series.Add(booksReadSeries);
                colourIndex++;
            }
        }
        private static void AddCountryGeographyToPlot(
            PlotModel newPlot,
            Dictionary <string, int> countryToReadLookUp,
            List <OxyColor> colors,
            Models.Geography.CountryGeography country)
        {
            OxyColor color     = OxyColors.LightGray;
            string   tagString = "";

            if (countryToReadLookUp.ContainsKey(country.Name))
            {
                color     = colors[countryToReadLookUp[country.Name]];
                tagString = "\nBooks Read = " + countryToReadLookUp[country.Name].ToString();
            }

            string trackerFormat = "{0}\nLat/Long ( {4:0.###} ,{2:0.###} )" + tagString;

            OxyPlotUtilities.AddCountryGeographyAreaSeriesToPlot(newPlot, country, color, country.Name, tagString, trackerFormat);
        }
Example #28
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Longitude With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Longitude With Time Plot");
            SetupLongitudeVsTimeAxes(newPlot);

            // create series and add them to the plot
            LineSeries overallSeries;
            LineSeries lastTenSeries;
            LineSeries overallTrendlineSeries;

            OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.DateKey, ChartAxisKeys.LongitudeKey, "Overall", 1);
            OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.DateKey, ChartAxisKeys.LongitudeKey, "Last 10", 0);
            OxyPlotUtilities.CreateLineSeries(out overallTrendlineSeries, ChartAxisKeys.DateKey, ChartAxisKeys.LongitudeKey, "Overall Trendline", 4);

            double yintercept;
            double slope;

            GetLongitudeLinearTrendlineParameters(out yintercept, out slope);

            foreach (var delta in BooksReadProvider.BookLocationDeltas)
            {
                double trendPageRate = yintercept + (slope * delta.DaysSinceStart);

                overallSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.AverageLongitude));
                lastTenSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), delta.AverageLongitudeLastTen));
                overallTrendlineSeries.Points.Add(
                    new DataPoint(DateTimeAxis.ToDouble(delta.Date), trendPageRate));
            }


            OxyPlotUtilities.AddLineSeriesToModel(newPlot, new[] { overallSeries, lastTenSeries, overallTrendlineSeries });


            // finally update the model with the new plot
            return(newPlot);
        }
        private PlotModel SetupWorldCountriesMapPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Countries of the World and Books Read"
            };

            SetupLatitudeAndLongitudeAxes(newPlot);

            // make up a lit of the countries with books read
            int maxBooksRead = -1;
            Dictionary <string, int> countryToReadLookUp = new Dictionary <string, int>();

            foreach (var authorCountry in _mainModel.AuthorCountries)
            {
                maxBooksRead = Math.Max(authorCountry.TotalBooksReadFromCountry, maxBooksRead);
                countryToReadLookUp.Add(authorCountry.Country, authorCountry.TotalBooksReadFromCountry);
            }
            List <OxyColor> colors;
            OxyPalette      faintPalette;

            maxBooksRead =
                OxyPlotUtilities.SetupFaintPaletteForRange(maxBooksRead, out colors, out faintPalette, 128);

            foreach (Models.Database.Nation nation in _mainModel.Nations)
            {
                Models.Geography.CountryGeography country = nation.Geography;
                if (country != null)
                {
                    AddCountryGeographyToPlot(newPlot, countryToReadLookUp, colors, country);
                }
            }

            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read", Maximum = maxBooksRead, Minimum = 0
            });

            // finally update the model with the new plot
            return(newPlot);
        }
        private PlotModel SetupTalliesPerCalendarYearPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Tallies Per Calendar Year Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Tallies Per Calendar Year Plot");
            SetupBookAndPagesVsDayOfYearAxes(newPlot);

            // get the books & pages read for each calendar year
            Dictionary <int, List <DayOfYearTally> > bookListsByDayandYear = GetBookListsByDayAndYear();

            // add a series for each year (in order)
            int colourIndex = 1;
            var colours     = OxyPlotUtilities.SetupStandardColourSet();

            foreach (var year in bookListsByDayandYear.Keys.ToList().OrderBy(x => x))
            {
                LineSeries booksReadSeries;
                LineSeries pagesReadSeries;
                GetBooksAndPagesReadLineSeries(colourIndex, colours, year, out booksReadSeries, out pagesReadSeries);

                // add the points for the days of this year
                foreach (var tally in bookListsByDayandYear[year])
                {
                    booksReadSeries.Points.Add(
                        new DataPoint(tally.DayOfYear, tally.BooksReadThisYearOnThisDay));
                    pagesReadSeries.Points.Add(
                        new DataPoint(tally.DayOfYear, tally.PagesReadThisYearOnThisDay));
                }

                // then add them to the model
                OxyPlotUtilities.AddLineSeriesToModel(newPlot, new
                                                      LineSeries[] { booksReadSeries, pagesReadSeries });
                colourIndex++;
            }

            // finally update the model with the new plot
            return(newPlot);
        }