diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index cee4bed..838afc2 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -1,7 +1,7 @@ --- name: Docker Build and maybe Push -on: +on: workflow_call: inputs: org: @@ -37,7 +37,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.10" - + - name: Fix metadata run: | if [ -x bin/freeze.sh ]; then @@ -76,4 +76,3 @@ jobs: context: . push: true tags: ${{ inputs.org }}/${{ inputs.repo }}:${{ inputs.tag }} - diff --git a/.github/workflows/build-latest.yml b/.github/workflows/build-latest.yml index 019dcdb..86fcf1d 100644 --- a/.github/workflows/build-latest.yml +++ b/.github/workflows/build-latest.yml @@ -21,27 +21,24 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - - name: install - uses: appleboy/ssh-action@v1.1.0 - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.KEY }} - port: ${{ secrets.PORT }} - passphrase: ${{ secrets.PASSPHRASE }} - script: | - set -euo pipefail - cd /opt/compose - docker compose pull freezing-web - docker compose up -d freezing-web - - - name: wait - uses: iFaxity/wait-on-action@v1.2.1 - with: - resource: https-get://freezingsaddles.org - timeout: 5000 - + - name: install + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + passphrase: ${{ secrets.PASSPHRASE }} + script: | + set -euo pipefail + cd /opt/compose + docker compose pull freezing-web + docker compose up -d freezing-web + - name: wait + uses: iFaxity/wait-on-action@v1.2.1 + with: + resource: https-get://freezingsaddles.org + timeout: 5000 test: concurrency: build-deploy-and-test @@ -49,10 +46,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - - name: checkout - uses: actions/checkout@v4 - - - name: test-wget-spider - run: "URL=https://freezingsaddles.org test/wget-spider.sh" - + - name: checkout + uses: actions/checkout@v4 + - name: test-wget-spider + run: "URL=https://freezingsaddles.org test/wget-spider.sh" diff --git a/.github/workflows/build-tag.yml b/.github/workflows/build-tag.yml index dd7488d..26a9885 100644 --- a/.github/workflows/build-tag.yml +++ b/.github/workflows/build-tag.yml @@ -4,7 +4,7 @@ name: Build Tag on: push: tags: - - '*' + - '*' jobs: build: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7e1fda0..6b03b10 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,9 +4,9 @@ name: Lint on: pull_request jobs: - - # Thanks https://black.readthedocs.io/en/stable/integrations/github_actions.html - lint: + # Thanks for the inspiration: + # https://black.readthedocs.io/en/stable/integrations/github_actions.html + python: name: Python Lint runs-on: ubuntu-latest steps: @@ -21,6 +21,24 @@ jobs: - name: isort Lint uses: isort/isort-action@v1 with: - requirements-files: "requirements.txt requirements-test.txt" + requirements-files: "requirements.txt requirements-test.txt" - name: flake8 Lint uses: py-actions/flake8@v2 + + templates: + name: Templates Lint + runs-on: ubuntu-latest + steps: + - name: Check out source repository + uses: actions/checkout@v4 + - name: Set up Python environment + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt -r requirements-test.txt + - name: djlint Lint + run: | + djlint --check freezing/web/templates diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index fce3dad..c0e1555 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -4,8 +4,9 @@ name: Security on: pull_request jobs: - - # Thanks https://black.readthedocs.io/en/stable/integrations/github_actions.html + + # Thanks for inspiration: + # https://black.readthedocs.io/en/stable/integrations/github_actions.html bandit: name: Bandit runs-on: ubuntu-latest diff --git a/README.md b/README.md index 24b00ff..0bff7bc 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,13 @@ To get `freezing-web` to permanently use the `freezing-model` changes you will h ### Coding standards -The `freezing-web` code is intended to be [PEP-8](https://www.python.org/dev/peps/pep-0008/) compliant. Code formatting is done with [black](https://black.readthedocs.io/en/stable/) and can be linted with [flake8](http://flake8.pycqa.org/en/latest/). See the [.flake8](.flake8) file and install the test dependencies to get these tools (`pip install -r test-requirements.txt`). +The `freezing-web` code is intended to be [PEP-8](https://www.python.org/dev/peps/pep-0008/) compliant. Code formatting is done with [black](https://black.readthedocs.io/en/stable/), [isort](https://pycqa.github.io/isort/) and [djlint}(https://www.djlint.com/) and can be linted with [flake8](http://flake8.pycqa.org/en/latest/). See the [.flake8](.flake8) file and install the test dependencies to get these tools (`pip install -r test-requirements.txt`). + +To run _all_ the linters and formatters, use the following commands: +``` +bin/lint.sh +bin/fmt.sh +``` ## Docker Deployment diff --git a/bin/fmt.sh b/bin/fmt.sh new file mode 100755 index 0000000..ddf8b3f --- /dev/null +++ b/bin/fmt.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +echo "Running formatters" +echo "*** black ***" +black freezing +echo "*** isort ***" +isort freezing +echo "*** djlint ***" +djlint --reformat freezing/web/templates + diff --git a/bin/lint.sh b/bin/lint.sh new file mode 100755 index 0000000..0fa0fb7 --- /dev/null +++ b/bin/lint.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +echo "Running linting checks" +echo "*** black ***" +black --check freezing +echo "*** isort ***" +isort --check freezing +echo "*** flake8 ***" +flake8 freezing +echo "*** mypy ***" +echo "*** djlint ***" +djlint --check freezing/web/templates + diff --git a/freezing/web/templates/alt_scoring/indiv_freeze.html b/freezing/web/templates/alt_scoring/indiv_freeze.html index d0767d2..26b2023 100644 --- a/freezing/web/templates/alt_scoring/indiv_freeze.html +++ b/freezing/web/templates/alt_scoring/indiv_freeze.html @@ -1,19 +1,39 @@ {% extends "base.html" %} {% block content %} -
-
Freeze Points
-
-

