Skip to content

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

@JohnCarp

Description

@JohnCarp

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}"
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions