diff --git a/src/database/stats.service.ts b/src/database/stats.service.ts index cceb867d..19ac1229 100644 --- a/src/database/stats.service.ts +++ b/src/database/stats.service.ts @@ -70,6 +70,28 @@ export class StatsService { return rows.length ? +rows[0].count : 0 } + public async getNewUsers (daysPeriod = 0): Promise { + const currentTime = moment() + const dateStart = moment() + .tz('America/Los_Angeles') + .set({ hour: 0, minute: 0, second: 0 }) + .subtract(daysPeriod, 'days') + .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 + } + public async getTotalMessages (daysPeriod = 0, onlySupportedCommands = false): Promise { const currentTime = moment() const dateStart = moment() @@ -83,8 +105,9 @@ export class StatsService { const query = logRepository .createQueryBuilder('logs') .select('count(*)') - .where(`logs.createdAt BETWEEN TO_TIMESTAMP(${dateStart}) and TO_TIMESTAMP(${dateEnd})`) - + if (daysPeriod > 0) { + query.where(`logs.createdAt BETWEEN TO_TIMESTAMP(${dateStart}) and TO_TIMESTAMP(${dateEnd})`) + } if (onlySupportedCommands) { query.andWhere('logs.isSupportedCommand=true') } @@ -113,7 +136,7 @@ export class StatsService { return rows } - public async getRevenue (daysPeriod = 7): Promise { + public async getRevenueFromLog (daysPeriod = 7): Promise { const currentTime = moment() const dateStart = moment() .tz('America/Los_Angeles') @@ -123,7 +146,6 @@ export class StatsService { const dateEnd = currentTime.unix() const result = await logRepository.createQueryBuilder('logs') - // const result = await invoiceRepository.createQueryBuilder('invoice') .select('SUM(CAST(logs.amountCredits AS NUMERIC)) AS revenue') .where('logs.isSupportedCommand=true') .andWhere(`logs.createdAt BETWEEN TO_TIMESTAMP(${dateStart}) and TO_TIMESTAMP(${dateEnd})`) diff --git a/src/modules/schedule/index.ts b/src/modules/schedule/index.ts index 0b50bddc..851fa194 100644 --- a/src/modules/schedule/index.ts +++ b/src/modules/schedule/index.ts @@ -92,8 +92,12 @@ export class BotSchedule { swapTradingVolume, balance, + uniqueUsersCount, + totalMessage, + weeklyUsers, - dailyMessages + dailyMessages, + weeklyRevenue ] = await Promise.all([ getDailyMetrics(MetricsDailyType.totalFee, 7), getDailyMetrics(MetricsDailyType.walletsCount, 7), @@ -104,9 +108,16 @@ export class BotSchedule { getTradingVolume(7), getAddressBalance(this.holderAddress), + statsService.getUniqueUsersCount(), + statsService.getTotalMessages(0, true), + statsService.getActiveUsers(7), - statsService.getTotalMessages(1, true) + statsService.getTotalMessages(7, true), + 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) @@ -123,13 +134,19 @@ export class BotSchedule { 'Total assets, monthly stakes, weekly swaps: ' + `*$${abbreviateNumber(bridgeTVL)}*, ${abbreviateNumber(totalStakeONE)}, $${abbreviateNumber(swapTradingVolumeSum)}` - const oneBotMetrics = - 'Bot total earns, weekly users, daily messages: ' + - `*${abbreviateNumber(balance / Math.pow(10, 18))}* ONE` + + const oneBotWeeklyMetrics = + 'Bot weekly earns, users, messages: ' + + `*${abbreviateNumber(+weeklyRevenue)}* ONE` + `, ${lessThan100(abbreviateNumber(weeklyUsers))}` + `, ${lessThan100(abbreviateNumber(dailyMessages))}` - return `${networkUsage}\n${assetsUpdate}\n${oneBotMetrics}` + const oneBotMetrics = + 'Bot total earns, users, messages: ' + + `*${abbreviateNumber(balance / Math.pow(10, 18))}* ONE` + + `, ${lessThan100(abbreviateNumber(uniqueUsersCount))}` + + `, ${lessThan100(abbreviateNumber(totalMessage))}` + + return `${networkUsage}\n${assetsUpdate}\n${oneBotWeeklyMetrics}\n${oneBotMetrics}` } public async generateReportEngagementByCommand (days: number): Promise {