Skip to content

Commit

Permalink
Merge pull request #98 from kodadot/convertoor
Browse files Browse the repository at this point in the history
Average BigInt is my best friend
  • Loading branch information
vikiival committed Jun 13, 2022
2 parents a1208df + 0974010 commit e859dc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
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

0 comments on commit e859dc0

Please sign in to comment.