From 1afa86506be468a29e3e5c8b5ed8c5b92e24c275 Mon Sep 17 00:00:00 2001 From: ebo Date: Tue, 7 May 2024 21:33:13 -0700 Subject: [PATCH] Ran the entire codebase through the Linter. The Python code should now be mostly PEP compliant so the IDE no longer yells at me every time I try to submit code. Note that I rolled back most HTML changes because I actively disagree with them. It seems that the code cleanup tool doesn't handle Jinja markup very well. --- .github/workflows/python-app.yml | 38 +- README.md | 2 +- app.py | 15 +- assets/html/about.html | 35 +- assets/html/admin/player.html | 14 +- assets/html/base.html | 237 +- assets/html/game/replay.html | 2 +- assets/html/game/replay_laserball.html | 5 +- assets/html/game/replay_sm5.html | 4 +- assets/html/game/sm5_tooltips_include.html | 1 - assets/html/index.html | 3 +- assets/html/rfid.html | 10 +- assets/html/stats.html | 4 +- assets/sitemap.xml | 5008 ++++++++++---------- config.py | 2 +- db/game.py | 75 +- db/laserball.py | 101 +- db/legacy.py | 16 +- db/player.py | 166 +- db/sm5.py | 92 +- db/types.py | 32 +- handlers/about.py | 6 +- handlers/admin/backfill_events.py | 2 +- handlers/admin/game.py | 46 +- handlers/admin/games.py | 18 +- handlers/admin/index.py | 21 +- handlers/admin/player.py | 15 +- handlers/admin/players.py | 16 +- handlers/api/game.py | 19 +- handlers/api/login.py | 15 +- handlers/api/matchmake.py | 18 +- handlers/api/player.py | 15 +- handlers/api/replay_data.py | 5 +- handlers/api/win_chances.py | 18 +- handlers/errors/errors.py | 13 +- handlers/game/game.py | 37 +- handlers/game/games.py | 19 +- handlers/game/replay.py | 8 +- handlers/game/scorecard.py | 2 +- handlers/index.py | 16 +- handlers/login.py | 21 +- handlers/logout.py | 10 +- handlers/matchmaking.py | 26 +- handlers/player/player.py | 76 +- handlers/player/players.py | 28 +- handlers/rfid.py | 9 +- handlers/stats.py | 98 +- handlers/util/upload_tdf.py | 13 +- helpers/adminhelper.py | 31 +- helpers/cachehelper.py | 37 +- helpers/datehelper.py | 6 +- helpers/gamehelper.py | 6 +- helpers/laserballhelper.py | 2 +- helpers/ratinghelper.py | 88 +- helpers/replay.py | 2 +- helpers/replay_laserball.py | 2 +- helpers/replay_sm5.py | 2 +- helpers/sm5helper.py | 2 + helpers/statshelper.py | 64 +- helpers/tdfhelper.py | 283 +- helpers/tooltiphelper.py | 4 +- helpers/userhelper.py | 25 +- mysql.py | 36 +- router.py | 12 +- shared.py | 10 +- stats/ranking_demo.py | 58 +- stats/test.py | 90 +- tests/helpers/formattinghelper_test.py | 1 - tests/helpers/gamehelper_test.py | 30 +- tests/helpers/replay_test.py | 3 +- tests/helpers/statshelper_test.py | 1 - utils.py | 15 +- web.py | 12 +- 73 files changed, 3786 insertions(+), 3488 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index d6ffe8d..2d782c5 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -18,22 +18,22 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest pytest-cov - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - python -m pytest --cov=./ --cov-report=xml --cov-report=html + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + python -m pytest --cov=./ --cov-report=xml --cov-report=html diff --git a/README.md b/README.md index 1073ed2..4af87d2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # laserforce_ranking - + [![Python application](https://github.com/EboMike/laserforce_ranking/actions/workflows/python-app.yml/badge.svg)](https://github.com/EboMike/laserforce_ranking/actions/workflows/python-app.yml) diff --git a/app.py b/app.py index dc79980..876ee96 100644 --- a/app.py +++ b/app.py @@ -1,17 +1,20 @@ +import asyncio import os import sys -import asyncio -import router -from shared import app -from sanic.server.async_server import AsyncioServer -from mysql import MySQLPool import threading + import webview +from sanic.server.async_server import AsyncioServer + +import router +from mysql import MySQLPool +from shared import app path = os.path.dirname(os.path.abspath(__file__)) os.chdir(path) sys.path.append(path) + async def main(): router.add_all_routes(app) app.static("assets", "assets", name="assets") @@ -30,4 +33,4 @@ async def main(): threading.Thread(target=lambda: loop.run_until_complete(main()), daemon=True).start() webview.create_window("Test", "http://localhost:8000/") - webview.start(http_server=True) \ No newline at end of file + webview.start(http_server=True) diff --git a/assets/html/about.html b/assets/html/about.html index c705e5e..af41fc4 100644 --- a/assets/html/about.html +++ b/assets/html/about.html @@ -24,34 +24,37 @@

Website Info

- This site was made for Invasion Laser Tag members to track and compare their stats to others - while providing a more fairand balanced matchmaking system for SM5 and Laserball. - The project is made for fun but improvements will continue to be made. + This site was made for Invasion Laser Tag members to track and compare their stats to others while providing + a more fair and balanced matchmaking system for SM5 and Laserball. The project is made for fun but + improvements will continue to be made. If you have any comments or suggestions please contact me at collinmcarroll@gmail.com. - +

- Made with Python (PyPy) 3.10, sanic, jinja2, and tortoise-orm with MySql. - Ranking system uses a modified version of Microsoft's TrueSkill algorithm. + Made with Python (PyPy) 3.10, sanic, jinja2, and tortoise-orm with MySql. Ranking system uses a modified + version of Microsoft's TrueSkill algorithm.

