BB.Caching.Redis.Analytics.BitwiseAnalytics.GetCounts C# (CSharp) Method

GetCounts() public static method

Gets counts by TimeInterval for the date range supplied.
/// This should never occur (unhandled TimeInterval). ///
public static GetCounts ( string category, string action, System.DateTime start, System.DateTime end, long eventId = -1, TimeInterval timeInterval = TimeInterval.FifteenMinutes, DayOfWeek firstDayOfWeek = DayOfWeek.Sunday ) : long>>.List
category string /// Typically the object that was interacted with (e.g. button) ///
action string /// The type of interaction (e.g. click) ///
start System.DateTime /// The starting DateTime, inclusive. ///
end System.DateTime /// The end. ///
eventId long /// You can optionally supply the id of the thing being interacted with, which will result in a count of just /// that event. ///
timeInterval TimeInterval /// The time interval. ///
firstDayOfWeek DayOfWeek /// The first day of week (only applies when doing TimeInterval.Week groupings). ///
return long>>.List
        public static List<Tuple<DateTime, long>> GetCounts(
            string category,
            string action,
            DateTime start,
            DateTime end,
            long eventId = -1,
            TimeInterval timeInterval = TimeInterval.FifteenMinutes,
            DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
        {
            var results = new List<Tuple<DateTime, long>>();
            var database = SharedCache.Instance.GetAnalyticsWriteConnection().GetDatabase(SharedCache.Instance.Db);

            do
            {
                switch (timeInterval)
                {
                    case TimeInterval.FifteenMinutes:
                        {
                            start = start.AddMinutes(-(start.Minute % 15));
                            results.Add(new Tuple<DateTime, long>(
                                start, Count(database, GetFifteenMinutes(category, action, start), eventId)));
                            start = start.AddMinutes(15);
                            break;
                        }

                    case TimeInterval.OneHour:
                        {
                            start = start.AddMinutes(-start.Minute);
                            results.Add(new Tuple<DateTime, long>(
                                start, Count(database, GetHour(database, category, action, start), eventId)));
                            start = start.AddHours(1);
                            break;
                        }

                    case TimeInterval.OneDay:
                        {
                            start = start.AddHours(-start.Hour);
                            results.Add(new Tuple<DateTime, long>(
                                start, Count(database, GetDay(database, category, action, start), eventId)));
                            start = start.AddDays(1);
                            break;
                        }

                    case TimeInterval.Week:
                        {
                            int startDiff = start.DayOfWeek - firstDayOfWeek;
                            if (startDiff < 0)
                            {
                                startDiff += 7;
                            }

                            start = start.AddDays(-startDiff);

                            results.Add(new Tuple<DateTime, long>(
                                start, Count(database, GetWeek(database, category, action, start), eventId)));
                            start = start.AddDays(7);
                            break;
                        }

                    case TimeInterval.OneMonth:
                        {
                            start = start.AddDays(1 - start.Day);
                            results.Add(new Tuple<DateTime, long>(
                                start, Count(database, GetMonth(database, category, action, start), eventId)));
                            start = start.AddMonths(1);
                            break;
                        }

                    case TimeInterval.Quarter:
                        {
                            int startQuarter = ((start.Month + 2) / 3) - 1;
                            start = new DateTime(start.Year, (startQuarter * 3) + 1, 1);

                            results.Add(new Tuple<DateTime, long>(
                                start, Count(database, GetQuarter(database, category, action, start), eventId)));
                            start = start.AddMonths(3);
                            break;
                        }

                    default:
                        {
                            throw new Exception(string.Format("unexpected time interval {0}", timeInterval));
                        }
                }
            }
            while (start < end);

            return results;
        }