@standardnotes/analytics
Advanced tools
Comparing version 1.10.0 to 1.11.0
@@ -9,2 +9,6 @@ import { Period } from '../Time/Period'; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number>; | ||
calculateActivityChangesTotalCount(activity: AnalyticsActivity, period: Period): Promise<Array<{ | ||
periodKey: string; | ||
totalCount: number; | ||
}>>; | ||
} |
@@ -9,3 +9,4 @@ export declare enum Period { | ||
ThisMonth = 6, | ||
LastMonth = 7 | ||
LastMonth = 7, | ||
Last30Days = 8 | ||
} |
@@ -14,2 +14,3 @@ "use strict"; | ||
Period[Period["LastMonth"] = 7] = "LastMonth"; | ||
Period[Period["Last30Days"] = 8] = "Last30Days"; | ||
})(Period = exports.Period || (exports.Period = {})); |
import { Period } from './Period'; | ||
import { PeriodKeyGeneratorInterface } from './PeriodKeyGeneratorInterface'; | ||
export declare class PeriodKeyGenerator implements PeriodKeyGeneratorInterface { | ||
getDiscretePeriodKeys(period: Period): string[]; | ||
getPeriodKey(period: Period): string; | ||
@@ -11,2 +12,3 @@ private getMonthlyKey; | ||
private getDayOfTheMonth; | ||
private getDateNDaysBefore; | ||
private getYesterdayDate; | ||
@@ -13,0 +15,0 @@ private getDayBeforeYesterdayDate; |
@@ -6,2 +6,14 @@ "use strict"; | ||
class PeriodKeyGenerator { | ||
getDiscretePeriodKeys(period) { | ||
const periodKeys = []; | ||
switch (period) { | ||
case Period_1.Period.Last30Days: | ||
for (let i = 1; i <= 30; i++) { | ||
periodKeys.unshift(this.getDailyKey(this.getDateNDaysBefore(i))); | ||
} | ||
return periodKeys; | ||
default: | ||
throw new Error(`Unsuporrted period: ${period}`); | ||
} | ||
} | ||
getPeriodKey(period) { | ||
@@ -53,6 +65,9 @@ switch (period) { | ||
} | ||
getDateNDaysBefore(n) { | ||
const date = new Date(); | ||
date.setDate(new Date().getDate() - n); | ||
return date; | ||
} | ||
getYesterdayDate() { | ||
const yesterday = new Date(); | ||
yesterday.setDate(new Date().getDate() - 1); | ||
return yesterday; | ||
return this.getDateNDaysBefore(1); | ||
} | ||
@@ -59,0 +74,0 @@ getDayBeforeYesterdayDate() { |
import { Period } from './Period'; | ||
export interface PeriodKeyGeneratorInterface { | ||
getPeriodKey(period: Period): string; | ||
getDiscretePeriodKeys(period: Period): string[]; | ||
} |
@@ -10,2 +10,6 @@ import * as IORedis from 'ioredis'; | ||
constructor(periodKeyGenerator: PeriodKeyGeneratorInterface, redisClient: IORedis.Redis); | ||
calculateActivityChangesTotalCount(activity: AnalyticsActivity, period: Period): Promise<Array<{ | ||
periodKey: string; | ||
totalCount: number; | ||
}>>; | ||
markActivity(activities: AnalyticsActivity[], analyticsId: number, periods: Period[]): Promise<void>; | ||
@@ -12,0 +16,0 @@ unmarkActivity(activities: AnalyticsActivity[], analyticsId: number, periods: Period[]): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RedisAnalyticsStore = void 0; | ||
const Period_1 = require("../../Domain/Time/Period"); | ||
class RedisAnalyticsStore { | ||
@@ -11,2 +12,16 @@ periodKeyGenerator; | ||
} | ||
async calculateActivityChangesTotalCount(activity, period) { | ||
if (period !== Period_1.Period.Last30Days) { | ||
throw new Error(`Unsuporrted period: ${period}`); | ||
} | ||
const periodKeys = this.periodKeyGenerator.getDiscretePeriodKeys(Period_1.Period.Last30Days); | ||
const counts = []; | ||
for (const periodKey of periodKeys) { | ||
counts.push({ | ||
periodKey, | ||
totalCount: await this.redisClient.bitcount(`bitmap:action:${activity}:timespan:${periodKey}`), | ||
}); | ||
} | ||
return counts; | ||
} | ||
async markActivity(activities, analyticsId, periods) { | ||
@@ -13,0 +28,0 @@ const pipeline = this.redisClient.pipeline(); |
{ | ||
"name": "@standardnotes/analytics", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=14.0.0 <17.0.0" | ||
}, | ||
"gitHead": "f2c549158d869b8b39195f4cbf7693f86050f270" | ||
"gitHead": "a04ab5b0e8afae29be843034bc07357d824c04a8" | ||
} |
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
55763
426