-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: move statistic feature from v1 to v2 (not tested yet) * feat: change job params so it can aggregate data at a specific date * fix: query fields from exact table * fix: query exact fields * feat: add logger when done * feat: finish statistic jobs (not tested) * feat: create a separate interval job that gets the current date and create statistics jobs with date * feat: update logic using dayjs and lodash lib * feat: update cron jobs logic, move api actions to its service folder * fix: query event from db and group it based on event_id and tx_id * fix: just use a single job to query all daily data * fix: move all queries in daily_stats job into a single Promise all * fix: move dayjs.extend to after import statements * fix: remove _start * fix: only count native token in account_stats job * feat: add api to sync stats from prev dates * fix: support case when user just pass startDate to api * fix: fix whitelist graphql * fix: update column in account_statistic table, update bignum top_tx_sent * fix: remove drop index in modify account statistic table --------- Co-authored-by: AnDQK <doquockhanhan@gmail.com> Co-authored-by: Phan Anh Tuan <fibonacci998@gmail.com>
- Loading branch information
1 parent
b6b007c
commit 887ecfd
Showing
21 changed files
with
1,872 additions
and
872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
migrations/20230704102018_create_table_daily_stats_account_stats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Knex } from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.createTable('daily_statistics', (table: any) => { | ||
table.increments(); | ||
table.bigint('daily_txs').index().notNullable(); | ||
table.bigint('daily_active_addresses').index().notNullable(); | ||
table.bigint('unique_addresses').index().notNullable(); | ||
table.timestamp('date').unique().notNullable(); | ||
}); | ||
await knex.schema.createTable('account_statistics', (table: any) => { | ||
table.increments(); | ||
table.string('address').index().notNullable(); | ||
table.bigint('amount_sent').index().notNullable(); | ||
table.bigint('amount_received').index().notNullable(); | ||
table.bigint('tx_sent').index().notNullable(); | ||
table.bigint('gas_used').index().notNullable(); | ||
table.timestamp('date').index().notNullable(); | ||
table.unique(['address', 'date']); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.dropTable('account_statistics'); | ||
await knex.schema.dropTable('daily_statistics'); | ||
} |
13 changes: 13 additions & 0 deletions
13
migrations/20230817015916_modify_column_table_account_statistic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Knex } from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('account_statistics', (table) => { | ||
table.integer('tx_sent').alter(); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('account_statistics', (table) => { | ||
table.bigint('tx_sent').alter(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import BaseModel from './base'; | ||
|
||
export class AccountStatistics extends BaseModel { | ||
address!: string; | ||
|
||
amount_sent!: string; | ||
|
||
amount_received!: string; | ||
|
||
tx_sent!: number; | ||
|
||
gas_used!: string; | ||
|
||
date!: Date; | ||
|
||
static get tableName() { | ||
return 'account_statistics'; | ||
} | ||
|
||
static get jsonSchema() { | ||
return { | ||
type: 'object', | ||
required: [ | ||
'address', | ||
'amount_sent', | ||
'amount_received', | ||
'tx_sent', | ||
'gas_used', | ||
'date', | ||
], | ||
properties: { | ||
address: { type: 'string' }, | ||
amount_sent: { type: 'string' }, | ||
amount_received: { type: 'string' }, | ||
tx_sent: { type: 'number' }, | ||
gas_used: { type: 'string' }, | ||
date: { type: 'string', format: 'date-time' }, | ||
}, | ||
}; | ||
} | ||
|
||
static get relationMappings() { | ||
return {}; | ||
} | ||
|
||
static newAccountStat(address: string, date: string) { | ||
return AccountStatistics.fromJson({ | ||
address, | ||
amount_sent: '0', | ||
amount_received: '0', | ||
tx_sent: 0, | ||
gas_used: '0', | ||
date, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import BaseModel from './base'; | ||
|
||
export class DailyStatistics extends BaseModel { | ||
daily_txs!: number; | ||
|
||
daily_active_addresses!: number; | ||
|
||
unique_addresses!: number; | ||
|
||
date!: Date; | ||
|
||
static get tableName() { | ||
return 'daily_statistics'; | ||
} | ||
|
||
static get jsonSchema() { | ||
return { | ||
type: 'object', | ||
required: [ | ||
'daily_txs', | ||
'daily_active_addresses', | ||
'unique_addresses', | ||
'date', | ||
], | ||
properties: { | ||
daily_txs: { type: 'number' }, | ||
daily_active_addresses: { type: 'number' }, | ||
unique_addresses: { type: 'number' }, | ||
date: { type: 'string', format: 'date-time' }, | ||
}, | ||
}; | ||
} | ||
|
||
static get relationMappings() { | ||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.