Skip to content

Commit

Permalink
Fix every day riders
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinorg committed Jan 3, 2025
1 parent cb7d618 commit 596721d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
2 changes: 1 addition & 1 deletion freezing/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
<a class="dropdown-item" href="/people">People</a>
</li>
<li>
<a class="dropdown-item" href="/people/ridedays">Ride Days</a>
<a class="dropdown-item" href="/people/ridedays">Every Day Riders</a>
</li>
<li>
<a class="dropdown-item" href="/people/friends">Friends of BAFS</a>
Expand Down
41 changes: 22 additions & 19 deletions freezing/web/templates/people/ridedays.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,58 @@ <h5 class="card-header">
<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 green, you've ridden every day. <em>Congratulations!</em>&nbsp;🏆 for you!
</p>
<p>
If your name is yellow or red, either you haven't ridden (see <a href="https://www.velominati.com/the-rules/#5">Rule 5</a>) or you need to upload your rides.
</p>
<p>
Yellow means you are one ride shy of every day and you have not yet ridden today. ⚠️ <strong>Go ride today!</strong>
</p>
<p>
Red means you have missed a day, alas. Maybe next year you will be in the elite group of every day riders.
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>
<table class="table table-condensed">
<tr>
<th class="number rank">
Days
</th>
<th>
Rider
</th>
<th class="number">
Days
</th>
<th class="number">
Miles
</th>
<th class="emoji">
Every Day Rider?
</th>
</tr>
{% for a, b, c, d in ride_days %}
{% for a, b, c, d, e in ride_days %}
{% if c >= num_days %}
{% set class = "text-success" %}
{% elif c == (num_days - 1) and not all_done %}
{% elif c == (num_days - 1) and e == 0 and not all_done %}
{% set class = "text-warning" %}
{% else %}
{% set class = "text-danger" %}
{% endif %}
<tr>
<td class="number rank">
{{ c }}
</td>
<td>
<a href="/people/{{ a }}" class="{{ class }} hover-underline">{{ b }}</a>
</td>
<td class="number">
{{ c }}
</td>
<td class="number">
{{ d | round(1) }}
</td>
<td class="emoji">
{% if c >= num_days %}
🏆
{% elif c == (num_days - 1) and not all_done %}
{% elif c == (num_days - 1) and e == 0 and not all_done %}
⚠️
{% endif %}
</td>
Expand Down
26 changes: 9 additions & 17 deletions freezing/web/views/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_today() -> datetime:
Sometimes you have an old database for testing and you need to set today to be something that is not actually today
"""
if False:
return datetime(2019, 3, 20, tzinfo=config.TIMEZONE)
return datetime(2024, 3, 18, tzinfo=config.TIMEZONE)
return get_local_datetime()


Expand Down Expand Up @@ -126,35 +126,27 @@ def ridedays():
a.display_name,
count(b.ride_date) as rides,
sum(b.distance) as miles,
max(b.ride_date) < :today as contender
sum(case when b.ride_date = :today then 1 else 0 end) as contender
FROM
lbd_athletes a,
daily_scores b where a.id = b.athlete_id
group by b.athlete_id
order by
rides desc,
contender desc,
miles desc,
display_name
;
"""
)
loc_time = get_today()
start_yday = config.START_DATE.timetuple().tm_yday
end_yday = config.END_DATE.timetuple().tm_yday
current_yday = loc_time.timetuple().tm_yday
loc_total_days = min(current_yday, end_yday) - start_yday + 1
loc_total_days = (
min(loc_time.toordinal(), config.END_DATE.toordinal())
- config.START_DATE.toordinal()
+ 1
)
all_done = competition_done(loc_time)
# once the competition is over, even if you're a day short you are no longer a contender
contender_date = config.END_DATE.date() if all_done else loc_time.date()
ride_days = [
(
x["id"],
x["display_name"],
x["rides"],
x["miles"],
)
for x in meta.engine.execute(q, today=contender_date).fetchall()
(x["id"], x["display_name"], x["rides"], x["miles"], x["contender"])
for x in meta.engine.execute(q, today=loc_time.date()).fetchall()
]
return render_template(
"people/ridedays.html",
Expand Down

0 comments on commit 596721d

Please sign in to comment.