Skip to content

Commit

Permalink
add one-time user report
Browse files Browse the repository at this point in the history
  • Loading branch information
fegloff committed Jan 12, 2024
1 parent bf0ceb5 commit fb2c3dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/database/stats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class StatsService {

const query = logRepository
.createQueryBuilder('logs')
.select('distinct("FirstInsertTime")') // distinct("FirstInsertTime")') // 'logs."tgUserId", MIN(logs."createdAt") AS "FirstTime"')
.select('distinct("FirstInsertTime")')
.from(subQuery =>
subQuery
.select('"tgUserId", MIN("createdAt") AS "FirstInsertTime"')
Expand All @@ -91,12 +91,30 @@ export class StatsService {
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
}

// Doesn't check last 7 days.
public async getOnetimeUsers (): Promise<number> {
const bufferDays = 7
const bufferDate = moment()
.tz('America/Los_Angeles')
.set({ hour: 0, minute: 0, second: 0 })
.subtract(bufferDays, 'days')
.unix()

const query = await logRepository
.createQueryBuilder('logs')
.select('count("tgUserId") AS row_count, "tgUserId", MAX("createdAt") AS max_created')
.where(`"createdAt" < TO_TIMESTAMP(${bufferDate})`)
.groupBy('"tgUserId"')
.getRawMany()
const result = query.filter(row => row.row_count === '1')
return result.length
}

public async getTotalMessages (daysPeriod = 0, onlySupportedCommands = false): Promise<number> {
const currentTime = moment()
const dateStart = moment()
Expand Down
10 changes: 8 additions & 2 deletions src/modules/schedule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export class BotSchedule {
weeklyUsers,
totalMessages,
totalSupportedMessages,
engagementByCommand
engagementByCommand,
onetimeUsers,
newUsers
] = await Promise.all([
this.getBotFeeReport(this.holderAddress),
getBotFee(this.holderAddress, 7),
Expand All @@ -187,15 +189,19 @@ export class BotSchedule {
statsService.getActiveUsers(7),
statsService.getTotalMessages(7),
statsService.getTotalMessages(7, true),
this.generateReportEngagementByCommand(7)
this.generateReportEngagementByCommand(7),
statsService.getOnetimeUsers(),
statsService.getNewUsers(7)
])

const report = `\nBot fees: *${botFeesReport}*` +
`\nWeekly bot fees collected: *${abbreviateNumber(botFeesWeekly)}*` +
`\nDaily Active Users: *${abbreviateNumber(dau)}*` +
`\nOne-time users: *${onetimeUsers}*` +
`\nTotal fees users pay in ONE: *${abbreviateNumber(totalOne)}*` +
`\nTotal fees users pay in free credits: *${abbreviateNumber(totalCredits)}*` +
`\nWeekly active users: *${abbreviateNumber(weeklyUsers)}*` +
`\nWeekly new users: *${abbreviateNumber(newUsers)}*` +
`\nWeekly user engagement (any commands): *${abbreviateNumber(totalMessages)}*` +
`\nWeekly user engagement (commands supported by bot): *${abbreviateNumber(totalSupportedMessages)}*` +
`\n\n${engagementByCommand}`
Expand Down

0 comments on commit fb2c3dc

Please sign in to comment.