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

Automate (former) champion badges #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tsunyoku
Copy link
Contributor

@tsunyoku tsunyoku commented Dec 7, 2024

One day I'd love for score submission to be split into components and be able to do this event-based, but this is still better than manual for now.

This will be a requirement for full-stack automation of the badge as I'd like to automate the Discord roles as well via the new Discord linking functionality.

main.py Show resolved Hide resolved
main.py Outdated
)

# user_badges has no unique key on (user, badge) so we have to check manually :(
existing_former_champion_badge = await db.fetch(
Copy link
Member

Choose a reason for hiding this comment

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

var is named former_champion but it's checking against CHAMPION_BADGE_ID?

Copy link
Member

@cmyui cmyui Dec 9, 2024

Choose a reason for hiding this comment

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

nit: it's probably best to use INSERT INTO ... IF NOT EXISTS ... ELSE UPDATE or w/e to make it one query, if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not possible due to the lack of unique constraint since that's how it decides if it "exists" or would conflict etc. - needs to be resolved on the table layer first

Copy link
Contributor Author

Choose a reason for hiding this comment

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

var is named former_champion but it's checking against CHAMPION_BADGE_ID?

note to self: don't trust F2

)

current_rank_one_user_id = await redis.zrevrange(rank_key, 0, 0)
users_who_peaked_at_rank_one.append({"user_id": current_rank_one_user_id})
Copy link
Member

@cmyui cmyui Dec 9, 2024

Choose a reason for hiding this comment

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

is this fetched separately to guard against the case where the #1 is not yet inserted into user_profile_history? (iirc the job runs nightly?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the API endpoint that the website uses to fetch peak rank does similar functionality (fetches peak from database and also current, takes whichever is lower)

# this is updated in a cron so we need to also check current rank one
users_who_peaked_at_rank_one = list(
await db.fetchall(
"SELECT DISTINCT user_id FROM user_profile_history WHERE mode = %s AND `rank` = 1",
Copy link
Member

Choose a reason for hiding this comment

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

Could you check how many users are going to receive a badge that don't currently have it, from the switch from manual -> auto based on user_profile_history data?

Copy link
Member

@cmyui cmyui Dec 9, 2024

Choose a reason for hiding this comment

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

I think there's a bit to consider here re. cases where someone cheated their way to #1 then got banned/unbanned -- I think this system would grant them the "former champion" badge in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's a bit to consider here re. cases where someone cheated their way to #1 then got banned/unbanned

if we're not wiping this table when wiping a user for an unban then that's an issue in it's own way - that would mean their peak rank on their profile would already appear as whatever they peaked while cheating 😳

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.

2 participants