-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: statistics #248
feat: statistics #248
Conversation
andqk00
commented
Jul 7, 2023
- Job to crawl daily onchain statistics (number of txs, number of active accounts, total accounts)
- Job to calculate top accounts
- Api to query top accounts since it is stored on redis
…reate statistics jobs with date
Event.EVENT_TYPE.COIN_RECEIVED, | ||
Event.EVENT_TYPE.USE_FEEGRANT, | ||
]) | ||
.orWhereIn('events:attributes.key', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
như này là sao nhỉ?
{ | ||
id: null, | ||
date: ctx.params.date, | ||
accountStats: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cho thành object key là address đi
.orderBy('id') | ||
)[0].id | ||
: _payload.id; | ||
const nextId = startTxId + 50; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sao phải chặn thế này? có nhiều lắm ko?
const dailyEvents = await Transaction.query() | ||
.joinRelated('events.[attributes]') | ||
.select( | ||
'transaction.gas_used', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nếu tách cái gas_used này ra thì có cần join nữa ko?
} | ||
|
||
private calculateTop(dayStat: AccountStatistics[]) { | ||
const newTopStat = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const topAmountSent = [], topAmountReceived = [], topTxSent = [], topGasUsed = [];
(_, index) => index < config.accountStatistics.numberOfTopRecords | ||
); | ||
|
||
return newTopStat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {
top_tx_sent: topTxSent,
top_tx_received: topTxReceived,
..
}
), | ||
}); | ||
}); | ||
newTopStat.top_amount_sent = newTopStat.top_amount_sent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topAmountSent = _.sortBy(topAmountSent, 'percentage').slice(0, config....);
public async handleTopAccounts(_payload: object): Promise<void> { | ||
try { | ||
const syncDate = new Date(); | ||
const now = syncDate.setUTCHours(0, 0, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dùng dayjs
dayjs().startOf('day')
const syncDate = new Date(); | ||
const now = syncDate.setUTCHours(0, 0, 0, 0); | ||
syncDate.setDate(syncDate.getDate() - 3); | ||
const threeDays = syncDate.setUTCHours(0, 0, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const threeDayAgo = syncDate.subtract(3, 'day')
.groupBy('address'), | ||
]); | ||
|
||
let topAccounts = await this.broker.cacher?.get(REDIS_KEY.TOP_ACCOUNTS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bỏ
|
||
@Action({ | ||
name: 'getTopAccounts', | ||
params: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache: {
key: ...
ttl:
},
.subtract(1, 'day') | ||
.startOf('day') | ||
.toDate(); | ||
const endTime = dayjs.utc(date).startOf('day').toDate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const startTime = endTime.subtract(1, 'day');
_payload.addresses.concat( | ||
dailyAddresses | ||
.filter((event) => | ||
Utils.isValidAccountAddress( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO cần tính xem chỉ count address thường hay cả contract address
.insert(dailyStat) | ||
.catch((error) => { | ||
this.logger.error('Error insert new daily statistic record'); | ||
this.logger.error(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trong job ko cần bắt