Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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 = new Dictionary <DateTime, DateTime>();

            foreach (var book in BooksRead)
            {
                if (!bookReadDates.ContainsKey(book.Date))
                {
                    TimeSpan ts = book.Date - startDate;
                    if (ts.Days >= 90)
                    {
                        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())
            {
                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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TalliedMonth" /> class.
        /// This constructor captures the selection rectangle for printing a region.
        /// </summary>
        /// <param name="date">The owning document view model.</param>
        /// <param name="booksRead">The document name.</param>
        public TalliedMonth(DateTime date, List <BookRead> booksRead)
        {
            MonthDate      = date;
            BooksRead      = booksRead;
            DaysInTheMonth = DateTime.DaysInMonth(date.Year, date.Month);


            TotalBooks       = 0;
            TotalPagesRead   = 0;
            TotalBookFormat  = 0;
            TotalComicFormat = 0;
            TotalAudioFormat = 0;
            UInt32 totalInEnglish = 0;

            // Loop through the books updating the counts as we go.
            foreach (BookRead book in BooksRead)
            {
                TotalBooks++;
                TotalPagesRead += book.Pages;

                if (book.Format == BookFormat.Book)
                {
                    TotalBookFormat++;
                }

                if (book.Format == BookFormat.Comic)
                {
                    TotalComicFormat++;
                }

                if (book.Format == BookFormat.Audio)
                {
                    TotalAudioFormat++;
                }

                if (book.OriginalLanguage == "English")
                {
                    totalInEnglish++;
                }
            }

            // Finally get the percentage read in English.
            PercentageInEnglish = BooksDelta.GetAsPercentage(TotalBooks, totalInEnglish);
        }