@standardnotes/analytics
Advanced tools
Comparing version 1.23.0 to 1.24.0
@@ -8,2 +8,8 @@ import { Period } from '../Time/Period'; | ||
calculateActivityRetention(activity: AnalyticsActivity, firstPeriod: Period, secondPeriod: Period): Promise<number>; | ||
calculateActivitiesRetention(parameters: { | ||
firstActivity: AnalyticsActivity; | ||
firstActivityPeriodKey: string; | ||
secondActivity: AnalyticsActivity; | ||
secondActivityPeriodKey: string; | ||
}): Promise<number>; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number>; | ||
@@ -10,0 +16,0 @@ calculateActivityChangesTotalCount(activity: AnalyticsActivity, period: Period): Promise<Array<{ |
@@ -18,4 +18,10 @@ import * as IORedis from 'ioredis'; | ||
wasActivityDone(activity: AnalyticsActivity, analyticsId: number, period: Period): Promise<boolean>; | ||
calculateActivitiesRetention(parameters: { | ||
firstActivity: AnalyticsActivity; | ||
firstActivityPeriodKey: string; | ||
secondActivity: AnalyticsActivity; | ||
secondActivityPeriodKey: string; | ||
}): Promise<number>; | ||
calculateActivityRetention(activity: AnalyticsActivity, firstPeriod: Period, secondPeriod: Period): Promise<number>; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number>; | ||
} |
@@ -57,12 +57,18 @@ "use strict"; | ||
} | ||
async calculateActivityRetention(activity, firstPeriod, secondPeriod) { | ||
const initialPeriodKey = this.periodKeyGenerator.getPeriodKey(firstPeriod); | ||
const subsequentPeriodKey = this.periodKeyGenerator.getPeriodKey(secondPeriod); | ||
const diffKey = `bitmap:action:${activity}:timespan:${initialPeriodKey}-${subsequentPeriodKey}`; | ||
await this.redisClient.bitop('AND', diffKey, `bitmap:action:${activity}:timespan:${initialPeriodKey}`, `bitmap:action:${activity}:timespan:${subsequentPeriodKey}`); | ||
async calculateActivitiesRetention(parameters) { | ||
const diffKey = `bitmap:action:${parameters.firstActivity}-${parameters.secondActivity}:timespan:${parameters.secondActivityPeriodKey}`; | ||
await this.redisClient.bitop('AND', diffKey, `bitmap:action:${parameters.firstActivity}:timespan:${parameters.firstActivityPeriodKey}`, `bitmap:action:${parameters.secondActivity}:timespan:${parameters.secondActivityPeriodKey}`); | ||
await this.redisClient.expire(diffKey, 3600); | ||
const retainedTotalInActivity = await this.redisClient.bitcount(diffKey); | ||
const initialTotalInActivity = await this.redisClient.bitcount(`bitmap:action:${activity}:timespan:${initialPeriodKey}`); | ||
const initialTotalInActivity = await this.redisClient.bitcount(`bitmap:action:${parameters.firstActivity}:timespan:${parameters.firstActivityPeriodKey}`); | ||
return Math.ceil((retainedTotalInActivity * 100) / initialTotalInActivity); | ||
} | ||
async calculateActivityRetention(activity, firstPeriod, secondPeriod) { | ||
return this.calculateActivitiesRetention({ | ||
firstActivity: activity, | ||
firstActivityPeriodKey: this.periodKeyGenerator.getPeriodKey(firstPeriod), | ||
secondActivity: activity, | ||
secondActivityPeriodKey: this.periodKeyGenerator.getPeriodKey(secondPeriod), | ||
}); | ||
} | ||
async calculateActivityTotalCount(activity, period) { | ||
@@ -69,0 +75,0 @@ return this.redisClient.bitcount(`bitmap:action:${activity}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); |
{ | ||
"name": "@standardnotes/analytics", | ||
"version": "1.23.0", | ||
"version": "1.24.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=14.0.0 <17.0.0" | ||
}, | ||
"gitHead": "686e4f8ddf8a268722b8a8bce4367413db7b2d75" | ||
"gitHead": "c5fdd59eb1fe4f7cea990d09c17e54e3c858db48" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62549
551