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

Add leaderboard stats, periodic updates via fastapi-utils #724

Merged
merged 6 commits into from
Jan 15, 2023

Conversation

andreaskoepf
Copy link
Collaborator

@andreaskoepf andreaskoepf commented Jan 15, 2023

Provide new leaderboard REST endpoints:
/api/v1/leaderboards/{day,week,month,total}

Example response:

{
  "time_frame": "day",
  "leaderboard": [
    {
      "user_rank": 0,
      "user_id": "38312e49-8cd6-4e7c-8bad-c626e452b1e7",
      "username": "__dummy_user__",
      "auth_method": "local",
      "display_name": "Dummy User",
      "leader_score": 2740,
      "base_date": "2023-01-14T00:42:14.937437",
      "modified_date": "2023-01-15T00:42:14.937534",
      "prompts": 74,
      "replies_assistant": 261,
      "replies_prompter": 109,
      "labels_simple": 0,
      "labels_full": 0,
      "rankings_total": 0,
      "rankings_good": 0,
      "accepted_prompts": 74,
      "accepted_replies_assistant": 261,
      "accepted_replies_prompter": 109,
      "reply_ranked_1": 22,
      "reply_ranked_2": 22,
      "reply_ranked_3": 22,
      "streak_last_day_date": null,
      "streak_days": null
    }
}

Copy link
Collaborator

@yk yk left a comment

Choose a reason for hiding this comment

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

awesome

def compute_leader_score(self) -> int:
return (
self.prompts
+ self.replies_assistant * 4
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about making these constants into settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to find a "stable" formula for the leader-score .. calculation is "magic" right now .. the exact way how to calculate it needs more discussion, e.g. could be based on acceptance rations or include negative values..



def log_timing(func):
def wrapped(*args, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

just for prettiness, could use functools.wraps

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made it now a param + non-param decorator .. with optional logging of the kwargs. regarding functool.wraps ..that makes sure that docstring and function name are preserved .. right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, it's just for clarity

# ### end Alembic commands ###


def downgrade() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

the upgrade drops and recreates the user_stats table, while the downgrade just modifies the columns. it's probably fine though

Copy link
Collaborator Author

@andreaskoepf andreaskoepf Jan 15, 2023

Choose a reason for hiding this comment

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

Yes, intentionally. Somehow alembic didn't manage it to add a second column to the PK as a change, e.g. this table has a combined user_id + time_frame PK and before had only user_id. The table wasn't used before...

@andreaskoepf andreaskoepf merged commit b5bb5bb into main Jan 15, 2023
@andreaskoepf andreaskoepf deleted the 713_gamification_layer branch January 15, 2023 11:04
@andreaskoepf andreaskoepf restored the 713_gamification_layer branch January 15, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants