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

GetWeekAsync() public static method

The get week.
public static GetWeekAsync ( IDatabase database, string category, string action, System.DateTime dateTime, DayOfWeek firstDayOfWeek = DayOfWeek.Sunday ) : Task
database IDatabase /// The database where the query will be performed. This is passed so that we can reuse the same database to /// perform multiple bitwise operations. Doing this with the same connection will guarantee that performance /// is good. ///
category string /// Typically the object that was interacted with (e.g. button) ///
action string /// The type of interaction (e.g. click) ///
dateTime System.DateTime /// The DateTime. ///
firstDayOfWeek DayOfWeek /// The first day to start each week. Defaults to Sunday which is used in the US, CA, and JP. You can /// change it to Monday to get weekly aggregates which are accurate for other countries, but it'll double /// the weekly data stored. ///
return Task
        public static async Task<RedisKey> GetWeekAsync(
            IDatabase database,
            string category,
            string action,
            DateTime dateTime,
            DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
        {
            // get the key
            string week = BitwiseAnalytics.DateTimeUtil.WeekNumber(dateTime, firstDayOfWeek);
            RedisKey key = EventKey(category, action, week);

            // return it if there's already data for this day
            bool weekExists = await BitwiseAnalytics.ExistsAsync(database, key);
            if (weekExists)
            {
                return key;
            }

            // no data for the week, so we need to create it from the days
            string[] daysInWeek = BitwiseAnalytics.DateTimeUtil.DaysInWeek(dateTime, firstDayOfWeek);

            var keyTasks = new List<Task<RedisKey>>();

            // make sure each day exists
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (string day in daysInWeek)
            {
                keyTasks.Add(GetDayAsync(
                    database, category, action, DateTime.ParseExact(day, "yyyyMMdd", CultureInfo.InvariantCulture)));
            }

            await Task.WhenAll(keyTasks);

            // combine the days to form one week
            await BitwiseAnalytics.BitwiseOrAsync(
                database,
                key,
                daysInWeek.Select(x => EventKey(category, action, x)).ToArray());

            return key;
        }