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

Leaderboard metadata #968

Merged
merged 6 commits into from
Jan 30, 2024
Merged

Leaderboard metadata #968

merged 6 commits into from
Jan 30, 2024

Conversation

Andrei-Dolgolev
Copy link
Contributor

@Andrei-Dolgolev Andrei-Dolgolev commented Nov 9, 2023

Leaderboards db model was extended by additional fields

blockchain_ids - array of ids which blockchain that leaderboard include
wallet_connect - show metamask connect on leaderboard (in case if address field is wallet address)
columns_names - dict of mapping for column names if it not empty then will use LeaderboardUnformattedPosition reponse model.

new model:

class LeaderboardUnformattedPosition(BaseModel):
    column_1: str = Field(serialization_alias="address")
    column_2: int = Field(serialization_alias="rank")
    column_3: int = Field(serialization_alias="score")
    column_4: Dict[str, Any] = Field(serialization_alias="points_data")

    class Config:
        orm_mode = True

If used that model client must look in columns_names of leaderboard/info endpoint for get correct names of each fields as well as extract keys.

If use change just 1 field columns_names : {"address": "token_id} then column_names will transform to that structure.

{
   "column_1": "rank",
   "column_2": "token_id",
   "column_3": "score",
   "column_4": "points_data"
}

Testing requests.

GET leaderboards Authorized Endpoints

GET http://127.0.0.1:7191/leaderboard/leaderboards
Authorization: Bearer <token>

Create Leaderboard Authorized Endpoints

POST http://127.0.0.1:7191/leaderboard/
Authorization: Bearer <token>

{
  "title": "Test columnnames",
  "description": "U2NvcmluZzoKKiBVcGdyYWRlLCBkZXBlbmRpbmcgb24gcmFyaXR5ICh1bmNvbW1vbiB1cGdyYWRlcyB3b3J0aCA2NSBwb2ludHMsIHJhcmUgOTUsIGVwaWMgMTU1LCBsZWdlbmRhcnkgMzAwKQoqIE9wZW5pbmcgY2hlc3QKICAgICogR29sZCA9IDFwCiAgICAqIE1hZ2ljYWwgPSAxMHAKICAgICogTGVnZW5kYXJ5IFJveWFsID0gMzVwCiAgICAqIFVsdHJhIFN1cHJlbWUgPSAxMjBwCiogR2V0dGluZyBhIHNoYXJkLCAyIHBvaW50IGZvciB1bmNvbW1vbiwgMyBwb2ludCBmb3IgcmFyZSwgNSBwb2ludCBmb3IgZXBpYywgMTAgcG9pbnQgZm9yIGxlZ2VuZGFyeS4KKiBHZXR0aW5nIGVxdWlwbWVudCwgNzAgcG9pbnQgZm9yIHVuY29tbW9uLCAxMDAgcG9pbnQgZm9yIHJhcmUsIDE4MCBwb2ludCBmb3IgZXBpYywgMzUwIHBvaW50IGZvciBsZWdlbmRhcnkuCiogR2V0dGluZyBhbiBhcnRpZmFjdCwgMzAgcG9pbnQgZm9yIHVuY29tbW9uLCA0MCBwb2ludCBmb3IgcmFyZSwgODAgcG9pbnQgZm9yIGVwaWMsIDE2MCBwb2ludCBmb3IgbGVnZW5kYXJ5Lg==",
  "columns_names": {
    "address": "token_id"
  }
}

Get scores

<leaderboard_id> 404 not found public is False

GET http://127.0.0.1:7191/leaderboard/?leaderboard_id=<leaderboard_id>

Update leaderboard endpoint

make it public

PUT http://127.0.0.1:7191/leaderboard/<leaderboard_id>
Authorization: Bearer <token>
Content-Type: application/json

{
  "public": true
}

Get scores

GET http://127.0.0.1:7191/leaderboard/?leaderboard_id=<leaderboard_id>

Push scores

PUT http://127.0.0.1:7191/leaderboard/<leaderboard_id>/scores?overwrite=true
Authorization: Bearer <token>
Content-Type: application/json

[
  {
            "address": "0x0000000000000000000000000000000000000000",
            "score": 200000000,
            "points_data": {
                "breeding": 100000000,
                "hatchingEggs": 100000000
        }
   }
]

Get scores

must see column_1 and etc because column_names not empty

GET http://127.0.0.1:7191/leaderboard/?leaderboard_id=<leaderboard_id>

Quartiles

GET http://127.0.0.1:7191/leaderboard/quartiles?leaderboard_id=<leaderboard_id>

Position

GET http://127.0.0.1:7191/leaderboard/position?leaderboard_id=<leaderboard_id>&address=0x0000000000000000000000000000000000000000

Rank

GET http://127.0.0.1:7191/leaderboard/rank?leaderboard_id=<leaderboard_id>&rank=1

Ranks

GET http://127.0.0.1:7191/leaderboard/ranks?leaderboard_id=<leaderboard_id>

Migration plan

  • Run database migration.
./alembic.sh -c alembic.prod-conf.ini upgrade head
  • merge that PR.

  • Run engine api deployment.

@Andrei-Dolgolev Andrei-Dolgolev linked an issue Nov 16, 2023 that may be closed by this pull request
Copy link
Contributor

@kompotkot kompotkot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments

@@ -370,6 +380,10 @@ class Leaderboard(BaseModel):
title: str
description: Optional[str] = None
resource_id: Optional[UUID] = None
public: Optional[bool] = False
wallet_connect: Optional[bool] = False
blockchain_ids: Optional[List[int]] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to store as empty list [] instead of None?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for Optional[List[int]] = None below

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because default in postgres default=[]

@@ -346,6 +347,11 @@ class Leaderboard(Base): # type: ignore
title = Column(VARCHAR(128), nullable=False)
description = Column(String, nullable=True)
resource_id = Column(UUID(as_uuid=True), nullable=True, index=True)
blockchain_ids = Column(ARRAY(Integer), nullable=False, default=[])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sugest also add sort for add and update values to this list, so it always will be readable, for example when query returns few result:

    id               blockchain_ids
<uuid1>             80001, 1
<uuid2>             1, 80001

@Andrei-Dolgolev Andrei-Dolgolev changed the title Add migration and endpoints changes. Leaderboard metadata Dec 5, 2023
@Andrei-Dolgolev Andrei-Dolgolev merged commit b2e67ff into main Jan 30, 2024
1 check failed
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

Successfully merging this pull request may close these issues.

Add leaderboard metadata
2 participants