Thanks to VVill for coming up with this, (explained here). Basically you get more points for riding in the cold, but distance doesn't matter so much.

- - -{% for a, b in indiv_freeze %} - - - - - -{% endfor %} -
RankTeamPoints
{{loop.index}}{{a}}{{ '%0.1f' % b }}
-
-
+
+
+ Freeze Points +
+
+

+ Thanks to VVill for coming up with this, (explained here). Basically you get more points for riding in the cold, but distance doesn't matter so much. +

+ + + + + + + {% for a, b in indiv_freeze %} + + + + + + {% endfor %} +
+ Rank + + Team + + Points +
+ {{ loop.index }} + + {{ a }} + + {{ '%0.1f' % b }} +
+
+
{% endblock %} diff --git a/freezing/web/templates/alt_scoring/indiv_hains.html b/freezing/web/templates/alt_scoring/indiv_hains.html index a42eaa5..34c2cca 100644 --- a/freezing/web/templates/alt_scoring/indiv_hains.html +++ b/freezing/web/templates/alt_scoring/indiv_hains.html @@ -1,43 +1,84 @@ {% extends "base.html" %} {% block content %} -
-
Hains Point Laps
-
-

We're looking for the hamsterest hamster who ever hamstered.

-

Segment Miles is based on the 2.5 mile Gate - to Gate segment, so it undercounts your mileage if you did a full lap. - However, since this segment is the official measure of "A Hains Point Lap" as far as - this contest is concerned, it was thought best to use 2.5 miles.

-

If you feel the wrong decision has been made here, please be reminded that you are a hamster, and hamsters don't get the admin password to the web server.

-
- - - - -{% for a, b, c in indiv_hains %} - - - - - - - - -{% endfor %} -
RankHamsterTimes HamsteredSegment MilesTotal MilesHamster %
{{loop.index}}{{a}}{{b}}{{b * 2.5}}{{c|round(1)}}{{((b*250)/c)|round(1)}}
-
-
-
+
+
+ Hains Point Laps +
+
+

+ We're looking for the hamsterest hamster who ever hamstered. +

+

+ Segment Miles is based on the 2.5 mile Gate + to Gate segment, so it undercounts your mileage if you did a full lap. + However, since this segment is the official measure of "A Hains Point Lap" as far as + this contest is concerned, it was thought best to use 2.5 miles. +

+

+ If you feel the wrong decision has been made here, please be reminded that you are a hamster, and hamsters don't get the admin password to the web server. +

+
+ + + + + + + + + + + + {% for a, b, c in indiv_hains %} + + + + + + + + + {% endfor %} +
+ Rank + + Hamster + + Times Hamstered + + Segment Miles + + Total Miles + + Hamster % +
+ {{ loop.index }} + + {{ a }} + + {{ b }} + + {{ b * 2.5 }} + + {{ c|round(1) }} + + {{ ((b*250)/c)|round(1) }} +
+
+
+
{% endblock %} {% block foot %} - - - + + + {% endblock %} diff --git a/freezing/web/templates/alt_scoring/indiv_sleaze.html b/freezing/web/templates/alt_scoring/indiv_sleaze.html index 95de91c..ab3fa7c 100644 --- a/freezing/web/templates/alt_scoring/indiv_sleaze.html +++ b/freezing/web/templates/alt_scoring/indiv_sleaze.html @@ -1,19 +1,39 @@ {% extends "base.html" %} {% block content %} -
-
Sleaze Rides
-
-

If we really want to be pedantic, and of course we want to be pedantic, it's actually Sleaze Days. Two one mile rides in a day gets you no sleaze ride credit. Since no one wants sleaze ride credit, this is a good thing.

- - -{% for a, b in indiv_sleaze %} - - - - - -{% endfor %} -
RankNameSleaze Rides
{{loop.index}}{{a}}{{b}}
-
-
+
+
+ Sleaze Rides +
+
+

+ If we really want to be pedantic, and of course we want to be pedantic, it's actually Sleaze Days. Two one mile rides in a day gets you no sleaze ride credit. Since no one wants sleaze ride credit, this is a good thing. +

+ + + + + + + {% for a, b in indiv_sleaze %} + + + + + + {% endfor %} +
+ Rank + + Name + + Sleaze Rides +
+ {{ loop.index }} + + {{ a }} + + {{ b }} +
+
+
{% endblock %} diff --git a/freezing/web/templates/alt_scoring/indiv_worst_day_points.html b/freezing/web/templates/alt_scoring/indiv_worst_day_points.html index ffbc743..66d1154 100644 --- a/freezing/web/templates/alt_scoring/indiv_worst_day_points.html +++ b/freezing/web/templates/alt_scoring/indiv_worst_day_points.html @@ -1,49 +1,96 @@ {% extends "base.html" %} {% block content %} -
-
Steve O's Worst Day Points Proposal
-
-

Take the median number of riders per day and then, for each day, your Adjusted Points are - your points in the old system (1 point per mile, 10 points per day for riding at least 1 mile) multiplied - by 1.025^(median-[total number of riders today]). - At this moment in time, the median number of riders is {{median}}. -

-

NOTE: This is calculated at the time you view the chart. This means that today's points will - change as more people ride. If you are the first rider of the day, you will get literally a - bajillion points (A sleaze ride of exactly one mile is worth almost 1500 points if you're - the only rider of the day). As more people ride, your points go down. -

-
- - - - -{% for a, b, c, d, e, f in data %} - - - - - - - - - - -{% endfor %} -
RankRiderTeamMilesOld PointsAdjusted PointsBump %Days Ridden
{{loop.index}}{{a}}{{b}}{{c|round(1)}}{{d|round(1)}}{{e|round(1)}}{{(100*(e-d)/d)|round(1) if d > 0 else 0}}%{{f}}
-
-
-
+
+
+ Steve O's Worst Day Points Proposal +
+
+

+ Take the median number of riders per day and then, for each day, your Adjusted Points are + your points in the old system (1 point per mile, 10 points per day for riding at least 1 mile) multiplied + by 1.025^(median-[total number of riders today]). + At this moment in time, the median number of riders is {{ median }}. +

+

+ NOTE: This is calculated at the time you view the chart. This means that today's points will + change as more people ride. If you are the first rider of the day, you will get literally a + bajillion points (A sleaze ride of exactly one mile is worth almost 1500 points if you're + the only rider of the day). As more people ride, your points go down. +

+
+ + + + + + + + + + + + + + {% for a, b, c, d, e, f in data %} + + + + + + + + + + + {% endfor %} +
+ Rank + + Rider + + Team + + Miles + + Old Points + + Adjusted Points + + Bump % + + Days Ridden +
+ {{ loop.index }} + + {{ a }} + + {{ b }} + + {{ c|round(1) }} + + {{ d|round(1) }} + + {{ e|round(1) }} + + {{ (100*(e-d)/d)|round(1) if d > 0 else 0}}% + + {{ f }} +
+
+
+
{% endblock %} {% block foot %} - - - + + + {% endblock %} diff --git a/freezing/web/templates/alt_scoring/team_daily.html b/freezing/web/templates/alt_scoring/team_daily.html index bde5864..8d44c08 100644 --- a/freezing/web/templates/alt_scoring/team_daily.html +++ b/freezing/web/templates/alt_scoring/team_daily.html @@ -1,14 +1,20 @@ {% extends "base.html" %} {% block content %} -
-
Team Points by Day
-
-

For each day, the team with the highest daily total gets {{team_total|length}} points. Second gets {{team_total|length - 1}}, down to 1 for the last place team.

-
    - {% for a,b in team_total %} -
  1. {{b}} {{a}}
  2. - {% endfor %} -
-
-
+
+
+ Team Points by Day +
+
+

+ For each day, the team with the highest daily total gets {{ team_total|length }} points. Second gets {{ team_total|length - 1 }}, down to 1 for the last place team. +

+
    + {% for a,b in team_total %} +
  1. + {{ b }} {{ a }} +
  2. + {% endfor %} +
