private void UpdateBookDeltas()
        {
            // clear the list and the counts
            BookDeltas.Clear();
            if (BooksRead.Count < 1)
            {
                return;
            }
            DateTime startDate = BooksRead[0].Date;

            // get all the dates a book has been read (after the first quarter)
            Dictionary <DateTime, DateTime> bookReadDates = GetBookReadDates(startDate);

            // then add the delta made up of the books up to that date
            foreach (var date in bookReadDates.Keys.ToList())
            {
                BooksDelta delta = new BooksDelta(date, startDate);
                foreach (var book in BooksRead)
                {
                    if (book.Date <= date)
                    {
                        delta.BooksReadToDate.Add(book);
                    }
                    else
                    {
                        break;
                    }
                }
                delta.UpdateTallies();
                BookDeltas.Add(delta);
            }
        }
        public static List <KeyValuePair <string, int> > SortedSortedBooksReadByCountryTotals(IBooksReadProvider booksReadProvider)
        {
            BooksDelta currentResults = booksReadProvider.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 (Tuple <string, uint, double, uint, double> 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;
                }
            }

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

            if (ttlOtherPercentage > 1.0)
            {
                sortedCountryTotals.Add(new KeyValuePair <string, int>("Other", ttlOtherBooks));
            }
            return(sortedCountryTotals);
        }
        /// <summary>
        /// Sets up the scatter chart series.
        /// </summary>
        protected override void SetupSeries()
        {
            // If no books return the default.
            if (BooksReadProvider == null)
            {
                base.SetupSeries();
                return;
            }

            // Set up the empty series set and the color range.
            Series = new SeriesCollection();
            List <ISeriesView> seriesViews = new List <ISeriesView>();
            List <Color>       colors      = ColorUtilities.Jet(NumberOfColors);

            //       End date, daysTaken, pagesRead, translated
            List <Tuple <DateTime, double, double, double> > points = new List <Tuple <DateTime, double, double, double> >();

            // Set up the list of deltas with to add points for.
            List <BooksDelta> deltasSet = new List <BooksDelta>();

            foreach (BooksDelta delta in BooksReadProvider.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;

                points.Add(new Tuple <DateTime, double, double, double>(end.Date, daysTaken, pagesRead, translated));

                deltasSet.RemoveAt(0);
            }

            // Add a series per point.
            foreach (Tuple <DateTime, double, double, double> point in points)
            {
                Color         color       = GetPointColorForTranslatedRate(point.Item4, colors);
                ScatterSeries pointSeries =
                    CreateScatterSeries(
                        point.Item1.ToString("ddd d MMM yyy") + " % Translated = " + point.Item4.ToString("G3"),
                        point.Item2,
                        point.Item3,
                        color,
                        9);
                seriesViews.Add(pointSeries);
            }

            Series.AddRange(seriesViews);
            SeriesCollection = Series;
        }
        private void UpdateBookPerYearDeltas()
        {
            // clear the list and the counts
            BookPerYearDeltas.Clear();
            if (BooksRead.Count < 1)
            {
                return;
            }
            DateTime startDate = BooksRead[0].Date;

            startDate = startDate.AddYears(1);

            // get all the dates a book has been read that are at least a year since the start
            Dictionary <DateTime, DateTime> bookReadDates = new Dictionary <DateTime, DateTime>();

            foreach (var book in BooksRead)
            {
                if (startDate > book.Date)
                {
                    continue;
                }
                if (!bookReadDates.ContainsKey(book.Date))
                {
                    bookReadDates.Add(book.Date, book.Date);
                }
            }

            // then add the delta made up of the books up to that date
            foreach (var date in bookReadDates.Keys.ToList())
            {
                DateTime startYearDate = date;
                startYearDate = startYearDate.AddYears(-1);
                BooksDelta delta = new BooksDelta(date, startYearDate);
                foreach (var book in BooksRead)
                {
                    if (book.Date < startYearDate)
                    {
                        continue;
                    }

                    if (book.Date <= date)
                    {
                        delta.BooksReadToDate.Add(book);
                    }
                    else
                    {
                        break;
                    }
                }
                delta.UpdateTallies();
                BookPerYearDeltas.Add(delta);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public DeltaBooks(BooksDelta booksDelta)
        {
            Date           = booksDelta.Date;
            StartDate      = booksDelta.StartDate;
            DaysSinceStart = booksDelta.DaysSinceStart;
            OverallTally   = new TallyDelta(booksDelta.OverallTally);
            LastTenTally   = new TallyDelta(booksDelta.LastTenTally);

            int languageTotalsCount = booksDelta.OverallTally.LanguageTotals.Count;

            LanguageTotals = new CategoryTotal[languageTotalsCount];
            for (int i = 0; i < languageTotalsCount; i++)
            {
                var languageTotal = booksDelta.OverallTally.LanguageTotals[i];
                LanguageTotals[i] =
                    new CategoryTotal
                {
                    Name            = languageTotal.Item1,
                    TotalBooks      = (int)languageTotal.Item2,
                    PercentageBooks = (float)languageTotal.Item3,
                    TotalPages      = (int)languageTotal.Item4,
                    PercentagePages = (float)languageTotal.Item5
                };
            }


            int countryTotalsCount = booksDelta.OverallTally.CountryTotals.Count;

            CountryTotals = new CategoryTotal[countryTotalsCount];
            for (int i = 0; i < countryTotalsCount; i++)
            {
                var countryTotal = booksDelta.OverallTally.CountryTotals[i];
                CountryTotals[i] =
                    new CategoryTotal
                {
                    Name            = countryTotal.Item1,
                    TotalBooks      = (int)countryTotal.Item2,
                    PercentageBooks = (float)countryTotal.Item3,
                    TotalPages      = (int)countryTotal.Item4,
                    PercentagePages = (float)countryTotal.Item5
                };
            }
        }
Esempio n. 7
0
        private static void GetLanguageTotalsForDelta(BooksDelta delta, string language,
                                                      out UInt32 ttlBooks, out UInt32 ttlPages, out double pctBooks, out double pctPages)
        {
            ttlBooks = 0;
            ttlPages = 0;
            pctBooks = 0;
            pctPages = 0;

            foreach (var total in delta.OverallTally.LanguageTotals)
            {
                if (language != total.Item1)
                {
                    continue;
                }
                ttlBooks = total.Item2;
                pctBooks = total.Item3;
                ttlPages = total.Item4;
                pctPages = total.Item5;
                break;
            }
        }
        /// <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 = "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>();

            double minRate = 1e16;
            double maxRate = 0.0;

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

                BooksDelta end = deltasSet.Last();

                double daysTaken = end.LastTenTally.DaysInTally;
                double pagesRead = end.LastTenTally.TotalPages;
                if (daysTaken < 1.0)
                {
                    daysTaken = 1.0;
                }
                double       rate  = pagesRead / daysTaken;
                ScatterPoint point =
                    new ScatterPoint(daysTaken, pagesRead, 5, rate)
                {
                    Tag = end.Date.ToString("ddd d MMM yyy")
                };
                pointsSeries.Points.Add(point);

                if (minRate > rate)
                {
                    minRate = rate;
                }
                if (maxRate < rate)
                {
                    maxRate = rate;
                }

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

            // finally update the model with the new plot
            return(newPlot);
        }
        /// <summary>
        /// Sets up the scatter chart series.
        /// </summary>
        protected override void SetupSeries()
        {
            // If no books return the default.
            if (BooksReadProvider == null)
            {
                base.SetupSeries();
                return;
            }

            // Set up the empty series set and the color range.
            Series = new SeriesCollection();
            List <ISeriesView> seriesViews = new List <ISeriesView>();
            List <Color>       colors      = ColorUtilities.Jet(NumberOfColors);

            //       End date, daysTaken, pagesRead, days
            List <Tuple <DateTime, double, double, double> > points = new List <Tuple <DateTime, double, double, double> >();

            // Set up the list of deltas with to add points for and the range they lie between.
            List <BooksDelta> deltasSet = new List <BooksDelta>();
            double            minDays   = 1e16;
            double            maxDays   = 0.0;

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

                BooksDelta end = deltasSet.Last();

                double daysTaken = end.LastTenTally.DaysInTally;
                double pagesRead = end.LastTenTally.TotalPages;
                if (daysTaken < 1.0)
                {
                    daysTaken = 1.0;
                }

                double days = end.DaysSinceStart;

                points.Add(new Tuple <DateTime, double, double, double>(end.Date, daysTaken, pagesRead, days));

                if (minDays > days)
                {
                    minDays = days;
                }
                if (maxDays < days)
                {
                    maxDays = days;
                }

                deltasSet.RemoveAt(0);
            }

            // Add a series per point.
            foreach (Tuple <DateTime, double, double, double> point in points)
            {
                Color         color       = GetPointColorForDaysSinceStart(point.Item4, minDays, maxDays, colors);
                ScatterSeries pointSeries =
                    CreateScatterSeries(
                        point.Item1.ToString("ddd d MMM yyy") + " Days since start = " + ((int)(point.Item4)),
                        point.Item2,
                        point.Item3,
                        color,
                        9);
                seriesViews.Add(pointSeries);
            }

            Series.AddRange(seriesViews);
            SeriesCollection = Series;
        }