Project Goals and Ambitions

- The goal is to create a more balanced matchmaking system for SM5 and Laserball to create more fair, fun, and competitive games. - Games where teams are evenly matched are more fun for everyone. - This project also serves as a way to track your stats and see how you compare to other players. + The goal is to create a more balanced matchmaking system for SM5 and Laserball to create more fair, fun, and + competitive games. Games where teams are evenly matched are more fun for everyone. This project also serves + as a way to track your stats and see how you compare to other players.

Matchmaking/Ranking System

- The ranking system used in this project is a modified version of the TrueSkill algorithm. It is a Bayesian ranking system that - takes into account the number of players, the number of teams, and the number of players per team. It is also used in games such as Halo 5. - For this use case, the algorithm is modified to take into account player performance for each game. The reason for this is so that - you can't just be carried by your team to a higher rank. This ranking system is used for both SM5 and Laserball to create more fair and balanced games. + The ranking system used in this project is a modified version of the TrueSkill algorithm. It is a Bayesian + ranking system that takes into account the number of players, the number of teams, and the number of players + per team. It is also used in games such as Halo 5. For this use case, the algorithm is modified to take into + account player performance for each game. The reason for this is so that you can't just be carried by your + team to a higher rank. This ranking system is used for both SM5 and Laserball to create more fair and + balanced games.

Open Source!

- This project is open source, meaning the code is free to use and modify (with the restrictions of the licensing). + This project is open source, meaning the code is free to use and modify (with the restrictions of the + licensing). You can find the code on my GitHub page here. - If you have any questions about usage or want to contribute in the form of code or suggestions, please contact me at - collinmcarroll@gmail.com. + If you have any questions about usage or want to contribute in the form of code or suggestions, please + contact me at collinmcarroll@gmail.com.

diff --git a/assets/html/admin/player.html b/assets/html/admin/player.html index 4901e55..6b90613 100644 --- a/assets/html/admin/player.html +++ b/assets/html/admin/player.html @@ -5,13 +5,13 @@ {% block html_head %} {% endblock %} diff --git a/assets/html/base.html b/assets/html/base.html index 72d5d97..a97a90d 100644 --- a/assets/html/base.html +++ b/assets/html/base.html @@ -6,106 +6,106 @@ Laserforce Ranking - {% block title %}{% endblock %} + > - + + > -{# --- Macros to use in player tables --- #} + {# --- Macros to use in player tables --- #} -{% macro sm5_role_icon(player) -%} + {% macro sm5_role_icon(player) -%} {% if player.role %} - {{ player.role }} + {{ player.role }} {% endif %} -{%- endmacro %} + {%- endmacro %} -{% macro alive_time_chart(player) -%} + {% macro alive_time_chart(player) -%} new Chart("time_in_game_{{player.entity_end.id}}", { - type: "pie", - data: { - datasets: [{ - backgroundColor: {{ player.alive_time_colors }}, - data: {{ player.alive_time_values }}, - borderWidth: 0 - }] - }, - options: { - legend: { - display: false, - fullSize: false - }, - title: { - display: false, - }, - tooltips: { - enabled: false - } - } + type: "pie", + data: { + datasets: [{ + backgroundColor: {{ player.alive_time_colors }}, + data: {{ player.alive_time_values }}, + borderWidth: 0 + }] + }, + options: { + legend: { + display: false, + fullSize: false + }, + title: { + display: false, + }, + tooltips: { + enabled: false + } + } }); -{%- endmacro %} + {%- endmacro %} -{% macro player_reference(player) -%} + {% macro player_reference(player) -%} {% if not player.player_info %} -

{{ player.name }}

+

{{ player.name }}

+ {% else %} + {% if player.player_info.is_member %} +

{{ player.player_info.display_name }}

{% else %} - {% if player.player_info.is_member %} -

{{ player.player_info.display_name }}

- {% else %} -

{{ player.player_info.display_name }}

- {% endif %} +

{{ player.player_info.display_name }}

{% endif %} -{%- endmacro %} + {% endif %} + {%- endmacro %} -{% macro tooltip(tooltip_id) -%} + {% macro tooltip(tooltip_id) -%} {{ tooltip_info.insert_tooltip(tooltip_id) }} -{%- endmacro %} + {%- endmacro %} -{% macro uptime_chart(entity_id, state_distribution) -%} + {% macro uptime_chart(entity_id, state_distribution) -%} new Chart("uptime_{{entity_id}}", { - type: "pie", - data: { - labels: {{ state_distribution.labels }}, - datasets: [{ - backgroundColor: {{ state_distribution.colors }}, - data: {{ state_distribution.data }}, - borderWidth: 0 - }] - }, - options: { - legend: { - display: false, - fullSize: false - }, - title: { - display: false, - }, - tooltips: { - enabled: false - } - } + type: "pie", + data: { + labels: {{ state_distribution.labels }}, + datasets: [{ + backgroundColor: {{ state_distribution.colors }}, + data: {{ state_distribution.data }}, + borderWidth: 0 + }] + }, + options: { + legend: { + display: false, + fullSize: false + }, + title: { + display: false, + }, + tooltips: { + enabled: false + } + } }); {%- endmacro %} @@ -250,62 +250,65 @@ font-weight: bold; } - + {% block html_head %}{% endblock %} - {% set navigation_bar = [ - ("/", "Home"), - ("/players", "Players"), - ("/games", "Games"), - ("/stats", "Stats"), - ("/matchmaking", "Matchmaking"), - ("/about", "About") - ] -%} - -
- {% block content %}{% endblock %} -
- -