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

How are we suppose to use this library with a local dataset? #113

Open
JohnCarp opened this issue Jan 28, 2023 · 1 comment
Open

How are we suppose to use this library with a local dataset? #113

JohnCarp opened this issue Jan 28, 2023 · 1 comment

Comments

@JohnCarp
Copy link

JohnCarp commented Jan 28, 2023

I pulled this code down and have been very confused with the documentation on how to run it on a local data set. I'm looking at this piece of code below.

I have a CSV which has all the asset names along with the occurrences. What do I need to do to feed this data to calculate the rarities? Is it possible to just feed a dictionary with all the assets at once?

If you can show me an example of what I need to do that would be great!

Thank you!

from open_rarity import Collection, OpenRarityScorer, Token
from open_rarity.rarity_ranker import RarityRanker

if __name__ == "__main__":
    scorer = OpenRarityScorer()

    collection = Collection(
        name="My Collection Name",
        tokens=[
            Token.from_erc721(
                contract_address="0xa3049...",
                token_id=1,
                metadata_dict={"hat": "cap", "shirt": "blue"},
            ),
            Token.from_erc721(
                contract_address="0xa3049...",
                token_id=2,
                metadata_dict={"hat": "visor", "shirt": "green"},
            ),
            Token.from_erc721(
                contract_address="0xa3049...",
                token_id=3,
                metadata_dict={"hat": "visor", "shirt": "blue"},
            ),
        ],
    )  # Replace inputs with your collection-specific details here

    # Generate scores for a collection
    token_scores = scorer.score_collection(collection=collection)

    print(f"Token scores for collection: {token_scores}")

    # Generate score for a single token in a collection
    token = collection.tokens[0]  # Your token details filled in
    token_score = scorer.score_token(collection=collection, token=token)

    # Better yet.. just use ranker directly!
    ranked_tokens = RarityRanker.rank_collection(collection=collection)
    for ranked_token in ranked_tokens:
        print(
            f"Token {ranked_token.token} has rank {ranked_token.rank} "
            "and score {ranked_token.score}"
        )
@impreso
Copy link
Contributor

impreso commented Feb 7, 2023

Hi! You can definitely read CSV and create list of Tokens with required fields and then use the scorrer interface to produce collection ranks. Can you share CSV file, i could drop python snippet to help you.

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