-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from tuckergordon/lottery
Lottery
- Loading branch information
Showing
8 changed files
with
146 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Standing, Standings } from '$lib/models/Standings.model'; | ||
|
||
// original team: current team | ||
const TRADED_FIRSTS = { | ||
devspiel: 'tgordon18', | ||
benstone099: 'nachocamacho', | ||
tgordon18: 'BrianEvans', | ||
julianpdx: 'ConQD', | ||
Crams_Clams: 'nachocamacho', | ||
DanBrownOnTrail: 'jseibert', | ||
} as { [key: string]: string }; | ||
|
||
// TODO: figure out a way to render a svelte component instead of this | ||
// weird JSX-like approach | ||
export function LotteryTable(standings: Standings, tradedPicks = TRADED_FIRSTS, nPicks = 6) { | ||
const lottoStandings = standings.slice(-nPicks).sort((a, b) => a.maxPf - b.maxPf); | ||
|
||
const row = (team: Standing, i: number) => | ||
(i === 6 ? `<tr><td></td></tr>` : '') + | ||
`<tr> | ||
<td> | ||
${i + 1} | ||
</td> | ||
<td> | ||
${team.userName in tradedPicks ? `${tradedPicks[team.userName]} (via ${team.userName})` : team.userName} | ||
</td> | ||
<td> | ||
${team.maxPf} | ||
</td> | ||
</tr>`; | ||
return ` | ||
<table> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th>Name</th> | ||
<th>Max PF</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
${lottoStandings.map(row).join('')} | ||
</tbody> | ||
</table> | ||
`; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Standing, Standings } from '$lib/models/Standings.model'; | ||
|
||
// TODO: figure out a way to render a svelte component instead of this | ||
// weird JSX-like approach | ||
export function StandingsTable(standings: Standings) { | ||
const row = (team: Standing, i: number) => | ||
(i === 6 ? `<tr><td></td></tr>` : '') + | ||
`<tr> | ||
<td> | ||
${i + 1} | ||
</td> | ||
<td> | ||
${team.teamName} | ||
</td> | ||
<td> | ||
${team.wins}-${team.losses} | ||
</td> | ||
</tr>`; | ||
return ` | ||
<table> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th>Name</th> | ||
<th>Record</th> | ||
<!-- <th>PF</th> | ||
<th>PA</th> --> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
${standings.map(row).join('')} | ||
</tbody> | ||
</table> | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Standing } from '$lib/models/Standings.model'; | ||
import { supabase } from './supabase-client'; | ||
|
||
// TODO: type the return value | ||
export async function getStandings(leagueId: bigint, startWeek: number = 1, endWeek: number = 17) { | ||
const { data, error } = await supabase | ||
.from('schedule') | ||
.select( | ||
` | ||
win_h2h:win_h2h.sum(), | ||
win_median: win_median.sum(), | ||
points_for: points_for.sum(), | ||
points_against: points_against.sum(), | ||
max_points_for: max_points_for.sum(), | ||
teams( | ||
name, | ||
user_id, | ||
users( | ||
name | ||
) | ||
) | ||
`, | ||
) | ||
.eq('league_id', leagueId) | ||
.gte('week', startWeek) | ||
.lte('week', endWeek); | ||
|
||
if (error) { | ||
console.error('Error fetching standings:', error); | ||
return null; | ||
} | ||
|
||
const totalWeeks = endWeek - startWeek + 1; | ||
|
||
return data | ||
.map((standing) => { | ||
const wins = standing.win_h2h + standing.win_median; | ||
const losses = totalWeeks * 2 - wins; | ||
|
||
return { | ||
// @ts-expect-error - teams is not typed correctly yet | ||
teamName: standing.teams.name, | ||
// @ts-expect-error - teams is not typed correctly yet | ||
userId: standing.teams.user_id, | ||
// @ts-expect-error - teams is not typed correctly yet | ||
userName: standing.teams.users.name, | ||
wins, | ||
losses, | ||
pf: standing.points_for, | ||
pa: standing.points_against, | ||
maxPf: standing.max_points_for, | ||
} as Standing; | ||
}) | ||
.sort((a, b) => b.wins - a.wins); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters