Skip to content

Commit

Permalink
Merge pull request #435 from freezingsaddles/highlight-my-rows
Browse files Browse the repository at this point in the history
Highlight my rows in leaderboards
  • Loading branch information
merlinorg authored Jan 21, 2025
2 parents 0cc1de1 + cd4d08a commit 69483fd
Show file tree
Hide file tree
Showing 31 changed files with 156 additions and 101 deletions.
4 changes: 3 additions & 1 deletion freezing/web/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class Config:
VERSION_NUM: str = version("freezing-web")
VERSION_STRING: str = f"{VERSION_NUM}+{branch}.{commit}.{build_date}"
SEND_FILE_MAX_AGE_DEFAULT: int = (
84600 # let the browser cache static files for 24 hours
None
if ENVIRONMENT == "localdev"
else 84600 # let the browser cache static files for 24 hours
)


Expand Down
8 changes: 8 additions & 0 deletions freezing/web/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ nav.bg-light {
aspect-ratio: 1;
}

.table tr.myself {
background-color: transparent !important;
}

.table tr.myself td {
background-color: #ffff0020;
}

@media (min-width: 576px) {
.stats-card {
flex-direction: row;
Expand Down
8 changes: 4 additions & 4 deletions freezing/web/templates/alt_scoring/indiv_freeze.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ <h2 class="mb-3">
Rank
</th>
<th>
Team
Rider
</th>
<th class="number">
Points
</th>
</tr>
{% for a, b in indiv_freeze %}
<tr>
{% for id, a, b in indiv_freeze %}
<tr class="{{ id | myself }}">
<td class="number rank">
{{ loop.index }}
</td>
<td>
{{ a }}
<a href="/people/{{ id }}" class="hover-underline">{{ a }}</a>
</td>
<td class="number">
{{ '%0.1f' % b }}
Expand Down
6 changes: 3 additions & 3 deletions freezing/web/templates/alt_scoring/indiv_hains.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ <h2 class="mb-3">
</th>
</tr>
</thead>
{% for a, b, c in indiv_hains %}
<tr>
{% for id, a, b, c in indiv_hains %}
<tr class="{{ id | myself }}">
<td>
{{ loop.index }}
</td>
<td>
{{ a }}
<a href="/people/{{ id }}" class="hover-underline">{{ a }}</a>
</td>
<td>
{{ b }}
Expand Down
6 changes: 3 additions & 3 deletions freezing/web/templates/alt_scoring/indiv_sleaze.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ <h2 class="mb-3">
Sleaze Rides
</th>
</tr>
{% for a, b in indiv_sleaze %}
<tr>
{% for id, a, b in indiv_sleaze %}
<tr class="{{ id | myself }}">
<td class="number rank">
{{ loop.index }}
</td>
<td>
{{ a }}
<a href="/people/{{ id }}" class="hover-underline">{{ a }}</a>
</td>
<td class="number">
{{ b }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ <h5 class="card-header">
</th>
</tr>
</thead>
{% for a, b, c, d, e, f in data %}
<tr>
{% for id, a, b, c, d, e, f in data %}
<tr class="{{ id | myself }}">
<td class="number">
{{ loop.index }}
</td>
Expand Down
4 changes: 2 additions & 2 deletions freezing/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link{% if request.path.startswith('/photos') %} active{% endif %}"
href="/photos">Photos</a>
href="/photos/">Photos</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle{% if request.path.startswith('/leaderboard') or request.path.startswith('/tribes') %} active{% endif %}"
Expand Down Expand Up @@ -438,7 +438,7 @@
</a>
<ul class="dropdown-menu" aria-labelledby="peopleDropdown">
<li>
<a class="dropdown-item" href="/people">People</a>
<a class="dropdown-item" href="/people/">People</a>
</li>
<li>
<a class="dropdown-item" href="/people/ridedays">Every Day Riders</a>
Expand Down
4 changes: 2 additions & 2 deletions freezing/web/templates/leaderboard/indiv_text.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>
</p>
<ol>
{% for indiv_row in indiv_rows[:10] %}
<li class="bigly{{ ' myself' if indiv_row['athlete_id'] == myself else '' }}">
<li class="bigly {{ indiv_row['athlete_id'] | myself }}">
<h4 class="mb-0">
<a href="/people/{{ indiv_row['athlete_id'] }}" class="hover-underline">{{ indiv_row['athlete_name'] }}</a>
{{ indiv_row['total_score']|round|int|groupnum }} points
Expand All @@ -29,7 +29,7 @@ <h4 class="mb-0">
</li>
{% endfor %}
{% for indiv_row in indiv_rows[10:] %}
<li class="{{ 'myself' if indiv_row['athlete_id'] == myself else '' }}">
<li class="{{ indiv_row['athlete_id'] | myself }}">
<a href="/people/{{ indiv_row['athlete_id'] }}" class="hover-underline">{{ indiv_row['athlete_name'] }}</a>
<strong>{{ indiv_row['total_score']|round|int|groupnum }}</strong> points
({{ indiv_row['days_ridden'] }} days, {{ indiv_row['total_distance']|round|int|groupnum }} miles) {{ indiv_row['team_name'] }}
Expand Down
51 changes: 42 additions & 9 deletions freezing/web/templates/people/friends.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,46 @@ <h1>
This "leaderboard" is for the those riders who are not currently on a competitive team, either by choice or by late registration. These riders are encouraged to ride,
to participate in reindeer games, and to show up at gatherings, but their rides will be ineligible for any and all leaderboards.
</p>
<ul>
{% for indiv_row in indiv_rows %}
<li>
<a href="/people/{{ indiv_row['athlete_id'] }}" class="hover-underline">{{ indiv_row['athlete_name'] }}</a>
<strong>{{ indiv_row['total_score']|round|int|groupnum }}</strong> points
({{ indiv_row['days_ridden'] }} days, {{ indiv_row['total_distance']|round|int|groupnum }} miles)
</li>
{% endfor %}
</ul>
<div class="card">
<div class="card-body py-1">
<table class="table table-condensed">
<tr>
<th class="number rank">
Rank
</th>
<th>
Rider
</th>
<th class="number">
Points
</th>
<th class="number">
Days
</th>
<th class="number">
Miles
</th>
</tr>
{% for indiv_row in indiv_rows %}
<tr class="{{ indiv_row['id'] | myself }}">
<td class="number rank">
{{ loop.index }}
</td>
<td>
<a href="/people/{{ indiv_row['id'] }}" class="hover-underline">{{ indiv_row['athlete_name'] }}</a>
</td>
<td class="number">
{{ indiv_row['total_score']|round|int|groupnum }}
</td>
<td class="number">
{{ indiv_row['days_ridden']|round|int|groupnum }}
</td>
<td class="number">
{{ indiv_row['total_distance']|round|int|groupnum }}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion freezing/web/templates/people/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h1>
</thead>
<tbody>
{% for u in users %}
<tr>
<tr class="{{ u.id | myself }}">
<td>
<a href="/people/{{ u.id }}" class="hover-underline">{{ u.name }}</a>
</td>
Expand Down
50 changes: 25 additions & 25 deletions freezing/web/templates/people/ridedays.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{% extends "base.html" %}
{% block content %}
<h2 class="mb-3">
Every Day Riders - Day {{ num_days }}
</h2>
{% if all_done %}
<p>
<strong>The competiton for this year is complete after {{ num_days }} days of riding!</strong>
</p>
{% endif %}
<ul>
<li>
If your name is <span class="text-success">green</span>, you've ridden every day. <em>Congratulations!</em>&nbsp;🏆 for you!
</li>
<li>
<span class="text-warning">Yellow</span> means you are one ride shy of every day and you have not yet ridden today. ⚠️ <strong>Go ride today!</strong>
</li>
<li>
<span class="text-danger">Red</span> means you have missed a day, alas. Maybe next year you will be in the elite group of every day riders.
</li>
</ul>
<p>
If your name is <span class="text-warning">yellow</span> or <span class="text-danger">red</span>, either you haven't ridden enough (see
<a href="https://www.velominati.com/the-rules/#5" rel="noreferrer">Rule 5</a>) or you need to upload your rides.
</p>
<div class="card">
<h5 class="card-header">
Every Day Riders - Day {{ num_days }}
</h5>
<div class="card-body">
{% if all_done %}
<p>
<strong>The competiton for this year is complete after {{ num_days }} days of riding!</strong>
</p>
{% endif %}
<ul>
<li>
If your name is <span class="text-success">green</span>, you've ridden every day. <em>Congratulations!</em>&nbsp;🏆 for you!
</li>
<li>
<span class="text-warning">Yellow</span> means you are one ride shy of every day and you have not yet ridden today. ⚠️ <strong>Go ride today!</strong>
</li>
<li>
<span class="text-danger">Red</span> means you have missed a day, alas. Maybe next year you will be in the elite group of every day riders.
</li>
</ul>
<p>
If your name is <span class="text-warning">yellow</span> or <span class="text-danger">red</span>, either you haven't ridden enough (see
<a href="https://www.velominati.com/the-rules/#5" rel="noreferrer">Rule 5</a>) or you need to upload your rides.
</p>
<div class="card-body py-1">
<table class="table table-condensed">
<tr>
<th class="number rank">
Expand All @@ -48,7 +48,7 @@ <h5 class="card-header">
{% else %}
{% set class = "text-danger" %}
{% endif %}
<tr>
<tr class="{{ a | myself }}">
<td class="number rank">
{{ c }}
</td>
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/templates/pointless/daily_variance.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1>
</thead>
<tbody>
{% for a,b,c,dist,can_win,d,e,f,g,h,i,j,k in data.tdata %}
<tr>
<tr class="{{ a | myself }}">
<td>
<a href="/people/{{ a }}"
{% if not can_win %}class="hover-underline text-danger"{% else %}class="hover-underline"{% endif %}>{{ b }}</a>
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/templates/pointless/foodrescue.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h5 class="card-header">
</th>
</tr>
{% for a, b, d, e, f in data.tdata %}
<tr>
<tr class="{{ a | myself }}">
<td class="number rank">
{{ f }}
</td>
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/templates/pointless/generic.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h5 class="card-header">
</thead>
<tbody>
{% for row in data %}
<tr>
<tr class="{{ row.athlete_id | myself }}">
<td class="number rank">
{{ row.rank }}
</td>
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/templates/pointless/hashtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3 class="accordion-header">
</th>
</tr>
{% for a, b, c, d in data.tdata %}
<tr>
<tr class="{{ a | myself }}">
<td class="number rank">
{{ loop.index }}
</td>
Expand Down
6 changes: 3 additions & 3 deletions freezing/web/templates/pointless/points_per_mile.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ <h5 class="card-header">
Ride Days
</th>
</tr>
{% for a, b, c, d, e in data.riders %}
<tr {% if e>=data.days %}class="success"{% endif %}>
{% for id, a, b, c, d, e in data.riders %}
<tr class="{{ id | myself }}">
<td class="number rank">
{{ loop.index }}
</td>
<td>
{{ a }}
<a class="hover-underline {{ 'text-danger' if e < data.days else '' }} href="/people/{{ id }}">{{ a }}</a>
</td>
<td class="number">
{{ b|round(1) }}
Expand Down
2 changes: 1 addition & 1 deletion freezing/web/templates/pointless/rosshillloop.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h5 class="card-header">
</th>
</tr>
{% for a, b, d, e in data.tdata %}
<tr>
<tr class="{{ a | myself }}">
<td class="number rank">
{{ loop.index }}
</td>
Expand Down
1 change: 1 addition & 0 deletions freezing/web/views/alt_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def indiv_worst_day_points():
)
data = [
(
x["athlete_id"],
x["athlete_name"],
x["team_name"],
x["total_distance"],
Expand Down
9 changes: 8 additions & 1 deletion freezing/web/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from datetime import datetime, timedelta
from re import findall, fullmatch
from re import findall, fullmatch, sub

from flask import (
Blueprint,
Expand Down Expand Up @@ -72,6 +72,13 @@ def ess(number):
return "" if groupnum(number) == "1" else "s"


@app.template_filter("myself")
def myself(number):
# generic board formats the PK into a fancy string so unformat it
id = int(sub(",", "", number)) if isinstance(number, str) else number
return "myself" if session.get("athlete_id") == id else ""


@blueprint.route("/")
def index():
q = text("""select count(*) as num_contestants from lbd_athletes""")
Expand Down
6 changes: 3 additions & 3 deletions freezing/web/views/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def team_hains():
def indiv_sleaze():
q = indiv_sleaze_query()
data = [
(x["athlete_name"], x["num_sleaze_days"])
(x["athlete_id"], x["athlete_name"], x["num_sleaze_days"])
for x in meta.scoped_session().execute(q).fetchall()
]
return render_template(
Expand All @@ -185,7 +185,7 @@ def indiv_sleaze():
def indiv_hains():
q = indiv_segment_query(join_miles=True)
data = [
(x["athlete_name"], x["segment_rides"], x["dist"])
(x["athlete_id"], x["athlete_name"], x["segment_rides"], x["dist"])
for x in meta.engine.execute(q, segment_id=1081507).fetchall()
]
return render_template(
Expand All @@ -199,7 +199,7 @@ def indiv_freeze():
friends = request.args.get("friends", "false") == "true"
q = indiv_freeze_query(friends)
data = [
(x["athlete_name"], x["freeze_points_total"])
(x["athlete_id"], x["athlete_name"], x["freeze_points_total"])
for x in meta.scoped_session().execute(q).fetchall()
]
return render_template(
Expand Down
Loading

0 comments on commit 69483fd

Please sign in to comment.