@standardnotes/analytics
Advanced tools
Comparing version 1.32.0 to 1.33.0
@@ -14,3 +14,3 @@ import { Period } from '../Time/Period'; | ||
}): Promise<number>; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number>; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, periodOrPeriodKey: Period | string): Promise<number>; | ||
calculateActivityChangesTotalCount(activity: AnalyticsActivity, period: Period): Promise<Array<{ | ||
@@ -17,0 +17,0 @@ periodKey: string; |
@@ -19,3 +19,3 @@ import { Period } from '../Time/Period'; | ||
getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
getMeasureTotal(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
getMeasureTotal(measure: StatisticsMeasure, periodOrPeriodKey: Period | string): Promise<number>; | ||
} |
@@ -16,3 +16,15 @@ export declare enum Period { | ||
Q3ThisYear = 13, | ||
Q4ThisYear = 14 | ||
Q4ThisYear = 14, | ||
JanuaryThisYear = 15, | ||
FebruaryThisYear = 16, | ||
MarchThisYear = 17, | ||
AprilThisYear = 18, | ||
MayThisYear = 19, | ||
JuneThisYear = 20, | ||
JulyThisYear = 21, | ||
AugustThisYear = 22, | ||
SeptemberThisYear = 23, | ||
OctoberThisYear = 24, | ||
NovemberThisYear = 25, | ||
DecemberThisYear = 26 | ||
} |
@@ -21,2 +21,14 @@ "use strict"; | ||
Period[Period["Q4ThisYear"] = 14] = "Q4ThisYear"; | ||
Period[Period["JanuaryThisYear"] = 15] = "JanuaryThisYear"; | ||
Period[Period["FebruaryThisYear"] = 16] = "FebruaryThisYear"; | ||
Period[Period["MarchThisYear"] = 17] = "MarchThisYear"; | ||
Period[Period["AprilThisYear"] = 18] = "AprilThisYear"; | ||
Period[Period["MayThisYear"] = 19] = "MayThisYear"; | ||
Period[Period["JuneThisYear"] = 20] = "JuneThisYear"; | ||
Period[Period["JulyThisYear"] = 21] = "JulyThisYear"; | ||
Period[Period["AugustThisYear"] = 22] = "AugustThisYear"; | ||
Period[Period["SeptemberThisYear"] = 23] = "SeptemberThisYear"; | ||
Period[Period["OctoberThisYear"] = 24] = "OctoberThisYear"; | ||
Period[Period["NovemberThisYear"] = 25] = "NovemberThisYear"; | ||
Period[Period["DecemberThisYear"] = 26] = "DecemberThisYear"; | ||
})(Period = exports.Period || (exports.Period = {})); |
import { Period } from './Period'; | ||
import { PeriodKeyGeneratorInterface } from './PeriodKeyGeneratorInterface'; | ||
export declare class PeriodKeyGenerator implements PeriodKeyGeneratorInterface { | ||
private readonly MONTHS; | ||
convertPeriodKeyToPeriod(periodKey: string): Period; | ||
getDiscretePeriodKeys(period: Period): string[]; | ||
@@ -20,2 +22,3 @@ getPeriodKey(period: Period): string; | ||
private generateMonthlyKeysRange; | ||
private generateDailyKeysRange; | ||
} |
@@ -6,2 +6,21 @@ "use strict"; | ||
class PeriodKeyGenerator { | ||
MONTHS = [ | ||
Period_1.Period.JanuaryThisYear, | ||
Period_1.Period.FebruaryThisYear, | ||
Period_1.Period.MarchThisYear, | ||
Period_1.Period.AprilThisYear, | ||
Period_1.Period.MayThisYear, | ||
Period_1.Period.JuneThisYear, | ||
Period_1.Period.JulyThisYear, | ||
Period_1.Period.AugustThisYear, | ||
Period_1.Period.SeptemberThisYear, | ||
Period_1.Period.OctoberThisYear, | ||
Period_1.Period.NovemberThisYear, | ||
Period_1.Period.DecemberThisYear, | ||
]; | ||
convertPeriodKeyToPeriod(periodKey) { | ||
const date = new Date(periodKey); | ||
const month = this.getMonth(date); | ||
return this.MONTHS[+month - 1]; | ||
} | ||
getDiscretePeriodKeys(period) { | ||
@@ -28,2 +47,19 @@ const periodKeys = []; | ||
return this.generateMonthlyKeysRange(9, 12); | ||
case Period_1.Period.ThisYear: | ||
return this.generateMonthlyKeysRange(0, 12); | ||
case Period_1.Period.ThisMonth: | ||
return this.generateDailyKeysRange(); | ||
case Period_1.Period.JanuaryThisYear: | ||
case Period_1.Period.FebruaryThisYear: | ||
case Period_1.Period.MarchThisYear: | ||
case Period_1.Period.AprilThisYear: | ||
case Period_1.Period.MayThisYear: | ||
case Period_1.Period.JuneThisYear: | ||
case Period_1.Period.JulyThisYear: | ||
case Period_1.Period.AugustThisYear: | ||
case Period_1.Period.SeptemberThisYear: | ||
case Period_1.Period.OctoberThisYear: | ||
case Period_1.Period.NovemberThisYear: | ||
case Period_1.Period.DecemberThisYear: | ||
return this.generateDailyKeysRange(period - 15); | ||
default: | ||
@@ -53,2 +89,26 @@ throw new Error(`Unsuporrted period: ${period}`); | ||
return this.getYearlyKey(); | ||
case Period_1.Period.JanuaryThisYear: | ||
return this.generateMonthlyKeysRange(0, 1)[0]; | ||
case Period_1.Period.FebruaryThisYear: | ||
return this.generateMonthlyKeysRange(1, 2)[0]; | ||
case Period_1.Period.MarchThisYear: | ||
return this.generateMonthlyKeysRange(2, 3)[0]; | ||
case Period_1.Period.AprilThisYear: | ||
return this.generateMonthlyKeysRange(3, 4)[0]; | ||
case Period_1.Period.MayThisYear: | ||
return this.generateMonthlyKeysRange(4, 5)[0]; | ||
case Period_1.Period.JuneThisYear: | ||
return this.generateMonthlyKeysRange(5, 6)[0]; | ||
case Period_1.Period.JulyThisYear: | ||
return this.generateMonthlyKeysRange(6, 7)[0]; | ||
case Period_1.Period.AugustThisYear: | ||
return this.generateMonthlyKeysRange(7, 8)[0]; | ||
case Period_1.Period.SeptemberThisYear: | ||
return this.generateMonthlyKeysRange(8, 9)[0]; | ||
case Period_1.Period.OctoberThisYear: | ||
return this.generateMonthlyKeysRange(9, 10)[0]; | ||
case Period_1.Period.NovemberThisYear: | ||
return this.generateMonthlyKeysRange(10, 11)[0]; | ||
case Period_1.Period.DecemberThisYear: | ||
return this.generateMonthlyKeysRange(11, 12)[0]; | ||
default: | ||
@@ -125,3 +185,18 @@ throw new Error(`Unsuporrted period: ${period}`); | ||
} | ||
generateDailyKeysRange(month) { | ||
const today = new Date(); | ||
if (month) { | ||
today.setMonth(month); | ||
} | ||
const numberOfDays = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate(); | ||
const keys = []; | ||
for (let i = 1; i <= numberOfDays; i++) { | ||
const date = new Date(); | ||
date.setMonth(today.getMonth()); | ||
date.setDate(i); | ||
keys.push(this.getDailyKey(date)); | ||
} | ||
return keys; | ||
} | ||
} | ||
exports.PeriodKeyGenerator = PeriodKeyGenerator; |
import { Period } from './Period'; | ||
export interface PeriodKeyGeneratorInterface { | ||
getPeriodKey(period: Period): string; | ||
convertPeriodKeyToPeriod(periodKey: string): Period; | ||
getDiscretePeriodKeys(period: Period): string[]; | ||
} |
@@ -25,3 +25,3 @@ import * as IORedis from 'ioredis'; | ||
calculateActivityRetention(activity: AnalyticsActivity, firstPeriod: Period, secondPeriod: Period): Promise<number>; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number>; | ||
calculateActivityTotalCount(activity: AnalyticsActivity, periodOrPeriodKey: Period | string): Promise<number>; | ||
} |
@@ -73,6 +73,10 @@ "use strict"; | ||
} | ||
async calculateActivityTotalCount(activity, period) { | ||
return this.redisClient.bitcount(`bitmap:action:${activity}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); | ||
async calculateActivityTotalCount(activity, periodOrPeriodKey) { | ||
let periodKey = periodOrPeriodKey; | ||
if (!isNaN(+periodOrPeriodKey)) { | ||
periodKey = this.periodKeyGenerator.getPeriodKey(periodOrPeriodKey); | ||
} | ||
return this.redisClient.bitcount(`bitmap:action:${activity}:timespan:${periodKey}`); | ||
} | ||
} | ||
exports.RedisAnalyticsStore = RedisAnalyticsStore; |
@@ -10,3 +10,3 @@ import * as IORedis from 'ioredis'; | ||
setMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
getMeasureTotal(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
getMeasureTotal(measure: StatisticsMeasure, periodOrPeriodKey: Period | string): Promise<number>; | ||
incrementMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
@@ -13,0 +13,0 @@ getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number>; |
@@ -19,4 +19,8 @@ "use strict"; | ||
} | ||
async getMeasureTotal(measure, period) { | ||
const totalValue = await this.redisClient.get(`count:measure:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); | ||
async getMeasureTotal(measure, periodOrPeriodKey) { | ||
let periodKey = periodOrPeriodKey; | ||
if (!isNaN(+periodOrPeriodKey)) { | ||
periodKey = this.periodKeyGenerator.getPeriodKey(periodOrPeriodKey); | ||
} | ||
const totalValue = await this.redisClient.get(`count:measure:${measure}:timespan:${periodKey}`); | ||
if (totalValue === null) { | ||
@@ -23,0 +27,0 @@ return 0; |
{ | ||
"name": "@standardnotes/analytics", | ||
"version": "1.32.0", | ||
"version": "1.33.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=14.0.0 <17.0.0" | ||
}, | ||
"gitHead": "ad60b9553744becd14c738e76dc475b4493fbc6e" | ||
"gitHead": "039d44718a73a7f3feeddc05bc308c1addc479ab" | ||
} |
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
70118
711