Skip to content

Commit

Permalink
Also show whether or not somebody's a leader
Browse files Browse the repository at this point in the history
We've historically used "number of trips led" as a weak proxy to
differentiate active club leaders from people who've just been given a
hiking co-leader rating. It's useful to be able to view who's actively a
MITOC leader though. Turns out the numbers don't differ much.
  • Loading branch information
DavidCain committed Apr 18, 2024
1 parent b957bfc commit 99be706
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ws/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def dispatch(self, request, *args, **kwargs):

class RawMembershipStatsView(View):
@staticmethod
def _all_members_info() -> Iterator[dict[str, str | int]]:
def _all_members_info() -> Iterator[dict[str, str | int | bool]]:
for info in geardb_utils.membership_information().values():
flat_info: dict[str, str | int] = {
"last_known_affiliation": info.last_known_affiliation,
Expand Down
10 changes: 8 additions & 2 deletions ws/templates/stats/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
var justLeaders = _.filter(allMembers, 'num_trips_led');
renderChart("#leaders", justLeaders);

var ratedLeaders = _.filter(allMembers, 'is_leader');
renderChart("#rated_leaders", ratedLeaders);

var justDiscounts = _.filter(allMembers, function(info) {
return (info.num_discounts && !info.num_rentals && !info.num_trips_attended);
});
Expand Down Expand Up @@ -239,11 +242,14 @@ <h4>MITOC members grouped</h4>
</p>
<div id="stacked"></div>

<h3>Current Leaders</h3>
<p>Affiliation of people who hold a leader rating, even if they never lead trips.</p>
<div id="rated_leaders"></div>

<h3>Leaders</h3>
<p>Current affiliation of people who have ever led a trip.</p>
<p>Current affiliation of people who have ever led a trip (even if they're not currently rated).</p>
<div id="leaders"></div>


<h3>All dues-paying members</h3>
<p>This is a count of all MITOCers who've paid their dues (but may not have
rented gear, participated on trips, or otherwise made use of the club).
Expand Down
5 changes: 4 additions & 1 deletion ws/utils/geardb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import requests
from allauth.account.models import EmailAddress
from django.contrib.auth.models import User
from django.db.models import Case, Count, IntegerField, Sum, When
from django.db.models import Case, Count, IntegerField, Q, Sum, When
from django.db.models.functions import Lower

from ws import models, settings
Expand Down Expand Up @@ -53,6 +53,7 @@ class Rental(NamedTuple):


class TripsInformation(NamedTuple):
is_leader: bool
num_trips_attended: int
num_trips_led: int
num_discounts: int
Expand Down Expand Up @@ -328,11 +329,13 @@ def trips_information() -> dict[int, TripsInformation]:
additional_stats = models.Participant.objects.all().annotate(
num_discounts=Count("discounts", distinct=True),
num_trips_led=Count("trips_led", distinct=True),
num_leader_ratings=Count("leaderrating", filter=Q(leaderrating__active=True)),
)

return {
par.user_id: TripsInformation(
email=par.email,
is_leader=bool(par.num_leader_ratings),
num_trips_attended=trips_per_participant[par.pk],
num_trips_led=par.num_trips_led,
num_discounts=par.num_discounts,
Expand Down

0 comments on commit 99be706

Please sign in to comment.