Пример #1
0
 public void SetEventsStatistics()
 {
     lock (sr_CalculatingEventsContext)
     {
         EventsStatistics.SetStatistics(CurrentLoggedInUser.Instance.CurentUser.Events);
     }
 }
Пример #2
0
        public static void PrintStatistics(EventsStatistics statistics)
        {
            Console.WriteLine("\r{0}{1}", "Number of events:".PadRight(25, '.'), statistics.TotalNumberOfEvents);
            Console.WriteLine("{0}{1}", "Earliest event:".PadRight(25, '.'), statistics.FirstEvent);
            Console.WriteLine("{0}{1}", "Latest event:".PadRight(25, '.'), statistics.LastEvent);
            Console.WriteLine("{0}{1}", "Days since last event:".PadRight(25, '.'), statistics.DaysSinceLastEvent);

            Console.WriteLine("\nStatistics:");

            foreach (var year in statistics.NumberOfEventsPerYear)
            {
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine();
                Console.WriteLine(year.Key.ToString());
                Console.WriteLine();
                Console.ResetColor();

                foreach (var month in year.Value)
                {
                    Console.Write("{0}{1} ",
                        month.Key.PadRight(15, '.'),
                        month.Value.ToString().PadRight(2));

                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write(new string('-', month.Value));
                    Console.ResetColor();

                    Console.WriteLine();
                }

                Console.WriteLine();
            }
        }
Пример #3
0
        public EventsStatistics Create(List<Event> events)
        {
            var orderedEvents = events.OrderBy(ev => ev.Date);

            var statistics = new EventsStatistics
            {
                TotalNumberOfEvents = orderedEvents.Count(),
                FirstEvent = orderedEvents.FirstOrDefault(),
                LastEvent = orderedEvents.LastOrDefault(),
                DaysSinceLastEvent = (DateTime.Now.Date - orderedEvents.Last().Date).Days
            };

            var groupedByYear = orderedEvents.GroupBy(ev => ev.Date.Date.Year);

            foreach (var yearGroup in groupedByYear)
            {
                statistics.NumberOfEventsPerYear.Add(yearGroup.Key);

                var monthGroup = yearGroup.GroupBy(ev => ev.Date.Date.Month);
                foreach (var item in monthGroup)
                {
                    statistics.NumberOfEventsPerYear[yearGroup.Key].Add(
                        CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.Key),
                        item.Count());
                }
            }

            return statistics;
        }
Пример #4
0
        public void should_add_year_dictionary()
        {
            var target = new EventsStatistics();

            target.NumberOfEventsPerYear.Add(2012);

            Assert.NotNull(target.NumberOfEventsPerYear[2012]);
        }
Пример #5
0
        public string GetStatisticsMessage(List <bool> i_AlbumsFilters, List <bool> i_EventsFilters, List <bool> i_PostsFilters)
        {
            StringBuilder stillCalculatingSomeStatistics = new StringBuilder();
            StringBuilder statistics = new StringBuilder();

            if (isAtLeastOneFilterChecked(i_AlbumsFilters))
            {
                if (AlbumsStatistics.IsAlbumsStatsiticsCalculated)
                {
                    statistics.Append(AlbumsStatistics.GetAlbumsStatisticsString(i_AlbumsFilters));
                }
                else
                {
                    stillCalculatingSomeStatistics.Append("Still calculating albums statistics" + Environment.NewLine);
                }
            }

            if (isAtLeastOneFilterChecked(i_EventsFilters))
            {
                if (EventsStatistics.IsEventsStatsiticsCalculated)
                {
                    statistics.Append(EventsStatistics.GetEventsStatisticsString(i_EventsFilters));
                }
                else
                {
                    stillCalculatingSomeStatistics.Append("Still calculating events statistics" + Environment.NewLine);
                }
            }

            if (isAtLeastOneFilterChecked(i_PostsFilters))
            {
                if (PostsStatistics.IsPostsStatsiticsCalculated)
                {
                    statistics.Append(PostsStatistics.GetPostsStatisticsString(i_PostsFilters));
                }
                else
                {
                    stillCalculatingSomeStatistics.Append("Still calculating Posts statistics" + Environment.NewLine);
                }
            }

            if (stillCalculatingSomeStatistics.Length != 0)
            {
                stillCalculatingSomeStatistics.Append("Please wait...");
                throw new Exception(stillCalculatingSomeStatistics.ToString());
            }

            return(statistics.ToString());
        }
Пример #6
0
        public void should_throw_exception_for_old_date()
        {
            var target = new EventsStatistics();

            Assert.Throws<ArgumentException>(() => target.NumberOfEventsPerYear.Add(2010));
        }
Пример #7
0
        public void NumberOfEventsPerYear_should_not_be_null_after_constructor_call()
        {
            var target = new EventsStatistics();

            Assert.NotNull(target.NumberOfEventsPerYear);
        }