Skip to content

Commit

Permalink
changed totalcreditsinschedule function to take in transfer credit co…
Browse files Browse the repository at this point in the history
…urses and calculate everything

transferred the calculation logic into the totalcreditsinschedule function
  • Loading branch information
denniwang committed Sep 22, 2024
1 parent 6c7678c commit b00e5c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
17 changes: 6 additions & 11 deletions packages/frontend/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,11 @@ const Sidebar: React.FC<SidebarProps> = memo(
concentrationValidationStatus = SidebarValidationStatus.Error;
}

const transferCredits = transferCourses.reduce(
(sum, course) => course.numCreditsMin + sum,
0
const creditsTaken = totalCreditsInSchedule(
selectedPlan.schedule,
transferCourses
);

const creditsTaken =
totalCreditsInSchedule(selectedPlan.schedule) + transferCredits;

return (
<SidebarContainer
title={major.name}
Expand Down Expand Up @@ -260,12 +257,10 @@ export const NoMajorSidebar: React.FC<NoMajorSidebarProps> = ({
selectedPlan,
transferCourses,
}) => {
const transferCredits = transferCourses.reduce(
(sum, course) => course.numCreditsMin + sum,
0
const creditsTaken = totalCreditsInSchedule(
selectedPlan.schedule,
transferCourses
);
const creditsTaken =
totalCreditsInSchedule(selectedPlan.schedule) + transferCredits;
return (
<SidebarContainer
title="No Major"
Expand Down
15 changes: 11 additions & 4 deletions packages/frontend/utils/plan/totalCredits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Schedule2, ScheduleTerm2, ScheduleYear2 } from "@graduate/common";
import {
Schedule2,
ScheduleCourse2,
ScheduleTerm2,
ScheduleYear2,
} from "@graduate/common";

/** The credits for all courses in a term. */
export const totalCreditsInTerm = (term: ScheduleTerm2<unknown>): number => {
Expand All @@ -23,12 +28,14 @@ export const totalCreditsInYear = (

/** The credits for all courses in a schedule summed. */
export const totalCreditsInSchedule = (
schedule: Schedule2<unknown>
schedule: Schedule2<unknown>,
transfer: ScheduleCourse2<unknown>[]
): number => {
return (
schedule.years.reduce(
(schedule.years.reduce(
(totalCredits, year) => totalCreditsInYear(year) + totalCredits,
0
) ?? 0
) ?? 0) +
(transfer.reduce((sum, course) => course.numCreditsMin + sum, 0) ?? 0)
);
};

0 comments on commit b00e5c8

Please sign in to comment.