feat(api-gateway): include increments count in statistics measures report

This commit is contained in:
Karol Sójko
2022-10-05 10:02:55 +02:00
parent d5db578bfd
commit 84e8a5cc6e
4 changed files with 18 additions and 5 deletions
@@ -12,4 +12,5 @@ export interface StatisticsStoreInterface {
setMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void>
getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number>
getMeasureTotal(measure: StatisticsMeasure, periodOrPeriodKey: Period | string): Promise<number>
getMeasureIncrementCounts(measure: StatisticsMeasure, period: Period): Promise<number>
}
@@ -8,6 +8,17 @@ import { StatisticsStoreInterface } from '../../Domain/Statistics/StatisticsStor
export class RedisStatisticsStore implements StatisticsStoreInterface {
constructor(private periodKeyGenerator: PeriodKeyGeneratorInterface, private redisClient: IORedis.Redis) {}
async getMeasureIncrementCounts(measure: StatisticsMeasure, period: Period): Promise<number> {
const increments = await this.redisClient.get(
`count:increments:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`,
)
if (increments === null) {
return 0
}
return +increments
}
async setMeasure(measure: StatisticsMeasure, value: number, periods: Period[]): Promise<void> {
const pipeline = this.redisClient.pipeline()
@@ -45,16 +56,15 @@ export class RedisStatisticsStore implements StatisticsStoreInterface {
}
async getMeasureAverage(measure: StatisticsMeasure, period: Period): Promise<number> {
const increments = await this.redisClient.get(
`count:increments:${measure}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`,
)
if (increments === null) {
const increments = await this.getMeasureIncrementCounts(measure, period)
if (increments === 0) {
return 0
}
const totalValue = await this.getMeasureTotal(measure, period)
return totalValue / +increments
return totalValue / increments
}
async getYesterdayOutOfSyncIncidents(): Promise<number> {
+1
View File
@@ -121,6 +121,7 @@ const requestReport = async (
period,
totalValue: await statisticsStore.getMeasureTotal(statisticMeasureName, period),
average: await statisticsStore.getMeasureAverage(statisticMeasureName, period),
increments: await statisticsStore.getMeasureIncrementCounts(statisticMeasureName, period),
})
}
}
@@ -16,6 +16,7 @@ export interface DailyAnalyticsReportGeneratedEventPayload {
name: string
totalValue: number
average: number
increments: number
period: number
}>
activityStatisticsOverTime: Array<{