-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tymescaledb config * Add analytics cron job * Update analytics job * Add timescale migrations * Save data into postgress * Update migrations * Add analytics resolver * Update migrations * Add hour to data api get price * Upgrade dependencies * add analytics indexer * Revert admin resolvers * Merge trending analytics with analytics * Remove commented code * increase batch logs * Update analytics Indexer * Clean up logs * remove duplicate case * Fix mapping for unknown prices * Undo commented configs * Analytics * Add logging * Add handle for buy now * Fix buy now events * Fix single event indexing * Add bid event to index * fix compile error * Fix indexer duplicates * Add date logs * Change timestamp saving * more logs * Fix timestamp saving * Analytics ectract methods * Add queries analytics * Clean up tools service * revert explore stats changes * Update stats resolver * Add caching layer * Delete unused service * Update naming * Remove empty lines * Update formating * Update general analyticsQuery * Remove nullable for resolve fields params * Update graphql schema * Add collections analytics resolver * Update collections resolver * Add config for public api * Add volume data for collection query * Update volume data fields * Clean up queries * Change views names * Update typeorm configs * Update typeorm to use config service * remove unused fields * Update Aggregate value * Save floor price also for analytics * Add null check * Remove purchase event * Log error and return empty * Add logging * Add max value check for floor price * Rename analytics parser * Code review follow up * Add floor price data volume * When search by identifier return 0 for sum * Change name from sum to value * Update floor price analytics * Fix floor price view * Add locf and rename function * Add change listing and price indexing * Clean up unused functions for analytics * Update AggregateValue to map object from timescale * remove unused dependency * Add analytics data getter tests * Add data setter tests * Rename tests * Update testing module scope * Trigger build
- Loading branch information
1 parent
e394ed4
commit 0b0f0f1
Showing
94 changed files
with
4,423 additions
and
1,266 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import BigNumber from 'bignumber.js'; | ||
import { AnalyticsService } from './modules/analytics/analytics.service'; | ||
import { AnalyticsModule } from './modules/analytics/analytics.module'; | ||
|
||
export async function run(startDateUtc: string, endDateUtc: string) { | ||
BigNumber.config({ EXPONENTIAL_AT: [-100, 100] }); | ||
const app = await NestFactory.create(AnalyticsModule); | ||
const analyticsService = app.get<AnalyticsService>(AnalyticsService); | ||
await analyticsService.indexAnalyticsLogs( | ||
parseInt(startDateUtc), | ||
parseInt(endDateUtc), | ||
); | ||
return process.exit(0); | ||
} | ||
|
||
run(process.argv[2], process.argv[3]); |
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
104 changes: 104 additions & 0 deletions
104
src/common/persistence/timescaledb/analytics-data.getter.service.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,104 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { computeTimeInterval } from 'src/utils/analytics.utils'; | ||
import { AnalyticsArgs } from './entities/analytics.query'; | ||
import { FloorPriceDaily, SumDaily } from './entities/sum-daily.entity'; | ||
import { AnalyticsAggregateValue } from 'src/modules/analytics/models/analytics-aggregate-value'; | ||
|
||
@Injectable() | ||
export class AnalyticsDataGetterService { | ||
constructor( | ||
@InjectRepository(SumDaily, 'timescaledb') | ||
private readonly sumDaily: Repository<SumDaily>, | ||
@InjectRepository(FloorPriceDaily, 'timescaledb') | ||
private readonly floorPriceDaily: Repository<FloorPriceDaily>, | ||
) {} | ||
|
||
async getTopCollectionsDaily( | ||
{ metric, series }: AnalyticsArgs, | ||
limit: number = 10, | ||
offset: number = 0, | ||
): Promise<[AnalyticsAggregateValue[], number]> { | ||
const query = this.sumDaily | ||
.createQueryBuilder() | ||
.select('sum(sum) as value') | ||
.addSelect('series') | ||
.addSelect('time') | ||
.andWhere('key = :metric', { metric }) | ||
.andWhere(`time between now() - INTERVAL '1 day' and now()`) | ||
.orderBy('sum', 'DESC') | ||
.groupBy('series, sum, time'); | ||
if (series) { | ||
query.andWhere('series = :series', { series }); | ||
} | ||
const [response, count] = await Promise.all([ | ||
query.offset(offset).limit(limit).getRawMany(), | ||
query.getCount(), | ||
]); | ||
if (series && count === 0) { | ||
return [[new AnalyticsAggregateValue({ value: 0, series: series })], 1]; | ||
} | ||
|
||
return [ | ||
response?.map((row) => | ||
AnalyticsAggregateValue.fromTimescaleObjext(row), | ||
) ?? [], | ||
count ?? 0, | ||
]; | ||
} | ||
|
||
async getVolumeData({ | ||
time, | ||
series, | ||
metric, | ||
start, | ||
}: AnalyticsArgs): Promise<AnalyticsAggregateValue[]> { | ||
const [startDate, endDate] = computeTimeInterval(time, start); | ||
const query = await this.sumDaily | ||
.createQueryBuilder() | ||
.select("time_bucket_gapfill('1 day', time) as timestamp") | ||
.addSelect('sum(sum) as value') | ||
.where('key = :metric', { metric }) | ||
.andWhere('series = :series', { series }) | ||
.andWhere( | ||
endDate ? 'time BETWEEN :startDate AND :endDate' : 'time >= :startDate', | ||
{ startDate, endDate }, | ||
) | ||
.orderBy('timestamp', 'ASC') | ||
.groupBy('timestamp') | ||
.getRawMany(); | ||
|
||
return ( | ||
query?.map((row) => AnalyticsAggregateValue.fromTimescaleObjext(row)) ?? | ||
[] | ||
); | ||
} | ||
|
||
async getFloorPriceData({ | ||
time, | ||
series, | ||
metric, | ||
start, | ||
}: AnalyticsArgs): Promise<AnalyticsAggregateValue[]> { | ||
const [startDate, endDate] = computeTimeInterval(time, start); | ||
const query = await this.floorPriceDaily | ||
.createQueryBuilder() | ||
.select("time_bucket_gapfill('1 day', time) as timestamp") | ||
.addSelect('locf(min(min)) as value') | ||
.where('key = :metric', { metric }) | ||
.andWhere('series = :series', { series }) | ||
.andWhere( | ||
endDate ? 'time BETWEEN :startDate AND :endDate' : 'time >= :startDate', | ||
{ startDate, endDate }, | ||
) | ||
.orderBy('timestamp', 'ASC') | ||
.groupBy('timestamp') | ||
.getRawMany(); | ||
|
||
return ( | ||
query?.map((row) => AnalyticsAggregateValue.fromTimescaleObjext(row)) ?? | ||
[] | ||
); | ||
} | ||
} |
Oops, something went wrong.