Skip to content

Commit

Permalink
Merge branch 'crowd-sourced-data' of https://github.com/asuc-octo/ber…
Browse files Browse the repository at this point in the history
…keleytime into crowd-sourced-data
  • Loading branch information
PineND committed Oct 30, 2024
2 parents 344993b + 8938ca8 commit 31835b6
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 242 deletions.
10 changes: 5 additions & 5 deletions apps/backend/src/modules/class/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import {
} from "../../generated-types/graphql";
import { ClassModule } from "./generated-types/module-types";

export type IntermediateClass = Omit<
ClassModule.Class,
"course" | "term" | "primarySection" | "sections"
> & {
interface Relationships {
course: null;
term: null;
primarySection: null;
sections: null;
gradeDistribution: null;
};
}

export type IntermediateClass = Omit<ClassModule.Class, keyof Relationships> &
Relationships;

export const formatDate = (date?: string | number | Date | null) => {
if (!date) return date;
Expand Down
13 changes: 8 additions & 5 deletions apps/backend/src/modules/course/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import {
import { formatDate } from "../class/formatter";
import { CourseModule } from "./generated-types/module-types";

export type IntermediateCourse = Omit<
CourseModule.Course,
"classes" | "crossListing" | "requiredCourses" | "gradeDistribution"
> & {
interface Relationships {
classes: null;
crossListing: string[];
requiredCourses: string[];
gradeDistribution: null;
};
}

export type IntermediateCourse = Omit<
CourseModule.Course,
keyof Relationships
> &
Relationships;

export function formatCourse(course: CourseType) {
return {
Expand Down
10 changes: 6 additions & 4 deletions apps/backend/src/modules/grade-distribution/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,23 @@ export const points: { [key: string]: number } = {
D: 1,
"D-": 0.7,
"D+": 1.3,
F: 0,
};

export const getAverageGrade = (distribution: Grade[]) => {
const total = distribution.reduce((acc, { letter, count }) => {
if (points[letter]) return acc + count;
if (Object.keys(points).includes(letter)) return acc + count;

// Ignore letters not included in grade point average
// Ignore letters not included in GPA
return acc;
}, 0);

// For distributions without a grade point average, return null
// For distributions without a GPA, return null
if (total === 0) return null;

const weightedTotal = distribution.reduce((acc, { letter, count }) => {
if (points[letter]) return points[letter] * count + acc;
if (Object.keys(points).includes(letter))
return points[letter] * count + acc;

return acc;
}, 0);
Expand Down
13 changes: 8 additions & 5 deletions apps/backend/src/modules/schedule/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { ScheduleType } from "@repo/common";

import { ScheduleModule } from "./generated-types/module-types";

interface Relationships {
classes: ScheduleModule.SelectedClassInput[];
term: null;
}

export type IntermediateSchedule = Omit<
ScheduleModule.Schedule,
"term" | "classes"
> & {
term: null;
classes: ScheduleModule.SelectedClassInput[];
};
keyof Relationships
> &
Relationships;

export const formatSchedule = async (schedule: ScheduleType) => {
return {
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/modules/user/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { UserType } from "@repo/common";

import { UserModule } from "./generated-types/module-types";

export type IntermediateUser = Omit<
UserModule.User,
"bookmarkedClasses" | "bookmarkedCourses"
> & {
interface Relationships {
bookmarkedCourses: UserModule.BookmarkedCourseInput[];
bookmarkedClasses: UserModule.BookmarkedClassInput[];
};
}

export type IntermediateUser = Omit<UserModule.User, keyof Relationships> &
Relationships;

export const formatUser = (user: UserType) => {
return {
Expand Down
Loading

0 comments on commit 31835b6

Please sign in to comment.