Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 22 additions & 14 deletions packages/api-client/src/generated/analytics/analytics.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/api-client/src/generated/model/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 29 additions & 13 deletions src/modules/analytics/analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export class AnalyticsController {

private async calculateApplicationMetrics(
applications: any[],
hackathonId?: string,
): Promise<ApplicationMetrics> {
const confirmedApplicants = applications.filter(
(app) => app.applicationStatus === "confirmed",
Expand All @@ -458,7 +459,7 @@ export class AnalyticsController {

const confirmedAndScannedApplicants = await this.scanRepo
.findAll()
.byHackathon()
.byHackathon(hackathonId)
.joinRelated("event")
.whereIn(
"user_id",
Expand Down Expand Up @@ -490,35 +491,50 @@ export class AnalyticsController {

@Get("/applications")
@Roles(Role.NONE)
@ApiQuery({
name: "hackathonId",
required: false,
type: String,
description:
"The hackathon ID to fetch application metrics for. Defaults to the active hackathon.",
})
@ApiDoc({
summary: "Get application metrics for each event",
auth: Role.TEAM,
response: {
ok: { type: AnalyticsApplicationsResponse },
},
})
async getApplicationAnalytics() {
const PENN_STATE_UNIVERSITY =
"The Pennsylvania State University - Main Campus";

// Get all registrations with user information for the active hackathon
async getApplicationAnalytics(@Query("hackathonId") hackathonId?: string) {
// Matches every Penn State campus, not just Main Campus
const PENN_STATE_PREFIX = "The Pennsylvania State University";
const isPennState = (university?: string | null) =>
university?.startsWith(PENN_STATE_PREFIX) ?? false;

// Get all registrations with user information for the requested hackathon
// (falls back to the active hackathon when no ID is provided)
const applications = await this.registrationRepo
.findAll()
.byHackathon()
.byHackathon(hackathonId)
.withGraphFetched("user");

// Separate Penn State and Other students
const pennStateApps = applications.filter(
(app) => app.user.university === PENN_STATE_UNIVERSITY,
const pennStateApps = applications.filter((app) =>
isPennState(app.user?.university),
);
const otherApps = applications.filter(
(app) => app.user.university !== PENN_STATE_UNIVERSITY,
(app) => !isPennState(app.user?.university),
);

const pennStateMetrics =
await this.calculateApplicationMetrics(pennStateApps);
const pennStateMetrics = await this.calculateApplicationMetrics(
pennStateApps,
hackathonId,
);

const otherMetrics = await this.calculateApplicationMetrics(otherApps);
const otherMetrics = await this.calculateApplicationMetrics(
otherApps,
hackathonId,
);

return {
pennState: pennStateMetrics,
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5067,11 +5067,11 @@ gtoken@^8.0.0:
jws "^4.0.0"

handlebars@^4.7.8, handlebars@^4.7.9:
version "4.7.9"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.9.tgz#6f139082ab58dc4e5a0e51efe7db5ae890d56a0f"
integrity sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==
version "4.7.10"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.10.tgz#12419ea1b41391b3ffcf003f2164dcbce090c417"
integrity sha512-P5VJMVM7qgBn6vjXMw8WG9uVI+ncf2pi72j4de4yz5ZULLj2RGqLYaKOYGsgyrViQ0tePOVlN1tDCCXXtFqXKg==
dependencies:
minimist "^1.2.5"
minimist "^1.2.8"
neo-async "^2.6.2"
source-map "^0.6.1"
wordwrap "^1.0.0"
Expand Down Expand Up @@ -6442,7 +6442,7 @@ minimatch@^9.0.4:
dependencies:
brace-expansion "^2.0.2"

minimist@^1.2.5, minimist@^1.2.6:
minimist@^1.2.6, minimist@^1.2.8:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
Expand Down
Loading