Skip to content

Commit

Permalink
Merge pull request #115 from filips123/fix-substitutions-special-case
Browse files Browse the repository at this point in the history
Handle substitutions special case
  • Loading branch information
filips123 authored Dec 29, 2024
2 parents 2d02b25 + ed577f5 commit 82d41b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A system for a school timetable, substitutions and menus at Gimnazija Vič.

This repository contains a system for a Progressive Web App to show the timetable, substitutions, menus and lunch schedules for students and teachers at Gimnazija Vič.

It uses Python API built with Flask and SQLAlchemy to download and parse the data from the official sources (e-classroom, website) using pdf2docx and bs4. The website is built using Vue.js framework and Vuetify theme. The source code can be found in [`API`](API) and [`website`](website) subdirectories.
It uses Python API built with Flask and SQLAlchemy to download and parse the data from the official sources (e-classroom, website) using pdfplumber and bs4. The website is built using Vue.js framework and Vuetify theme. The source code can be found in [`API`](API) and [`website`](website) subdirectories.

The website is currently deployed at [urnik.gimvic.org](https://urnik.gimvic.org).

Expand Down
46 changes: 45 additions & 1 deletion website/src/components/TimetableDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,50 @@ function filterForTargetDay(lessonsTime: MergedLesson[][]) {
if (typeof targetDay !== 'undefined') return [lessonsTime[targetDay]]
return lessonsTime
}
function handleSubstitutionsSpecialCase(lessonsTimeDay: MergedLesson[]) {
// Important: This can cause breaking changes when multiple entities have overlapping times
// Special cases occur only when multiple lessons happen at the same time in the class view
// This accounts for ŠVM/ŠVŽ, INFV/INF and language lessons happening at the same time (FRA/ITA/NEM/ŠPA)
if (currentEntityType.value === EntityType.Class && lessonsTimeDay.length > 1) {
// If subjects that are not in the timetable originally appear, we replace the original subjects with them
if (lessonsTimeDay.find(l => l.subject === null)) {
return lessonsTimeDay.filter(l => l.subject === null)
}
// A subject change needs to be present as this is the breaking point
const lesson: MergedLesson | undefined = lessonsTimeDay.find(
l => l.isSubstitution && l.substitutionSubject !== l.subject,
)
if (!lesson) return lessonsTimeDay
// We need to treat ŠVM/ŠVŽ and INFV/INF as the same subject, so that what happens to one also happens to another
if (['ŠVM', 'ŠVŽ', 'INFV', 'INF'].includes(lesson.subject!)) {
if (lessonsTimeDay.length > 2) {
// When there are more than two subjects, it means a new subject has appeared
// We then need to delete the original subjects
return lessonsTimeDay.filter(l => !['ŠVM', 'ŠVŽ', 'INFV', 'INF'].includes(l.subject || ''))
} else {
// We keep only the element of the subject pair that changed
return lessonsTimeDay.filter(l => l === lesson)
}
}
// At this point we are left only with languages
const LanguageLesson: MergedLesson | undefined = lessonsTimeDay.find(
l => l.isSubstitution && !['FRA', 'ITA', 'NEM', 'ŠPA', null].includes(l.substitutionSubject),
)
if (!LanguageLesson) return lessonsTimeDay
// If a subject was changed for another, then all the languages are substituted with the new subject
return [LanguageLesson!]
}
return lessonsTimeDay
}
</script>

<template>
Expand Down Expand Up @@ -127,7 +171,7 @@ function filterForTargetDay(lessonsTime: MergedLesson[][]) {
class="w-100"
>
<tr
v-for="lesson in lessonsTimeDay"
v-for="lesson in handleSubstitutionsSpecialCase(lessonsTimeDay)"
:key="`${lesson.time}-${lesson.day}-${lesson.class}-${lesson.teacher}-${lesson.classroom}`"
>
<TimetableLesson :lesson="lesson" />
Expand Down
5 changes: 2 additions & 3 deletions website/src/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ export const useSettingsStore = defineStore('settings', {

showSubstitutions: true,
showLinksInTimetable: true,
highlightCurrentTime: true,
enableLessonDetails: true,

showDatesInTimetable: true,
showHoursInTimetable: true,
highlightCurrentTime: true,
enableLessonDetails: true,
enablePullToRefresh: true,

dataCollectionPerformance: navigator.doNotTrack !== '1' && !navigator.globalPrivacyControl,
Expand Down

0 comments on commit 82d41b8

Please sign in to comment.