Compare commits

..

2 Commits

Author SHA1 Message Date
standardci
24c0cb8366 chore(release): publish new version
- @standardnotes/api-gateway@1.24.1
2022-10-03 12:15:56 +00:00
Karol Sójko
2236cc3828 fix: add debug logs for churn calculation 2022-10-03 14:14:27 +02:00
3 changed files with 21 additions and 4 deletions

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.24.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.24.0...@standardnotes/api-gateway@1.24.1) (2022-10-03)
### Bug Fixes
* add debug logs for churn calculation ([2236cc3](https://github.com/standardnotes/api-gateway/commit/2236cc3828167e4b94defbde2691bba38458bd1c))
# [1.24.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.23.0...@standardnotes/api-gateway@1.24.0) (2022-10-03)
### Features

View File

@@ -26,6 +26,7 @@ const requestReport = async (
statisticsStore: StatisticsStoreInterface,
domainEventPublisher: DomainEventPublisherInterface,
periodKeyGenerator: PeriodKeyGeneratorInterface,
logger: Logger,
): Promise<void> => {
const analyticsOverTime = []
@@ -140,30 +141,40 @@ const requestReport = async (
const churnRates = []
for (const monthPeriodKey of monthlyPeriodKeys) {
const monthPeriod = periodKeyGenerator.convertPeriodKeyToPeriod(monthPeriodKey)
logger.info(`Calculating churn for: ${monthPeriodKey} (${monthPeriod})`)
const dailyPeriodKeys = periodKeyGenerator.getDiscretePeriodKeys(monthPeriod)
const totalCustomerCounts: Array<number> = []
for (const dailyPeriodKey of dailyPeriodKeys) {
totalCustomerCounts.push(await statisticsStore.getMeasureTotal(StatisticsMeasure.TotalCustomers, dailyPeriodKey))
const customersCount = await statisticsStore.getMeasureTotal(StatisticsMeasure.TotalCustomers, dailyPeriodKey)
logger.info(`Customers count for ${dailyPeriodKey}: ${customersCount}`)
totalCustomerCounts.push(customersCount)
}
const filteredTotalCustomerCounts = totalCustomerCounts.filter((count) => !!count)
const averageCustomersCount =
filteredTotalCustomerCounts.reduce((total, current) => total + current, 0) / filteredTotalCustomerCounts.length
logger.info(
`Average customers count for ${monthPeriodKey} (total: ${filteredTotalCustomerCounts.length}): ${averageCustomersCount}`,
)
const existingCustomersChurn = await analyticsStore.calculateActivityTotalCount(
AnalyticsActivity.ExistingCustomersChurn,
monthPeriodKey,
)
logger.info(`Existing customers churn ${existingCustomersChurn}`)
const newCustomersChurn = await analyticsStore.calculateActivityTotalCount(
AnalyticsActivity.NewCustomersChurn,
monthPeriodKey,
)
logger.info(`Existing customers churn ${newCustomersChurn}`)
const totalChurn = existingCustomersChurn + newCustomersChurn
logger.info(`Churn Rate: ${(totalChurn / averageCustomersCount) * 100}`)
churnRates.push({
periodKey: monthPeriodKey,
rate: totalChurn / averageCustomersCount,
rate: (totalChurn / averageCustomersCount) * 100,
})
}
@@ -218,7 +229,7 @@ void container.load().then((container) => {
const domainEventPublisher: DomainEventPublisherInterface = container.get(TYPES.DomainEventPublisher)
const periodKeyGenerator: PeriodKeyGeneratorInterface = container.get(TYPES.PeriodKeyGenerator)
Promise.resolve(requestReport(analyticsStore, statisticsStore, domainEventPublisher, periodKeyGenerator))
Promise.resolve(requestReport(analyticsStore, statisticsStore, domainEventPublisher, periodKeyGenerator, logger))
.then(() => {
logger.info('Usage report generation complete')

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.24.0",
"version": "1.24.1",
"engines": {
"node": ">=16.0.0 <17.0.0"
},