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

Calculate rarity score per ERC-721 items #12

Open
vikiival opened this issue Jul 9, 2022 · 3 comments
Open

Calculate rarity score per ERC-721 items #12

vikiival opened this issue Jul 9, 2022 · 3 comments

Comments

@vikiival
Copy link
Member

vikiival commented Jul 9, 2022

for ERC-721 add

rarity: Float!

after create was called:

  • check if you indexed max
  • calculate rarity on last fetched item

ref

articles:

@vikiival
Copy link
Member Author

First we need to change attribute schema from JSON to actual entity.

However it is hackable to do so via view

CREATE OR REPLACE view trait_list as
select
    x.acc ->> 'trait' trait,
    x.acc ->> 'value' "value",
    m.id
from metadata_entity m
cross join lateral jsonb_array_elements(m.attributes) as x(acc);

to get counts for attributes simply run

SELECT
    trait,
    value,
    count(value)
FROM
    trait_list
GROUP BY
    GROUPING SETS (
        (trait),
        (trait, value)
    );

this will tell you the counts for each trait-value and also total for each trait

to sum it up:

select
       trait,
       value,
       count(value),
       ROUND((count(value) / sum(count(value)) over (partition by trait)) * 100, 2) as rarity
    from trait_list
group by trait, value
order by value;

this will return:

  • trait: hat,
  • value: Black Unicorn
  • count: 24
  • rarity: count / total * 100 -> 5.02%

then we need to basically for each NFT calculate the avg rarity ∑(rarities) / trait_count

@vikiival
Copy link
Member Author

This is imo most effective way to calculate it, may @dzlzv can have an opinion since he has PhD from math ;D

@yangwao
Copy link
Member

yangwao commented Sep 21, 2022

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

No branches or pull requests

2 participants