FingerLakesRunnersClub / Leaderboards

Leaderboards for the FLRC Challenge and Trail Circuit
https://fingerlakesrunners.org
GNU General Public License v3.0
0 stars 0 forks source link

Automatically populate age-group and @Challengers lists in Discourse from registrant info #145

Closed adamengst closed 1 year ago

adamengst commented 1 year ago

As the race director, I spend a stupid amount of time adding people to the @Challengers group in Discourse and to the @Fabulous-50s and other age-group-based groups. It would be a huge win if the leaderboard code could populate those groups automatically based on the participant's age and email. No idea what the DIscourse API allows here.

If it can match to an existing user's email address, that's a partial win, and if it could invite people who aren't on Discourse yet, that would be a complete win.

Thanks!

SteveDesmond-ca commented 1 year ago

I'll need to dig into the Discourse API docs to know for sure, but my initial guess is that this is pretty pie in the sky. I'd hope at the very least we can get a list of unmatched individuals, so there's no manual reconciliation necessary every time you're trying to mentally sync the lists.

adamengst commented 1 year ago

Happy to brainstorm other solutions to the problem. As it stands, I have to keep downloading the reg list from Webscorer, trying to remember where I last stopped, and then manually add the people to both @Challengers and their age-group group. And if they're not in Discourse at all, I have to invite their email address to @Challengers and remember to go back and add them to the age-group group once (if) they accept the invite.

SteveDesmond-ca commented 1 year ago

OK, this should be mostly doable now that I've actually taken a look at what's possible, though I'll need an admin API key to be able to get the list of all Discourse users:

  1. The groups will already need to exist, and will need the IDs of each to put in the config file, though I think that's just their hyphenated name
  2. We're already matching on the user's name for community stars, since email isn't readily available through the API, so can do the same here
  3. The API allows viewing a group's members (see https://forum.fingerlakesrunners.org/g/Challengers/members.json?limit=1000) and adding members to a group, so we automatically sync these where the user's names match, and output a list of who's left, or have a single button to add someone who's not there yet
  4. As for invites, there is an API call for that, but we're not storing state anywhere in this app, so it'd end up spamming them until they sign up (maybe that's what you want? :smiling_imp:) -- I think just having a list of people without name matches would allow you to look up their email in WebScorer to send a Discourse invite easily enough? (this will probably be implemented as a hidden admin page, but I'd still rather not expose email addresses to the Internet)
adamengst commented 1 year ago

Woo, that's great!

The groups do exist, and all that needs to be done is to clear out last year's people.

A list of people without name matches should be good enough—it won't be hard to invite them once. And after several years of this, there shouldn't be too many. But tempting to DoS them with invitations. 😈

SteveDesmond-ca commented 1 year ago

Getting started on this before Challenge registrations get too far underway -- @adamengst, could you create an admin API key for either your forum user or a new "API only" admin user, and send via some semi-secure method?

SteveDesmond-ca commented 1 year ago

@adamengst Also it looks like the forum's age group team groups for last year got deleted. Will the new ones have the same names?

    "CommunityTeams": {
        "2": "Terrific-20s-Teens",
        "3": "Thundering-30s",
        "4": "Fantastic-40s",
        "5": "Fabulous-50s",
        "6": "Super-60s-70s"
    }
adamengst commented 1 year ago

FYI, looks like you had an API key from last year. I've created a new one with these settings:

Music 2023-04-06 at 16 57 51

Here's a single-use link to it:

https://1ty.me/3JbHDDE

Those groups are still present, but I suspect you can't see them because you're not an admin, so I've made you one. If nothing else, best to have another highly technical person with permissions. I think you have the names right, but copying and pasting to be sure:

Terrific-20s-Teens Thundering-30s Fantastic-40s Fabulous-50s Super-60s-70s

SteveDesmond-ca commented 1 year ago

Thanks for the API key / admin access, this is coming along nicely but I'm hitting the wall so hoping to finish it up this weekend.

Screenshot of work-in-progress using real 2022 data: image

adamengst commented 1 year ago

Very cool! Do you need me to clear out those groups from last year too?

SteveDesmond-ca commented 1 year ago

If you could leave them for now, I'm doing some manual testing and debugging with myself -- thanks!

SteveDesmond-ca commented 1 year ago

Heads up @scottpdawson, I'm using us as guinea pigs for testing this batch functionality -- can't use @adamengst since he's an owner...apologies if you get any forum notifications about being added/removed from the Challenge groups!

SteveDesmond-ca commented 1 year ago

Implemented as of 23d82ba, waiting until tonight to deploy given the high traffic of opening morning

SteveDesmond-ca commented 1 year ago

@adamengst Could you clear all the Challenge forum groups at some point this evening (or earlier is fine if you don't mind them being empty for a bit) so I can run through the first round of sync'ing as a load/stress test? And then once I deploy I can hand it over to you to sync away at your leisure.

adamengst commented 1 year ago

OK, all the groups are now empty. If only I'd found the bulk delete UI before deleting them one at a time. ;-)

SteveDesmond-ca commented 1 year ago

That was way faster and easier than I expected it to go first time -- at least one of the new features went that way!