예제 #1
0
        public static async Task <bool> IsFeatureUsedInTheLastXDays(this UsageRule self, LocalAnalytics analytics)
        {
            var allEvents = await analytics.GetAllEventsForCategory(self.categoryId);

            if (allEvents.IsNullOrEmpty())
            {
                return(false);
            }
            DateTime lastEvent      = allEvents.Last().GetDateTimeUtc();
            TimeSpan lastEventVsNow = DateTimeV2.UtcNow - lastEvent;

            return(lastEventVsNow.Days <= self.days);
        }
예제 #2
0
        public static async Task <bool> IsNotificationMinXDaysOld(this UsageRule self, LocalAnalytics analytics)
        {
            var allEvents = await analytics.GetAllEventsForCategory(EventConsts.catUsage);

            var showEvents = allEvents.Filter(x => x.action == EventConsts.SHOW + "_" + self.categoryId);

            if (showEvents.IsNullOrEmpty())
            {
                return(false);
            }
            DateTime firstShownEvent = showEvents.First().GetDateTimeUtc();
            TimeSpan firstShownVsNow = DateTimeV2.UtcNow - firstShownEvent;

            return(firstShownVsNow.Days >= self.days);
        }
예제 #3
0
        public static UsageRule SetupUsing(this UsageRule self, LocalAnalytics analytics)
        {
            self.isTrue = async() => {
                switch (self.ruleType)
                {
                case UsageRule.AppUsedXDays: return(await self.IsAppUsedXDays(analytics));

                case UsageRule.AppNotUsedXDays: return(!await self.IsAppUsedXDays(analytics));

                case UsageRule.AppUsedInTheLastXDays: return(self.IsAppUsedInTheLastXDays());

                case UsageRule.AppNotUsedInTheLastXDays: return(!self.IsAppUsedInTheLastXDays());

                case UsageRule.FeatureUsedInTheLastXDays: return(await self.IsFeatureUsedInTheLastXDays(analytics));

                case UsageRule.FeatureNotUsedInTheLastXDays: return(!await self.IsFeatureUsedInTheLastXDays(analytics));

                case UsageRule.FeatureUsedXDays: return(await self.IsFeatureUsedXDays(analytics));

                case UsageRule.FeatureNotUsedXDays: return(!await self.IsFeatureUsedXDays(analytics));

                case UsageRule.FeatureUsedXTimes: return(await self.IsFeatureUsedXTimes(analytics));

                case UsageRule.FeatureNotUsedXTimes: return(!await self.IsFeatureUsedXTimes(analytics));

                case UsageRule.NotificationMinXDaysOld: return(await self.IsNotificationMinXDaysOld(analytics));

                case UsageRule.ConcatRule:
                    foreach (var rule in self.andRules)
                    {
                        if (rule.isTrue == null)
                        {
                            rule.SetupUsing(analytics);
                        }
                        if (!await rule.isTrue())
                        {
                            return(false);
                        }
                    }
                    return(true);

                default:
                    Log.e("Unknown ruleType: " + self.ruleType);
                    return(false);
                }
            };
            return(self);
        }
예제 #4
0
        public static async Task <bool> IsAppUsedXDays(this UsageRule self, LocalAnalytics analytics)
        {
            var allEvents = await analytics.GetAll();

            return(allEvents.GroupByDay().Count() >= self.days);
        }
예제 #5
0
        public static async Task <bool> IsFeatureUsedXTimes(this UsageRule self, LocalAnalytics analytics)
        {
            var startEvents = await analytics.GetStartEvents(self.categoryId);

            return(startEvents.Count() >= self.timesUsed.Value);
        }
예제 #6
0
        public static bool IsAppUsedInTheLastXDays(this UsageRule self)
        {
            var tSinceLatestLaunch = DateTimeV2.UtcNow - EnvironmentV2.instance.systemInfo.GetLatestLaunchDate();

            return(tSinceLatestLaunch.Days < self.days);
        }
예제 #7
0
        public static async Task <bool> IsFeatureUsedXDays(this UsageRule self, LocalAnalytics analytics)
        {
            var allEvents = await analytics.GetAllEventsForCategory(self.categoryId);

            return(allEvents.GroupByDay().Count() >= self.days);
        }