Skip to content

Commit

Permalink
Merge pull request #4 from near-daos/feature/leaderboard_overview_month
Browse files Browse the repository at this point in the history
Using month as a timespan for leaderboard overview
  • Loading branch information
andkom authored Jan 17, 2022
2 parents b9b20eb + 4dd5e8d commit 97d0456
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/common/metric.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class MetricService {
const { contractId } = context;

const dayAgo = moment().subtract(1, 'day');
const weekAgo = moment().subtract(1, 'week');
const monthAgo = moment().subtract(1, 'month');

const leaderboard = await this.daoStatsService.getLeaderboard({
contractId,
Expand All @@ -109,7 +109,7 @@ export class MetricService {
contractId,
dao,
metric,
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
}),
]);

Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/flow/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export class FlowService {
): Promise<FlowLeaderboardMetricResponse> {
const { contract } = context;

const weekAgo = moment().subtract(7, 'days');
const days = getDailyIntervals(weekAgo.valueOf(), moment().valueOf());
const monthAgo = moment().subtract(1, 'month');
const days = getDailyIntervals(monthAgo.valueOf(), moment().valueOf());
const dayAgo = moment().subtract(1, 'days');

const [
Expand All @@ -190,7 +190,7 @@ export class FlowService {
metricType,
TransferType.Incoming,
{
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
to: moment().valueOf(),
},
true,
Expand All @@ -200,7 +200,7 @@ export class FlowService {
metricType,
TransferType.Outgoing,
{
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
to: moment().valueOf(),
},
true,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/general/general.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ export class GeneralService {
async activeLeaderboard(
context: ContractContext,
): Promise<LeaderboardMetricResponse> {
const weekAgo = moment().subtract(7, 'days');
const days = getDailyIntervals(weekAgo.valueOf(), moment().valueOf());
const monthAgo = moment().subtract(1, 'month');
const days = getDailyIntervals(monthAgo.valueOf(), moment().valueOf());

const byDays = await this.transactionService.getActivityLeaderboard(
context,
{
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
to: moment().valueOf(),
},
true,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/governance/governance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class GovernanceService {
const { contractId, dao } = context as DaoContractContext;

const dayAgo = moment().subtract(1, 'days');
const weekAgo = moment().subtract(7, 'days');
const monthAgo = moment().subtract(30, 'month');

const [totalLeaderboard, approvedLeaderboard] = await Promise.all([
this.daoStatsService.getLeaderboard({
Expand Down Expand Up @@ -376,13 +376,13 @@ export class GovernanceService {
contractId,
dao,
metric: DaoStatsMetric.ProposalsCount,
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
}),
this.daoStatsHistoryService.getHistory({
contractId,
dao,
metric: DaoStatsMetric.ProposalsApprovedCount,
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
}),
]);

Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export class UsersService {
async usersLeaderboard(
context: ContractContext,
): Promise<LeaderboardMetricResponse> {
const weekAgo = moment().subtract(7, 'days');
const days = getDailyIntervals(weekAgo.valueOf(), moment().valueOf());
const monthAgo = moment().subtract(1, 'month');
const days = getDailyIntervals(monthAgo.valueOf(), moment().valueOf());

const { results: byDays, errors } = await PromisePool.withConcurrency(5)
.for(days)
Expand Down Expand Up @@ -249,15 +249,15 @@ export class UsersService {
async interactionsLeaderboard(
context: ContractContext,
): Promise<LeaderboardMetricResponse> {
const weekAgo = moment().subtract(7, 'days');
const days = getDailyIntervals(weekAgo.valueOf(), moment().valueOf());
const monthAgo = moment().subtract(1, 'month');
const days = getDailyIntervals(monthAgo.valueOf(), moment().valueOf());
const dayAgo = moment().subtract(1, 'days');

const [byDays, dayAgoActivity, totalActivity] = await Promise.all([
this.transactionService.getActivityLeaderboard(
context,
{
from: weekAgo.valueOf(),
from: monthAgo.valueOf(),
to: moment().valueOf(),
},
true,
Expand Down

0 comments on commit 97d0456

Please sign in to comment.