@standardnotes/analytics
Advanced tools
Comparing version 1.31.1 to 1.32.0
@@ -11,3 +11,4 @@ export declare enum StatisticsMeasure { | ||
FilesCount = "files-count", | ||
NewCustomers = "new-customers" | ||
NewCustomers = "new-customers", | ||
TotalCustomers = "total-customers" | ||
} |
@@ -16,2 +16,3 @@ "use strict"; | ||
StatisticsMeasure["NewCustomers"] = "new-customers"; | ||
StatisticsMeasure["TotalCustomers"] = "total-customers"; | ||
})(StatisticsMeasure = exports.StatisticsMeasure || (exports.StatisticsMeasure = {})); |
@@ -17,4 +17,5 @@ import { Period } from '../Time/Period'; | ||
incrementMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
setMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
getMeasureTotal(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
} |
@@ -10,8 +10,9 @@ export declare enum Period { | ||
LastMonth = 7, | ||
Last30Days = 8, | ||
Last7Days = 9, | ||
Q1ThisYear = 10, | ||
Q2ThisYear = 11, | ||
Q3ThisYear = 12, | ||
Q4ThisYear = 13 | ||
ThisYear = 8, | ||
Last30Days = 9, | ||
Last7Days = 10, | ||
Q1ThisYear = 11, | ||
Q2ThisYear = 12, | ||
Q3ThisYear = 13, | ||
Q4ThisYear = 14 | ||
} |
@@ -14,8 +14,9 @@ "use strict"; | ||
Period[Period["LastMonth"] = 7] = "LastMonth"; | ||
Period[Period["Last30Days"] = 8] = "Last30Days"; | ||
Period[Period["Last7Days"] = 9] = "Last7Days"; | ||
Period[Period["Q1ThisYear"] = 10] = "Q1ThisYear"; | ||
Period[Period["Q2ThisYear"] = 11] = "Q2ThisYear"; | ||
Period[Period["Q3ThisYear"] = 12] = "Q3ThisYear"; | ||
Period[Period["Q4ThisYear"] = 13] = "Q4ThisYear"; | ||
Period[Period["ThisYear"] = 8] = "ThisYear"; | ||
Period[Period["Last30Days"] = 9] = "Last30Days"; | ||
Period[Period["Last7Days"] = 10] = "Last7Days"; | ||
Period[Period["Q1ThisYear"] = 11] = "Q1ThisYear"; | ||
Period[Period["Q2ThisYear"] = 12] = "Q2ThisYear"; | ||
Period[Period["Q3ThisYear"] = 13] = "Q3ThisYear"; | ||
Period[Period["Q4ThisYear"] = 14] = "Q4ThisYear"; | ||
})(Period = exports.Period || (exports.Period = {})); |
@@ -6,2 +6,3 @@ import { Period } from './Period'; | ||
getPeriodKey(period: Period): string; | ||
private getYearlyKey; | ||
private getMonthlyKey; | ||
@@ -8,0 +9,0 @@ private getDailyKey; |
@@ -49,2 +49,4 @@ "use strict"; | ||
return this.getMonthlyKey(this.getLastMonthDate()); | ||
case Period_1.Period.ThisYear: | ||
return this.getYearlyKey(); | ||
default: | ||
@@ -54,2 +56,6 @@ throw new Error(`Unsuporrted period: ${period}`); | ||
} | ||
getYearlyKey(date) { | ||
date = date ?? new Date(); | ||
return this.getYear(date); | ||
} | ||
getMonthlyKey(date) { | ||
@@ -56,0 +62,0 @@ date = date ?? new Date(); |
@@ -9,2 +9,3 @@ import * as IORedis from 'ioredis'; | ||
constructor(periodKeyGenerator: PeriodKeyGeneratorInterface, redisClient: IORedis.Redis); | ||
setMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
getMeasureTotal(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
@@ -11,0 +12,0 @@ incrementMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; |
@@ -12,2 +12,9 @@ "use strict"; | ||
} | ||
async setMeasure(measure, value, periods) { | ||
const pipeline = this.redisClient.pipeline(); | ||
for (const period of periods) { | ||
pipeline.set(`count:measure:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`, value); | ||
} | ||
await pipeline.exec(); | ||
} | ||
async getMeasureTotal(measure, period) { | ||
@@ -14,0 +21,0 @@ const totalValue = await this.redisClient.get(`count:measure:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); |
{ | ||
"name": "@standardnotes/analytics", | ||
"version": "1.31.1", | ||
"version": "1.32.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=14.0.0 <17.0.0" | ||
}, | ||
"gitHead": "27cfd0ccf64492ae1f51191d0fa6f1bb83d0d64c" | ||
"gitHead": "ad60b9553744becd14c738e76dc475b4493fbc6e" | ||
} |
65119
600