Skip to content

Commit

Permalink
Leaderboard: add total tally proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
vladh committed Oct 8, 2024
1 parent 115e53e commit 40d7696
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 29 deletions.
67 changes: 38 additions & 29 deletions src/components/Leaderboard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,47 @@ const { grouped } = Astro.props;
import LeaderboardMember from "./LeaderboardMember.astro";
import {
getMembers, formatDevGroupBounds, filterInactiveMembers, groupMembers,
getMembers, getGrandTotalRaised, fmtCurrency, formatDevGroupBounds, filterInactiveMembers, groupMembers,
sortMembersByDevs, DEV_GROUP_BOUNDS
} from '../members.ts';
const members = filterInactiveMembers(await getMembers());
---

{grouped ? <div>
{groupMembers(members).map((groupMembers, idx) => groupMembers.length > 0 && <div>
<h2>{formatDevGroupBounds(DEV_GROUP_BOUNDS[idx])}</h2>
<div>
<p class="grand-total"
>Our members have raised a total of <strong>{fmtCurrency(await getGrandTotalRaised())}</strong>!</p
>
{grouped ? <div>
{groupMembers(members).map((groupMembers, idx) => groupMembers.length > 0 && <div>
<h2>{formatDevGroupBounds(DEV_GROUP_BOUNDS[idx])}</h2>
<table class="table--lrr table--40-30-30">
<thead>
<tr>
<th>Name</th>
<th>
<abbr title="Average number of employed full-time equivalent developers (in latest report)">Devs</abbr>
</th>
<th>
<abbr title="USD paid / average number of employed full-time equivalent developers (in latest report)"
>$/dev</abbr
>
</th>
</tr>
</thead>
<tbody>
{sortMembersByDevs(groupMembers).map((member) =>
<LeaderboardMember member={member}></LeaderboardMember>
)}
</tbody>
</table>
</div>)}
</div> : (
<table class="table--lrr table--40-30-30">
<thead>
<tr>
<th>Name</th>
<th>
<th class="ndevs">
<abbr title="Average number of employed full-time equivalent developers (in latest report)">Devs</abbr>
</th>
<th>
Expand All @@ -35,36 +61,19 @@ const members = filterInactiveMembers(await getMembers());
</tr>
</thead>
<tbody>
{sortMembersByDevs(groupMembers).map((member) =>
{sortMembersByDevs(members).map((member) =>
<LeaderboardMember member={member}></LeaderboardMember>
)}
</tbody>
</table>
</div>)}
</div> : (
<table class="table--lrr table--40-30-30">
<thead>
<tr>
<th>Name</th>
<th class="ndevs">
<abbr title="Average number of employed full-time equivalent developers (in latest report)">Devs</abbr>
</th>
<th>
<abbr title="USD paid / average number of employed full-time equivalent developers (in latest report)"
>$/dev</abbr
>
</th>
</tr>
</thead>
<tbody>
{sortMembersByDevs(members).map((member) =>
<LeaderboardMember member={member}></LeaderboardMember>
)}
</tbody>
</table>
)}
)}
</div>

<style>
.grand-total {
margin: 2rem 0;
text-align: center;
}
h2 {
margin-top: 2rem;
padding: 0.3rem 0.5rem;
Expand Down
12 changes: 12 additions & 0 deletions src/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ export function getDollarsPerDev(report: MemberReport) {
return report.payments / report.averageNumberOfDevs;
}

export async function getGrandTotalRaised() {
const members = filterInactiveMembers(await getMembers());
let grandTotal = 0;
members.forEach((member) => {
member.data.annualReports.forEach((report) => {
console.log(member.data.name, report.dateYearEnding, report.payments);
grandTotal += report.payments;
});
});
return grandTotal;
}

export function fmtCurrency(num: number) {
return '$' + num.toLocaleString(undefined, {
minimumFractionDigits: 0,
Expand Down

0 comments on commit 40d7696

Please sign in to comment.