Skip to content

Commit

Permalink
feat: add outreach hours category
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Oct 29, 2024
1 parent 08e2d1e commit d1d0c7e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "enum_HourLogs_type" ADD VALUE 'outreach';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ enum enum_HourLogs_type {
external
summer
event
outreach
}

enum enum_MeetingAttendances_state {
Expand Down
11 changes: 5 additions & 6 deletions src/lib/hour_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export async function calculateHours(user: Prisma.MemberWhereUniqueInput) {
}
user.email = member.email
}
const sums = await prisma.hourLog.groupBy({ by: 'type', _sum: { duration: true }, where: { state: 'complete', member_id: user.email, time_out: { gte: season_start_date } } })
const sums = await prisma.hourLog.groupBy({ by: 'type', _sum: { duration: true }, where: { state: 'complete', member_id: user.email, time_in: { gte: season_start_date } } })
const meetingCount = await prisma.meetingAttendanceEntry.count({ where: { member_id: user.email, state: 'present', Meeting: { date: { gte: season_start_date } } } })
const out: Record<HourCategory, number> = { event: 0, external: 0, lab: 0, summer: 0, total: 0, qualifying: 0, meeting: 0.5 * meetingCount }
const out: Record<HourCategory, number> = { outreach: 0, event: 0, external: 0, lab: 0, summer: 0, total: 0, qualifying: 0, meeting: 0.5 * meetingCount }
sums.forEach((sum) => {
out[sum.type] = sum._sum.duration!.toNumber()
out.total += out[sum.type]
})
out.total += out.meeting
out.qualifying = out.lab + out.external + out.meeting
out.qualifying = out.lab + out.external + out.meeting + out.outreach
return out
}
export async function calculateAllHours() {
Expand All @@ -79,15 +79,14 @@ export async function calculateAllHours() {
})
const meetings = await getMeetings()
totals.forEach((total) => {
out[total.member_id] ??= { event: 0, external: 0, lab: 0, summer: 0, total: 0, qualifying: 0, meeting: 0 }
out[total.member_id] ??= { outreach: 0, 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
out[member].qualifying = out[member].lab + out[member].external + out[member].meeting + out[member].outreach
})
return out
}
Expand Down
3 changes: 2 additions & 1 deletion src/slack/blocks/admin/hour_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ export function getHourSubmissionBlocks(v: HourSubmissionBlocksInput) {
Blocks.Actions().elements(
Elements.Button().primary().text('Accept').actionId(ActionIDs.ACCEPT).value(v.request_id),
Elements.Button().danger().text('Reject').actionId(ActionIDs.REJECT).value(v.request_id),
Elements.Button().text('☀️').actionId(ActionIDs.ACCEPT_SUMMER).value(v.request_id),
// Elements.Button().text('☀️').actionId(ActionIDs.ACCEPT_SUMMER).value(v.request_id), // 7 buttons renders poorly, not used in fall
Elements.Button().text('📆').actionId(ActionIDs.ACCEPT_EVENT).value(v.request_id),
Elements.Button().text('🔨').actionId(ActionIDs.ACCEPT_LAB).value(v.request_id),
Elements.Button().text('⛳').actionId(ActionIDs.ACCEPT_OUTREACH).value(v.request_id),
Elements.Button().text('Accept w/ Message').actionId(ActionIDs.ACCEPT_WITH_MSG).value(v.request_id)
)
)
Expand Down
3 changes: 2 additions & 1 deletion src/slack/blocks/admin/respond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export function getRespondMessageModal(
Bits.Option().text('External').value('external'),
Bits.Option().text('Summer ☀️').value('summer'),
Bits.Option().text('Event').value('event'),
Bits.Option().text('Lab').value('lab')
Bits.Option().text('Lab').value('lab'),
Bits.Option().text('Outreach').value('outreach')
)
)
)
Expand Down
16 changes: 7 additions & 9 deletions src/slack/blocks/app_home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ export async function getAppHome(user_id: string) {
const homeTab = HomeTab()
if (config.slack.users.devs.includes(user_id)) {
const tasks = getTaskKeys().map((key) => Bits.Option().text(key).value(key))
homeTab.blocks(
Blocks.Header().text('Dev Dashboard'),
)
for (let i = 0; i<Math.ceil(tasks.length/5); i++) {
console.log(tasks.slice(i*5,(i+1)*5))
homeTab.blocks(Blocks.Header().text('Dev Dashboard'))
for (let i = 0; i < Math.ceil(tasks.length / 5); i++) {
console.log(tasks.slice(i * 5, (i + 1) * 5))
homeTab.blocks(
Blocks.Section()
.text('Manual Tasks ('+i+")")
.text('Manual Tasks (' + i + ')')
.accessory(
Elements.OverflowMenu()
.actionId(ActionIDs.RUN_TASK)
.options(tasks.slice(i*5,(i+1)*5))
),
.options(tasks.slice(i * 5, (i + 1) * 5))
)
)
}

homeTab.blocks(
Blocks.Actions().elements(
Elements.Button().text('Open Onboarding').actionId(ActionIDs.OPEN_ONBOARDING_MODAL),
Expand Down
2 changes: 2 additions & 0 deletions src/slack/blocks/member/user_hours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export async function getUserHourSummaryBlocks(user: Prisma.MemberWhereUniqueInp
Blocks.Divider(),
Blocks.Section().fields('Summer', hours.summer.toFixed(1)),
Blocks.Divider(),
Blocks.Section().fields('Outreach', hours.outreach.toFixed(1)),
Blocks.Divider(),
Blocks.Section().fields('*Total*', '*' + hours.total.toFixed(1) + '*'),
Blocks.Divider(),
Blocks.Section().fields('Qualifying', hours.qualifying.toFixed(1)),
Expand Down
2 changes: 2 additions & 0 deletions src/slack/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum ActionIDs {
ACCEPT_SUMMER = 'accept_summer',
ACCEPT_EVENT = 'accept_event',
ACCEPT_LAB = 'accept_lab',
ACCEPT_OUTREACH = 'accept_outreach',
ACCEPT_WITH_MSG = 'accept_msg',
REJECT = 'reject',
OPEN_USERINFO_MODAL = 'open_settings_modal',
Expand Down Expand Up @@ -72,6 +73,7 @@ export function registerSlackHandlers(app: App) {
app.action(ActionIDs.ACCEPT_SUMMER, createHoursAcceptButtonHandler('summer'))
app.action(ActionIDs.ACCEPT_EVENT, createHoursAcceptButtonHandler('event'))
app.action(ActionIDs.ACCEPT_LAB, createHoursAcceptButtonHandler('lab'))
app.action(ActionIDs.ACCEPT_OUTREACH, createHoursAcceptButtonHandler('outreach'))
app.action(ActionIDs.ACCEPT_WITH_MSG, handleHoursAcceptWithMessageButton)
app.action(ActionIDs.REJECT, handleHoursRejectButton)
app.action(ActionIDs.OPEN_USERINFO_MODAL, handleOpenUserInfoModal)
Expand Down
6 changes: 2 additions & 4 deletions src/spreadsheet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export async function authorize() {

const client = await authorize()

function max50Hours(hours: number) {
return hours >= 50 ? '50+' : hours
}

export async function updateSheet() {
const members = await prisma.member.findMany({ orderBy: { full_name: 'asc' }, where: { active: true } })
const certs = await prisma.memberCert.findMany({ orderBy: { cert_id: 'asc' }, include: { Cert: { select: { label: true } } } })
Expand Down Expand Up @@ -53,6 +49,7 @@ export async function updateSheet() {
'ExternalHours',
'EventHours',
'SummerHours',
'OutreachHours',
'QualifyingHours',
'TotalHours',
'WeeklyHours',
Expand All @@ -76,6 +73,7 @@ export async function updateSheet() {
row[columns.ExternalHours] = hours.external
row[columns.EventHours] = hours.event
row[columns.SummerHours] = hours.summer
row[columns.OutreachHours] = hours.outreach
row[columns.QualifyingHours] = hours.qualifying
row[columns.TotalHours] = hours.total
row[columns.WeeklyHours] = weeklyHours[m.email] ?? 0
Expand Down
8 changes: 4 additions & 4 deletions src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export function scheduleTasks() {

// Slack is silly and can only handle 5 items in the overflow menu
scheduleCronTask(createTaskFunc(promptCheckinMessage), '0 19 * * FRI')
tasks["Sync Sheet"] = scheduleTask(updateSheet, 60 * 5, isProd, 0)
tasks["Sync Slack Members"] = scheduleTask(syncSlackMembers, 60 * 60, isProd, 0) // can be run from the admin members page
tasks["Update profile Certs"] = scheduleTask(updateProfileCerts, 60 * 60 * 24, isProd, 5 * 60)
tasks["Update Profile Departments"] = scheduleTask(updateProfileDepartments, 60 * 60 * 24, isProd, 10 * 60)
tasks['Sync Sheet'] = scheduleTask(updateSheet, 60 * 5, isProd, 0)
tasks['Sync Slack Members'] = scheduleTask(syncSlackMembers, 60 * 60, isProd, 0) // can be run from the admin members page
tasks['Update profile Certs'] = scheduleTask(updateProfileCerts, 60 * 60 * 24, isProd, 5 * 60)
tasks['Update Profile Departments'] = scheduleTask(updateProfileDepartments, 60 * 60 * 24, isProd, 10 * 60)
}

export async function runTask(key: string) {
Expand Down

0 comments on commit d1d0c7e

Please sign in to comment.