Skip to content

Commit

Permalink
fix: show meeting hours in total and qualifying on sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Oct 17, 2024
1 parent eb35a30 commit 3c2a40d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/hour_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,24 @@ export async function calculateHours(user: Prisma.MemberWhereUniqueInput) {
return out
}
export async function calculateAllHours() {
const out: Record<string, Record<enum_HourLogs_type | 'total' | 'qualifying', number>> = {}
const out: Record<string, Record<HourCategory, number>> = {}
const totals = await prisma.hourLog.groupBy({
by: ['member_id', 'type'],
_sum: { duration: true },
where: { state: 'complete', time_in: { gte: season_start_date } }
})
const meetings = await getMeetings()
totals.forEach((total) => {
out[total.member_id] ??= { event: 0, external: 0, lab: 0, summer: 0, total: 0, qualifying: 0 }
out[total.member_id] ??= { event: 0, external: 0, lab: 0, summer: 0, total: 0, qualifying: 0, meeting: 0 }
out[total.member_id][total.type] = total._sum.duration!.toNumber()
out[total.member_id].total += out[total.member_id][total.type]
out[total.member_id].qualifying = out[total.member_id].lab + out[total.member_id].external
})
Object.keys(out).forEach((member) => {
out[member].meeting = meetings[member] * 0.5
out[member].total += out[member].meeting
out[member].qualifying = out[member].lab + out[member].external + out[member].meeting
})
return out
}
export async function getWeeklyHours(): Promise<Record<string, number>> {
Expand Down

0 comments on commit 3c2a40d

Please sign in to comment.