Skip to content

Commit

Permalink
nicer error page so it's not lightmode and blinding
Browse files Browse the repository at this point in the history
  • Loading branch information
spookybear0 committed Jul 12, 2024
1 parent 7abe0e0 commit 5ca17aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions handlers/errors/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br> Please contact the administrator if the problem persists."

return await render_template(request, "errors/500.html", description=description)

Expand Down
18 changes: 17 additions & 1 deletion helpers/ratinghelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5ca17aa

Please sign in to comment.