private static async Task AddAFewLocalNewsEvents(InMemoryKeyValueStore onDeviceEventsStore) { var a = new LocalAnalytics(); // Set up a few simple usage rules to generate local news events from if they are true: var appUsed1DayRule = a.NewAppUsedXDaysRule(days: 1); var featureNeverUsedRule = a.NewFeatureNotUsedXTimesRule("feature1", times: 1); var appNotUsedLast5Days = a.NewAppUsedInTheLastXDaysRule(5); var userCameBackRule = a.NewConcatRule(appUsed1DayRule, appNotUsedLast5Days); var url = "https://github.com/cs-util-com/cscore"; var urlText = "Show details.."; if (await appUsed1DayRule.isTrue()) { var n = News.NewLocalNewsEvent("Achievement Unlocked", "You used the app 1 day", url, urlText); await onDeviceEventsStore.Set(n.key, n); } if (await featureNeverUsedRule.isTrue()) { var n = News.NewLocalNewsEvent("Did you know you can do feature1?", "Feature 1 is the best", url, urlText); await onDeviceEventsStore.Set(n.key, n); } if (await userCameBackRule.isTrue()) { var n = News.NewLocalNewsEvent("You did not use the app for a while", "How dare you", url, urlText); await onDeviceEventsStore.Set(n.key, n); } }
async Task TestAllRules1(LocalAnalytics analytics, string featureId) { var daysUsed = 20; var timesUsed = 200; UsageRule featureUsedXDays = analytics.NewFeatureUsedXDaysRule(featureId, daysUsed); Assert.False(await featureUsedXDays.isTrue()); Assert.False(await featureUsedXDays.IsFeatureUsedXDays(analytics)); // Used by .isTrue UsageRule featureNotUsedXDays = analytics.NewFeatureNotUsedXDaysRule(featureId, daysUsed); Assert.True(await featureNotUsedXDays.isTrue()); UsageRule appNotUsedXDays = analytics.NewAppNotUsedXDaysRule(daysUsed); Assert.True(await appNotUsedXDays.isTrue()); UsageRule featureNotUsedXTimes = analytics.NewFeatureNotUsedXTimesRule(featureId, timesUsed); Assert.True(await featureNotUsedXTimes.isTrue()); UsageRule appUsedInTheLastXDays = analytics.NewAppUsedInTheLastXDaysRule(daysUsed); Assert.True(await appUsedInTheLastXDays.isTrue()); UsageRule appNotUsedInTheLastXDays = analytics.NewAppNotUsedInTheLastXDaysRule(daysUsed); Assert.False(await appNotUsedInTheLastXDays.isTrue()); UsageRule featureUsedInTheLastXDays = analytics.NewFeatureUsedInTheLastXDaysRule(featureId, daysUsed); Assert.True(await featureUsedInTheLastXDays.isTrue()); { // Compose a more complex usage rule out of multiple rules: UsageRule appUsedXDays = analytics.NewAppUsedXDaysRule(daysUsed); Assert.False(await appUsedXDays.isTrue()); UsageRule featureUsedXTimes = analytics.NewFeatureUsedXTimesRule(featureId, timesUsed); Assert.False(await featureUsedXTimes.isTrue()); UsageRule featureNotUsedInTheLastXDays = analytics.NewFeatureNotUsedInTheLastXDaysRule(featureId, daysUsed); Assert.False(await featureNotUsedInTheLastXDays.isTrue()); UsageRule featureNotUsedAnymoreRule = analytics.NewConcatRule( appUsedXDays, featureUsedXTimes, featureNotUsedInTheLastXDays ); Assert.False(await featureNotUsedAnymoreRule.isTrue()); UsageRule clone = featureNotUsedAnymoreRule.DeepCopyViaJson(); clone.SetupUsing(analytics); Assert.False(await clone.isTrue()); } }