@standardnotes/analytics
Advanced tools
Comparing version 1.18.1 to 1.19.0
export * from './Analytics/AnalyticsActivity'; | ||
export * from './Analytics/AnalyticsStoreInterface'; | ||
export * from './Statistics/StatisticsMeasure'; | ||
export * from './Statistics/StatisticsStoreInterface'; | ||
@@ -4,0 +5,0 @@ export * from './Time/Period'; |
@@ -19,2 +19,3 @@ "use strict"; | ||
__exportStar(require("./Analytics/AnalyticsStoreInterface"), exports); | ||
__exportStar(require("./Statistics/StatisticsMeasure"), exports); | ||
__exportStar(require("./Statistics/StatisticsStoreInterface"), exports); | ||
@@ -21,0 +22,0 @@ __exportStar(require("./Time/Period"), exports); |
@@ -0,1 +1,3 @@ | ||
import { Period } from '../Time/Period'; | ||
import { StatisticsMeasure } from './StatisticsMeasure'; | ||
export interface StatisticsStoreInterface { | ||
@@ -14,2 +16,5 @@ incrementSNJSVersionUsage(snjsVersion: string): Promise<void>; | ||
getYesterdayOutOfSyncIncidents(): Promise<number>; | ||
incrementMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
getMeasureTotal(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
} |
import * as IORedis from 'ioredis'; | ||
import { PeriodKeyGeneratorInterface } from '../../Domain'; | ||
import { Period, PeriodKeyGeneratorInterface } from '../../Domain'; | ||
import { StatisticsMeasure } from '../../Domain/Statistics/StatisticsMeasure'; | ||
import { StatisticsStoreInterface } from '../../Domain/Statistics/StatisticsStoreInterface'; | ||
@@ -8,2 +9,5 @@ export declare class RedisStatisticsStore implements StatisticsStoreInterface { | ||
constructor(periodKeyGenerator: PeriodKeyGeneratorInterface, redisClient: IORedis.Redis); | ||
getMeasureTotal(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
incrementMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>; | ||
getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number>; | ||
getYesterdayOutOfSyncIncidents(): Promise<number>; | ||
@@ -10,0 +14,0 @@ incrementOutOfSyncIncidents(): Promise<void>; |
@@ -12,2 +12,25 @@ "use strict"; | ||
} | ||
async getMeasureTotal(measure, period) { | ||
const totalValue = await this.redisClient.get(`count:measure:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); | ||
if (totalValue === null) { | ||
return 0; | ||
} | ||
return +totalValue; | ||
} | ||
async incrementMeasure(measure, value, periods) { | ||
const pipeline = this.redisClient.pipeline(); | ||
for (const period of periods) { | ||
pipeline.incrby(`count:measure:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`, value); | ||
pipeline.incr(`count:increments:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); | ||
} | ||
await pipeline.exec(); | ||
} | ||
async getMeasureAverage(measure, period) { | ||
const increments = await this.redisClient.get(`count:increments:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`); | ||
if (increments === null) { | ||
return 0; | ||
} | ||
const totalValue = await this.getMeasureTotal(measure, period); | ||
return totalValue / +increments; | ||
} | ||
async getYesterdayOutOfSyncIncidents() { | ||
@@ -14,0 +37,0 @@ const count = await this.redisClient.get(`count:action:out-of-sync:timespan:${this.periodKeyGenerator.getPeriodKey(Domain_1.Period.Yesterday)}`); |
{ | ||
"name": "@standardnotes/analytics", | ||
"version": "1.18.1", | ||
"version": "1.19.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=14.0.0 <17.0.0" | ||
}, | ||
"gitHead": "4bb785c7f0e54fe160dba51d7c5d97197b8e8bae" | ||
"gitHead": "e618f046ea906588d97f44e8f77212b96a0cd903" | ||
} |
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
61294
26
525