Skip to content

Display semester half hours as Q1/Q2 or Q3/Q4 based on semester #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ function HydrantApp() {
selectedActivities={state.selectedActivities}
units={state.units}
hours={state.hours}
hoursFirstHalf={state.hoursFirstHalf}
hoursSecondHalf={state.hoursSecondHalf}
warnings={state.warnings}
state={hydrant}
/>
Expand Down
17 changes: 15 additions & 2 deletions src/components/SelectedActivities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,29 @@ export function SelectedActivities(props: {
selectedActivities: Array<Activity>;
units: number;
hours: number;
hoursFirstHalf: number;
hoursSecondHalf: number;
warnings: Array<string>;
state: State;
}) {
const { selectedActivities, units, hours, warnings, state } = props;
const { selectedActivities, units, hours, hoursFirstHalf, hoursSecondHalf, warnings, state } = props;

const formatHours = () => {
if (hoursFirstHalf === hoursSecondHalf) {
return `${hours.toFixed(1)} hours`;
}

// Use Q1/Q2 for fall semester, Q3/Q4 for spring semester
const [firstLabel, secondLabel] = state.term.semester === 'f' ? ['Q1', 'Q2'] : ['Q3', 'Q4'];

return `\u2264 ${hours.toFixed(1)} hours (${hoursFirstHalf.toFixed(1)} ${firstLabel}, ${hoursSecondHalf.toFixed(1)} ${secondLabel})`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might as well use ≤ directly in the string

also, what's the rationale for having ≤ here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see the rationale for ≤

can we have a tooltip instead though?

};

return (
<Flex direction="column" gap={2}>
<Flex gap={8} justify="center">
<Text>{units} units</Text>
<Text>{hours.toFixed(1)} hours</Text>
<Text>{formatHours()}</Text>
</Flex>
<ButtonGroup gap={0} wrap="wrap">
{selectedActivities.map((activity) => (
Expand Down
4 changes: 4 additions & 0 deletions src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type HydrantState = {
totalOptions: number;
units: number;
hours: number;
hoursFirstHalf: number;
hoursSecondHalf: number;
Comment on lines 35 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about the type

hours: { firstHalf: number; secondHalf: number; }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and omit the max hours, which i think we can recompute in the thing when we need to? unless we use it somewhere else

warnings: Array<string>;
saveId: string;
saves: Array<Save>;
Expand All @@ -47,6 +49,8 @@ export const DEFAULT_STATE: HydrantState = {
totalOptions: 0,
units: 0,
hours: 0,
hoursFirstHalf: 0,
hoursSecondHalf: 0,
warnings: [],
saveId: "",
saves: [],
Expand Down
32 changes: 31 additions & 1 deletion src/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,50 @@ export class State {
* localStorage.
*/
updateState(save: boolean = true): void {
// Calculate hours for each half
const firstHalfHours = sum(
this.selectedActivities
.filter(act => {
if ('rawClass' in act) {
// Include if class is full semester or first half
return !act.rawClass.half || act.rawClass.half === 1;
}
// Include all non-class activities in both halves
return true;
Comment on lines +203 to +208
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you feel about

act => !('rawClass' in act) || !act.rawClass.half || act.rawClass.half === 1

or perhaps

act => [
  !('rawClass' in act), // non-class activity
  !act.rawClass.half, // full-semester class
  act.rawClass.half === 1, // first half
].some(Boolean)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very nit-ty btw, so take it or leave it

})
.map(activity => activity.hours)
);

const secondHalfHours = sum(
this.selectedActivities
.filter(act => {
if ('rawClass' in act) {
// Include if class is full semester or second half
return !act.rawClass.half || act.rawClass.half === 2;
}
// Include all non-class activities in both halves
return true;
})
.map(activity => activity.hours)
);

this.callback?.({
selectedActivities: this.selectedActivities,
viewedActivity: this.viewedActivity,
selectedOption: this.selectedOption,
totalOptions: this.options.length,
units: sum(this.selectedClasses.map((cls) => cls.totalUnits)),
hours: sum(this.selectedActivities.map((activity) => activity.hours)),
hours: Math.max(firstHalfHours, secondHalfHours), // Use max for total hours
hoursFirstHalf: firstHalfHours,
hoursSecondHalf: secondHalfHours,
warnings: Array.from(
new Set(this.selectedClasses.flatMap((cls) => cls.warnings.messages)),
),
saveId: this.saveId,
saves: this.saves,
preferences: this.preferences,
});

if (save) {
this.storeSave(this.saveId, false);
}
Expand Down
Loading