public static GetWeek ( IDatabase database, string category, string action, System.DateTime dateTime, DayOfWeek firstDayOfWeek = DayOfWeek.Sunday ) : RedisKey | ||
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 | RedisKey |
public static RedisKey GetWeek(
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 = BitwiseAnalytics.Exists(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);
// make sure each day exists
foreach (string day in daysInWeek)
{
GetDay(database, category, action, DateTime.ParseExact(day, "yyyyMMdd", CultureInfo.InvariantCulture));
}
// combine the days to form one week
BitwiseAnalytics.BitwiseOr(
database,
key,
daysInWeek.Select(x => EventKey(category, action, x)).ToArray());
return key;
}