From 6b0ef48bec8466802dde118b1cb2d1ac701b38d8 Mon Sep 17 00:00:00 2001 From: fegloff Date: Thu, 11 Jan 2024 15:22:52 -0400 Subject: [PATCH] fix new users report --- src/database/stats.service.ts | 23 ++++++++++++++--------- src/modules/schedule/index.ts | 11 ++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/database/stats.service.ts b/src/database/stats.service.ts index 19ac1229..1ed98f1e 100644 --- a/src/database/stats.service.ts +++ b/src/database/stats.service.ts @@ -79,17 +79,22 @@ export class StatsService { .unix() const dateEnd = currentTime.unix() + const query = logRepository .createQueryBuilder('logs') - .select('tgUserId') - .where( - 'logs.createdAt = (SELECT MIN(createdAt) FROM logs WHERE tgUserId = logs.tgUserId)' - ) - .andWhere(`logs.createdAt BETWEEN TO_TIMESTAMP(${dateStart}) and TO_TIMESTAMP(${dateEnd})`) - - const result = await query.getMany() - console.log(`DAYS ${daysPeriod}`, result) - return 8 + .select('distinct("FirstInsertTime")') // distinct("FirstInsertTime")') // 'logs."tgUserId", MIN(logs."createdAt") AS "FirstTime"') + .from(subQuery => + subQuery + .select('"tgUserId", MIN("createdAt") AS "FirstInsertTime"') + .from(BotLog, 'logs') + .groupBy('"tgUserId"'), 'first_inserts') + if (daysPeriod > 0) { + query.where(`"FirstInsertTime" BETWEEN TO_TIMESTAMP(${dateStart}) and TO_TIMESTAMP(${dateEnd})`) + } + // query.groupBy('logs."tgUserId"') + const result = await query.execute() + // console.log(dateStart, dateEnd, result.length) + return result.length } public async getTotalMessages (daysPeriod = 0, onlySupportedCommands = false): Promise { diff --git a/src/modules/schedule/index.ts b/src/modules/schedule/index.ts index 851fa194..6b61be60 100644 --- a/src/modules/schedule/index.ts +++ b/src/modules/schedule/index.ts @@ -96,7 +96,7 @@ export class BotSchedule { totalMessage, weeklyUsers, - dailyMessages, + newUsers, weeklyRevenue ] = await Promise.all([ getDailyMetrics(MetricsDailyType.totalFee, 7), @@ -112,12 +112,9 @@ export class BotSchedule { statsService.getTotalMessages(0, true), statsService.getActiveUsers(7), - statsService.getTotalMessages(7, true), + statsService.getNewUsers(7), getBotFee(this.holderAddress, 7) // statsService.getRevenue(100) ]) - // await statsService.getNewUsers(100) - // await statsService.getNewUsers(400) - // await statsService.getNewUsers(600) const networkFeesSum = networkFeesWeekly.reduce((sum, item) => sum + +item.value, 0) const walletsCountSum = walletsCountWeekly.reduce((sum, item) => sum + +item.value, 0) @@ -135,10 +132,10 @@ export class BotSchedule { `*$${abbreviateNumber(bridgeTVL)}*, ${abbreviateNumber(totalStakeONE)}, $${abbreviateNumber(swapTradingVolumeSum)}` const oneBotWeeklyMetrics = - 'Bot weekly earns, users, messages: ' + + 'Bot weekly earns, active users, new users: ' + `*${abbreviateNumber(+weeklyRevenue)}* ONE` + `, ${lessThan100(abbreviateNumber(weeklyUsers))}` + - `, ${lessThan100(abbreviateNumber(dailyMessages))}` + `, ${lessThan100(abbreviateNumber(newUsers))}` const oneBotMetrics = 'Bot total earns, users, messages: ' +