+
+
{% endblock %} diff --git a/freezing/web/templates/alt_scoring/team_hains.html b/freezing/web/templates/alt_scoring/team_hains.html index d7b0d8b..cac6fcb 100644 --- a/freezing/web/templates/alt_scoring/team_hains.html +++ b/freezing/web/templates/alt_scoring/team_hains.html @@ -1,19 +1,39 @@ {% extends "base.html" %} {% block content %} -
-
Team Hains Point Laps
-
-

Certainly hope at least some of these were together as a team.

- - -{% for a, b in team_hains %} - - - - - -{% endfor %} -
RankTeamLaps
{{loop.index}}{{a}}{{b}}
-
-
+
+
+ Team Hains Point Laps +
+
+

+ Certainly hope at least some of these were together as a team. +

+ + + + + + + {% for a, b in team_hains %} + + + + + + {% endfor %} +
+ Rank + + Team + + Laps +
+ {{ loop.index }} + + {{ a }} + + {{ b }} +
+
+
{% endblock %} diff --git a/freezing/web/templates/alt_scoring/team_riders.html b/freezing/web/templates/alt_scoring/team_riders.html index fc40f07..9847375 100644 --- a/freezing/web/templates/alt_scoring/team_riders.html +++ b/freezing/web/templates/alt_scoring/team_riders.html @@ -1,19 +1,39 @@ {% extends "base.html" %} {% block content %} -
-
Team Riders
-
-

Ride days per team

- - -{% for a, b in team_riders %} - - - - - -{% endfor %} -
RankTeamRide Days
{{loop.index}}{{a}}{{b}}
-
-
+
+
+ Team Riders +
+
+

+ Ride days per team +

+ + + + + + + {% for a, b in team_riders %} + + + + + + {% endfor %} +
+ Rank + + Team + + Ride Days +
+ {{ loop.index }} + + {{ a }} + + {{ b }} +
+
+
{% endblock %} diff --git a/freezing/web/templates/alt_scoring/team_sleaze.html b/freezing/web/templates/alt_scoring/team_sleaze.html index 3201644..040663b 100644 --- a/freezing/web/templates/alt_scoring/team_sleaze.html +++ b/freezing/web/templates/alt_scoring/team_sleaze.html @@ -1,20 +1,42 @@ {% extends "base.html" %} {% block content %} -
-
Team Sleaze
-
-

Now, you know it's up to you whether or not you want to just do the bare minimum. People can go for a bike ride anywhere, okay? They do Freezing Saddles for the camaraderie and the soul-crushing cold.

-

Look, we want you to ride your bike, okay? Now if you feel that the bare minimum is enough, then okay. But some people choose to ride more and we encourage that, okay? You do want to ride your bike, don't you?

- - -{% for a, b in team_sleaze %} - - - - - -{% endfor %} -
RankTeamSleaze Rides
{{loop.index}}{{a}}{{b}}
-
-
+
+
+ Team Sleaze +
+
+

+ Now, you know it's up to you whether or not you want to just do the bare minimum. People can go for a bike ride anywhere, okay? They do Freezing Saddles for the camaraderie and the soul-crushing cold. +

+

+ Look, we want you to ride your bike, okay? Now if you feel that the bare minimum is enough, then okay. But some people choose to ride more and we encourage that, okay? You do want to ride your bike, don't you? +

+ + + + + + + {% for a, b in team_sleaze %} + + + + + + {% endfor %} +
+ Rank + + Team + + Sleaze Rides +
+ {{ loop.index }} + + {{ a }} + + {{ b }} +
+
+
{% endblock %} diff --git a/freezing/web/templates/authorization_error.html b/freezing/web/templates/authorization_error.html index 9289b04..4a702fa 100644 --- a/freezing/web/templates/authorization_error.html +++ b/freezing/web/templates/authorization_error.html @@ -1,12 +1,13 @@ {% extends "base.html" %} {% block content %} -

Authorization Failed

-

- There was an error authorizing the Freezing Saddles application to - access your Strava account. -

-

- Error code: {{ error }} -

- -{% endblock %} \ No newline at end of file +

+ Authorization Failed +

+

+ There was an error authorizing the Freezing Saddles application to + access your Strava account. +

+

+ Error code: {{ error }} +

+{% endblock %} diff --git a/freezing/web/templates/authorization_success.html b/freezing/web/templates/authorization_success.html index ff76a2f..0393927 100644 --- a/freezing/web/templates/authorization_success.html +++ b/freezing/web/templates/authorization_success.html @@ -1,62 +1,75 @@ {% extends "base.html" %} {% block content %} -

Authorization Results

-

- Welcome, {{ athlete.firstname }}. -

-

- You have successfully logged in to Strava and authorized the Freezing Saddles application to read your rides. -

-