Пример #1
0
        internal IEnumerable <string> GetFilesToRead(DateTime start, DateTime end)
        {
            if (start > end)
            {
                throw new ArgumentException("Start time is greater than end time");
            }

            ITimeWindow   window   = new DayTimeWindow(start);
            List <string> fileList = new List <string>();

            if (end > window.EndTime)
            {
                window = window.ToWeekWindow();

                if (end > window.EndTime)
                {
                    fileList.AddRange(GetAllWeeksBetween(start, end));
                }
                else
                {
                    fileList.AddRange(GetAllDaysForWeek(window.StartTime));
                }
            }
            else
            {
                fileList.AddRange(GetAllHourForDay(window.StartTime));
            }
            return(fileList);
        }
Пример #2
0
        /// <summary>
        /// Aggregates based on time and activity and returns in grouped data format
        /// </summary>
        /// <returns></returns>
        public IEnumerable <GroupedDataFormat> ToGroupedDataFormat()
        {
            if (_list.Count() == 0)
            {
                return(new List <GroupedDataFormat>());
            }

            var start = _list.Min(s => s.Time);
            var end   = _list.Max(s => s.Time);

            ITimeWindow window = new DayTimeWindow(start);

            if (end > window.EndTime)
            {
                window = window.ToWeekWindow();

                if (end > window.EndTime)
                {
                    return(ToGroupedDataFormatPerWeek());
                }
                else
                {
                    return(ToGroupedDataFormatPerDay());
                }
            }
            else
            {
                return(ToGroupedDataFormatPerHour());
            }
        }
Пример #3
0
        internal string GetWeekSummary(DateTime time)
        {
            // TODO this method needs to be called by write store at sometime.
            ITimeWindow window = new DayTimeWindow(time);

            window = window.ToWeekWindow();

            return(Path.Combine(_baseFolder,
                                window.EndTime.Year.ToString(),
                                window.EndTime.Month.ToString(),
                                window.EndTime.Day.ToString(),
                                _weekSummary));
        }
Пример #4
0
        private static string GetAxisString(DateTime time, GroupWindowType type)
        {
            switch (type)
            {
            case GroupWindowType.Hour:
                return(time.ToShortDateString() + " " + time.Hour);

            case GroupWindowType.Day:
                return(time.ToShortDateString());

            case GroupWindowType.Week:
                ITimeWindow window = new DayTimeWindow(time);
                window = window.ToWeekWindow();
                return(window.StartTime.ToShortDateString() + " " + window.EndTime.ToShortDateString());

            default:
                throw new ArgumentException();
            }
        }
Пример #5
0
        private IEnumerable <string> GetAllWeeksBetween(DateTime start, DateTime end)
        {
            List <string> filePaths = new List <string>();

            ITimeWindow window = new DayTimeWindow(start);

            window = window.ToWeekWindow();
            while (end > window.EndTime)
            {
                string fileName = GetWeekSummary(window.EndTime);
                if (File.Exists(fileName))
                {
                    filePaths.Add(fileName);
                }

                window.GoNext();
            }

            return(filePaths);
        }
Пример #6
0
        public void Basic_ListAtom_GroupedDataFormat_ByWeek()
        {
            // Aggregation if same activity???
            DateTime date = new DateTime(2012, 4, 1, 1, 1, 1);

            ITimeWindow window     = new DayTimeWindow(date).ToWeekWindow();
            ITimeWindow windowNext = new DayTimeWindow(date).ToWeekWindow();

            windowNext.GoNext();

            List <DataAtom> list = new List <DataAtom>()
            {
                new DataAtom()
                {
                    Time      = window.StartTime.AddDays(1),
                    Process   = "Foo",                // activity
                    Title     = "Foo title",          // not bubbled yet
                    Frequency = 5                     // aggregated
                },
                new DataAtom()
                {
                    Time      = window.StartTime.AddDays(2),
                    Process   = "Foo",                // activity
                    Title     = "Foo title",          // not bubbled yet
                    Frequency = 5                     // aggregated
                },
                new DataAtom()
                {
                    Time      = window.StartTime.AddDays(3).AddMinutes(1),
                    Process   = "Bar",                 // activity
                    Title     = "Foo title",           // not bubbled yet
                    Frequency = 20                     // aggregated
                },
                new DataAtom()
                {
                    Time      = windowNext.StartTime.AddDays(1),
                    Process   = "Qux",                 // activity
                    Title     = "Foo title",           // not bubbled yet
                    Frequency = 30                     // aggregated
                }
            };

            List <GroupedDataFormat> expected = new List <GroupedDataFormat>()
            {
                new GroupedDataFormat()
                {
                    GroupBy  = window.StartTime,
                    Activity = new[] { "Bar", "Foo" },
                    TimeSpan = new long[] { 20, 10 }                    // aggregated over start - end, but grouped by group by
                },
                new GroupedDataFormat()
                {
                    GroupBy  = windowNext.StartTime,
                    Activity = new[] { "Qux" },
                    TimeSpan = new long[] { 30 }                     // aggregated over start - end, but grouped by group by
                }
            };

            var actual = new DataFormatConvertor(list).ToGroupedDataFormat();

            Assert.AreEqual(expected.Count, actual.Count());

            var zipped = expected.Zip(actual, (e, a) => new { Expected = e, Actual = a });

            foreach (var item in zipped)
            {
                CollectionAssert.AreEqual(item.Expected.Activity, item.Actual.Activity);
                CollectionAssert.AreEqual(item.Expected.TimeSpan, item.Actual.TimeSpan);
                Assert.AreEqual(item.Expected.GroupBy.Year, item.Actual.GroupBy.Year);
                Assert.AreEqual(item.Expected.GroupBy.Month, item.Actual.GroupBy.Month);
                Assert.AreEqual(item.Expected.GroupBy.Day, item.Actual.GroupBy.Day);
            }
        }