From 5ca17aa024aac79a6d744f71b2913fca571a7d93 Mon Sep 17 00:00:00 2001 From: spookybear0 <50897638+spookybear0@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:47:20 -0700 Subject: [PATCH] nicer error page so it's not lightmode and blinding --- handlers/errors/errors.py | 7 ++++--- helpers/ratinghelper.py | 18 +++++++++++++++++- web.py | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/handlers/errors/errors.py b/handlers/errors/errors.py index 7ad23bd..f9c30fb 100644 --- a/handlers/errors/errors.py +++ b/handlers/errors/errors.py @@ -12,10 +12,11 @@ async def notfound(request: Request, exception: Exception) -> str: return await render_template(request, "errors/404.html", description=description) -@app.exception(ServerError) +@app.exception(ServerError, Exception) async def servererror(request: Request, exception: Exception) -> str: - description = exception.args[ - 0] if exception.args else "The server encountered an internal error and was unable to complete your request." + #description = exception.args[ + # 0] if exception.args else "The server encountered an internal error and was unable to complete your request." + description = "The server encountered an internal error and was unable to complete your request.

Please contact the administrator if the problem persists." return await render_template(request, "errors/500.html", description=description) diff --git a/helpers/ratinghelper.py b/helpers/ratinghelper.py index a1ee41e..b82d5ae 100644 --- a/helpers/ratinghelper.py +++ b/helpers/ratinghelper.py @@ -388,6 +388,22 @@ def evaluate_teams(teams): return best_teams def get_best_roles_for_teams(teams: List[List[Player]]) -> List[List[IntRole]]: + """ + Gets the best roles for a list of teams + + Algorithm: + + 1. Assign unique roles (commander, heavy, ammo, medic) to the players with the highest rating for that role + 2. Assign the remaining players as scouts + 3. (if using the matchmaker) shuffle the players and repeat the process until the best combination is found + + + Possible improvements: + - Consider how well resupply combos work together + - Consider giving players their preferred roles + - Consider giving players roles that they haven't played often for variety + """ + best_roles = [] roles = [IntRole.COMMANDER, IntRole.HEAVY, IntRole.AMMO, IntRole.MEDIC, IntRole.SCOUT] @@ -447,7 +463,7 @@ def evaluate_teams(teams, roles): best_roles = get_best_roles_for_teams(best_teams) best_fairness = evaluate_teams(best_teams, best_roles) - for _ in range(1000): + for _ in range(5000): random.shuffle(players) current_teams = [players[i::num_teams] for i in range(num_teams)] current_roles = get_best_roles_for_teams(current_teams) diff --git a/web.py b/web.py index 267d211..d2b4b4c 100644 --- a/web.py +++ b/web.py @@ -96,7 +96,7 @@ async def main() -> None: Start the server in a development/nonprod environment. """ app.ctx.sql = await MySQLPool.connect_with_config() - app.ctx.banner = {"text": "Rating recalculation in progress, stats may be inaccurate", "type": None} + app.ctx.banner = {"text": "", "type": None} app.ctx.banner_type_to_color = utils.banner_type_to_color await Tortoise.init(