Skip to content
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

Merged
merged 22 commits into from
Jul 27, 2023
Merged

feat: statistics #248

merged 22 commits into from
Jul 27, 2023

Conversation

andqk00
Copy link
Contributor

@andqk00 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

@andqk00 andqk00 requested a review from peara July 7, 2023 04:14
Event.EVENT_TYPE.COIN_RECEIVED,
Event.EVENT_TYPE.USE_FEEGRANT,
])
.orWhereIn('events:attributes.key', [
Copy link
Member

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: [],
Copy link
Member

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;
Copy link
Member

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',
Copy link
Member

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 = {
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

@peara peara Jul 20, 2023

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);
Copy link
Member

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: {},
Copy link
Member

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();
Copy link
Member

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(
Copy link
Member

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);
Copy link
Member

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

@peara peara merged commit c845293 into main Jul 27, 2023
2 checks passed
@peara peara deleted the feat/statistics branch July 27, 2023 08:10
@peara peara restored the feat/statistics branch July 28, 2023 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants