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

Average BigInt is my best friend #98

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type Collector @entity {
uniqueCollectors: Int!
collections: Int!
total: Int!
average: BigInt
average: Float
volume: BigInt @index
max: BigInt
}
Expand Down
36 changes: 21 additions & 15 deletions src/mappings/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,34 @@ enum Query {
GROUP BY ce.id, me.image, ce.name`,

spotlight = `SELECT
issuer as id, COUNT(distinct collection_id) as collections,
COUNT(distinct meta_id) as unique, AVG(price) as average,
COUNT(*) as total, COUNT(distinct ne.current_owner) as unique_collectors,
issuer as id,
COUNT(distinct collection_id) as collections,
COUNT(distinct meta_id) as unique,
AVG(price) as average,
COUNT(*) as total,
COUNT(distinct ne.current_owner) as unique_collectors,
SUM(CASE WHEN ne.issuer <> ne.current_owner THEN 1 ELSE 0 END) as sold,
COALESCE(SUM(e.meta::bigint), 0) as volume
FROM nft_entity ne
JOIN event e on e.nft_id = ne.id WHERE e.interaction = 'BUY'
GROUP BY issuer`,

collector_whale = `SELECT
ne.current_owner as id, ne.current_owner as name,
COUNT(distinct collection_id) as collections,
COUNT(distinct meta_id) as unique,
AVG(e.meta::bigint) as average,
COUNT(*) as total,
COUNT(ne.current_owner) as unique_collectors,
COALESCE(SUM(e.meta::bigint), 0) as volume,
COALESCE(MAX(e.meta::bigint), 0) as max
FROM nft_entity ne
JOIN event e on e.nft_id = ne.id WHERE e.interaction = 'BUY'
GROUP BY ne.current_owner
LIMIT 100 OFFSET 0`,
ne.current_owner as id,
ne.current_owner as name,
COUNT(distinct collection_id) as collections,
COUNT(distinct meta_id) as unique,
AVG(e.meta::bigint) as average,
COUNT(e.id) as total,
COUNT(ne.current_owner) as unique_collectors,
COALESCE(SUM(e.meta::bigint), 0) as volume,
COALESCE(MAX(e.meta::bigint), 0) as max
FROM nft_entity ne
JOIN event e on e.nft_id = ne.id
WHERE e.interaction = 'BUY'
GROUP BY ne.current_owner
ORDER BY volume DESC
LIMIT 100`,

}

Expand Down
4 changes: 2 additions & 2 deletions src/model/generated/collector.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class Collector {
@Column_("int4", {nullable: false})
total!: number

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
average!: bigint | undefined | null
@Column_("numeric", {nullable: true})
average!: number | undefined | null

@Index_()
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
Expand Down