Skip to content

Commit 31ca7ef

Browse files
Fixed support for Y-session courses (#1757)
Co-authored-by: Jason D. / Purplegaze <purplecoin64@gmail.com>
1 parent c532b25 commit 31ca7ef

15 files changed

Lines changed: 445 additions & 395 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Remove period after instructor's first name in course info modal
1313
- Fixed a bug regarding the scrollbar appearing on the /graph and /generate pages
1414
- Fix bool node centering in Generate page
15+
- Fixed support for year-long ("Y" session) courses
1516

1617
### 🔧 Internal changes
1718

app/Config.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ createReqBody page = object [ "campuses" .= ([] :: [T.Text]),
183183
"page" .= page,
184184
"pageSize" .= (300 :: Int),
185185
"requirementProps" .= ([] :: [T.Text]),
186-
"sessions" .= (["20269", "20271"] :: [T.Text]),
186+
"sessions" .= (["20269", "20271", "20269-20271"] :: [T.Text]),
187187
"timePreferences" .= ([] :: [T.Text])
188188
]
189189

app/Database/Migrations.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ applyMigrations currVersion migrations = do
3333
migrationList :: [MigrationWrapper]
3434
migrationList = [ MigrationWrapper {version=2, script=renamePostTables}
3535
, MigrationWrapper {version=3, script=renameCoursesTable}
36+
, MigrationWrapper {version=4, script=splitTimes}
3637
]
3738

3839
-- | Migration script which renames the Post tables to Program
@@ -47,6 +48,13 @@ renameCoursesTable :: Migration
4748
renameCoursesTable =
4849
addMigration True "ALTER TABLE courses RENAME TO course;"
4950

51+
-- | Migration script to add proper support for year-long courses
52+
splitTimes :: Migration
53+
splitTimes = do
54+
addMigration True "ALTER TABLE times RENAME COLUMN first_room TO location;"
55+
addMigration True "ALTER TABLE times DROP COLUMN second_room;"
56+
addMigration True "ALTER TABLE times ADD session varchar(32);"
57+
5058
-- | Gets the current version of the database.
5159
-- If no version is defined, initialize the
5260
-- version to the latest version and return that.

app/Database/Tables.hs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ Meeting
7070
UniqueMeeting code session section
7171

7272
Times
73+
session T.Text Maybe
7374
weekDay Double
7475
startHour Double
7576
endHour Double
7677
meeting MeetingId
77-
firstRoom T.Text Maybe
78-
secondRoom T.Text Maybe
78+
location T.Text Maybe
7979

8080
Breadth
8181
description T.Text
@@ -161,20 +161,20 @@ SchemaVersion
161161
-- ** TODO: Remove these extra types and class instances
162162

163163
data Time' =
164-
Time' { weekDay' :: Double,
164+
Time' { timeSession' :: Maybe T.Text,
165+
weekDay' :: Double,
165166
startHour' :: Double,
166167
endHour' :: Double,
167-
firstLocation' :: Maybe T.Text,
168-
secondLocation' :: Maybe T.Text
168+
timeLocation' :: Maybe T.Text
169169
} deriving (Show, Eq, Generic)
170170

171171
data Time =
172-
Time { weekDay :: Double,
173-
startHour :: Double,
174-
endHour :: Double,
175-
firstLocation :: Maybe Building,
176-
secondLocation :: Maybe Building
177-
} deriving (Show, Generic)
172+
Time { timeSession :: Maybe T.Text,
173+
weekDay :: Double,
174+
startHour :: Double,
175+
endHour :: Double,
176+
timeLocation :: Maybe Building
177+
} deriving (Show, Generic)
178178

179179
-- | A Meeting with its associated Times.
180180
data MeetTime = MeetTime {meetInfo :: Meeting, timeInfo :: [Time'] }
@@ -229,12 +229,11 @@ instance FromJSON Time' where
229229

230230
building <- o .: "building"
231231
buildingCode <- building .: "buildingCode"
232-
buildingRoomNumber <- building .: "buildingRoomNumber"
233-
let meetingRoom1 = Just (T.concat [buildingCode, buildingRoomNumber])
234-
meetingRoom2 <- o .:? "assignedRoom2" .!= Nothing
232+
233+
session <- o .: "sessionCode"
235234

236235
let (adjustedDay, adjustedStartTime, adjustedEndTime) = convertTimeVals meetingDay meetingStartTime meetingEndTime
237-
return $ Time' adjustedDay adjustedStartTime adjustedEndTime meetingRoom1 meetingRoom2
236+
return $ Time' session adjustedDay adjustedStartTime adjustedEndTime buildingCode
238237

239238
instance FromJSON MeetTime where
240239
parseJSON (Object o) = do

app/Models/Time.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ import Models.Building (getBuilding)
88
-- | Convert a Times record into a Time by resolving room codes to Buildings
99
buildTime :: Times -> SqlPersistM Time
1010
buildTime t = do
11-
room1 <- getBuilding (timesFirstRoom t)
12-
room2 <- getBuilding (timesSecondRoom t)
13-
return $ Time (timesWeekDay t)
11+
location <- getBuilding (timesLocation t)
12+
return $ Time (timesSession t)
13+
(timesWeekDay t)
1414
(timesStartHour t)
1515
(timesEndHour t)
16-
room1
17-
room2
16+
location
1817

1918
buildTimes :: MeetingId -> Time' -> Times
2019
buildTimes meetingKey t =
21-
Times (weekDay' t)
20+
Times (timeSession' t)
21+
(weekDay' t)
2222
(startHour' t)
2323
(endHour' t)
2424
meetingKey
25-
(firstLocation' t)
26-
(secondLocation' t)
25+
(timeLocation' t)

backend-test/Controllers/CourseControllerTests.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ retrieveCourseTestCases =
5858
}
5959
[
6060
Time' {
61+
timeSession' = Just "F",
6162
weekDay' = 0.0,
6263
startHour' = 10.0,
6364
endHour' = 11.0,
64-
firstLocation' = Just "MP",
65-
secondLocation' = Nothing
65+
timeLocation' = Just "MP"
6666
},
6767
Time' {
68+
timeSession' = Just "F",
6869
weekDay' = 2.0,
6970
startHour' = 13.0,
7071
endHour' = 14.0,
71-
firstLocation' = Just "SS",
72-
secondLocation' = Nothing
72+
timeLocation' = Just "SS"
7373
}
7474
],
7575
MeetTime
@@ -85,23 +85,23 @@ retrieveCourseTestCases =
8585
}
8686
[
8787
Time' {
88+
timeSession' = Just "S",
8889
weekDay' = 1.0,
8990
startHour' = 10.0,
9091
endHour' = 11.0,
91-
firstLocation' = Just "WW",
92-
secondLocation' = Nothing
92+
timeLocation' = Just "WW"
9393
},
9494
Time' {
95+
timeSession' = Just "S",
9596
weekDay' = 4.0,
9697
startHour' = 13.0,
9798
endHour' = 14.0,
98-
firstLocation' = Just "SS",
99-
secondLocation' = Nothing
99+
timeLocation' = Just "SS"
100100
}
101101
]
102102
],
103103
200,
104-
"{\"allMeetingTimes\":[{\"meetData\":{\"cap\":50,\"code\":\"STA238\",\"enrol\":15,\"extra\":0,\"instructor\":\"Instructor Name\",\"section\":\"LEC0101\",\"session\":\"F\",\"wait\":0},\"timeData\":[{\"endHour\":11,\"firstLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"MP\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"MP\",\"buildingPostalCode\":\"A1A 1A1\"},\"secondLocation\":null,\"startHour\":10,\"weekDay\":0},{\"endHour\":14,\"firstLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"SS\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"SS\",\"buildingPostalCode\":\"A1A 1A1\"},\"secondLocation\":null,\"startHour\":13,\"weekDay\":2}]}],\"breadth\":null,\"coreqs\":\"CSC108H1/ CSC110Y1/ CSC148H1 *Note: the corequisite may be completed either concurrently or in advance.\",\"description\":\"An introduction to statistical inference and practice. Statistical models and parameters, estimators of parameters and their statistical properties, methods of estimation, confidence intervals, hypothesis testing, likelihood function, the linear model. Use of statistical computation for data analysis and simulation.\",\"distribution\":null,\"exclusions\":\"ECO220Y1/ ECO227Y1/ GGR270H1/ PSY201H1/ SOC300H1/ SOC202H1/ SOC252H1/ STA220H1/ STA221H1/ STA255H1/ STA248H1/ STA261H1/ STA288H1/ EEB225H1/ STAB22H3/ STAB27H3/ STAB57H3/ STA220H5/ STA221H5/ STA258H5/ STA260H5/ ECO220Y5/ ECO227Y5\",\"name\":\"STA238H1\",\"prereqString\":\"STA237H1/ STA247H1/ STA257H1/ STAB52H3/ STA256H5\",\"title\":\"Probability, Statistics and Data Analysis II\",\"videoUrls\":[\"https://example.com/video1\",\"https://example.com/video2\"]}"
104+
"{\"allMeetingTimes\":[{\"meetData\":{\"cap\":50,\"code\":\"STA238\",\"enrol\":15,\"extra\":0,\"instructor\":\"Instructor Name\",\"section\":\"LEC0101\",\"session\":\"F\",\"wait\":0},\"timeData\":[{\"endHour\":11,\"startHour\":10,\"timeLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"MP\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"MP\",\"buildingPostalCode\":\"A1A 1A1\"},\"timeSession\":\"F\",\"weekDay\":0},{\"endHour\":14,\"startHour\":13,\"timeLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"SS\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"SS\",\"buildingPostalCode\":\"A1A 1A1\"},\"timeSession\":\"F\",\"weekDay\":2}]}],\"breadth\":null,\"coreqs\":\"CSC108H1/ CSC110Y1/ CSC148H1 *Note: the corequisite may be completed either concurrently or in advance.\",\"description\":\"An introduction to statistical inference and practice. Statistical models and parameters, estimators of parameters and their statistical properties, methods of estimation, confidence intervals, hypothesis testing, likelihood function, the linear model. Use of statistical computation for data analysis and simulation.\",\"distribution\":null,\"exclusions\":\"ECO220Y1/ ECO227Y1/ GGR270H1/ PSY201H1/ SOC300H1/ SOC202H1/ SOC252H1/ STA220H1/ STA221H1/ STA255H1/ STA248H1/ STA261H1/ STA288H1/ EEB225H1/ STAB22H3/ STAB27H3/ STAB57H3/ STA220H5/ STA221H5/ STA258H5/ STA260H5/ ECO220Y5/ ECO227Y5\",\"name\":\"STA238H1\",\"prereqString\":\"STA237H1/ STA247H1/ STA257H1/ STAB52H3/ STA256H5\",\"title\":\"Probability, Statistics and Data Analysis II\",\"videoUrls\":[\"https://example.com/video1\",\"https://example.com/video2\"]}"
105105
),
106106

107107
("Course exists with meeting times",
@@ -132,23 +132,23 @@ retrieveCourseTestCases =
132132
}
133133
[
134134
Time' {
135+
timeSession' = Just "F",
135136
weekDay' = 0.0,
136137
startHour' = 10.0,
137138
endHour' = 11.0,
138-
firstLocation' = Just "MP",
139-
secondLocation' = Nothing
139+
timeLocation' = Just "MP"
140140
},
141141
Time' {
142+
timeSession' = Just "F",
142143
weekDay' = 2.0,
143144
startHour' = 13.0,
144145
endHour' = 14.0,
145-
firstLocation' = Just "SS",
146-
secondLocation' = Nothing
146+
timeLocation' = Just "SS"
147147
}
148148
]
149149
],
150150
200,
151-
"{\"allMeetingTimes\":[{\"meetData\":{\"cap\":50,\"code\":\"STA238\",\"enrol\":15,\"extra\":0,\"instructor\":\"Instructor Name\",\"section\":\"LEC0101\",\"session\":\"F\",\"wait\":0},\"timeData\":[{\"endHour\":11,\"firstLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"MP\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"MP\",\"buildingPostalCode\":\"A1A 1A1\"},\"secondLocation\":null,\"startHour\":10,\"weekDay\":0},{\"endHour\":14,\"firstLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"SS\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"SS\",\"buildingPostalCode\":\"A1A 1A1\"},\"secondLocation\":null,\"startHour\":13,\"weekDay\":2}]}],\"breadth\":null,\"coreqs\":\"CSC108H1/ CSC110Y1/ CSC148H1 *Note: the corequisite may be completed either concurrently or in advance.\",\"description\":\"An introduction to statistical inference and practice. Statistical models and parameters, estimators of parameters and their statistical properties, methods of estimation, confidence intervals, hypothesis testing, likelihood function, the linear model. Use of statistical computation for data analysis and simulation.\",\"distribution\":null,\"exclusions\":\"ECO220Y1/ ECO227Y1/ GGR270H1/ PSY201H1/ SOC300H1/ SOC202H1/ SOC252H1/ STA220H1/ STA221H1/ STA255H1/ STA248H1/ STA261H1/ STA288H1/ EEB225H1/ STAB22H3/ STAB27H3/ STAB57H3/ STA220H5/ STA221H5/ STA258H5/ STA260H5/ ECO220Y5/ ECO227Y5\",\"name\":\"STA238H1\",\"prereqString\":\"STA237H1/ STA247H1/ STA257H1/ STAB52H3/ STA256H5\",\"title\":\"Probability, Statistics and Data Analysis II\",\"videoUrls\":[\"https://example.com/video1\",\"https://example.com/video2\"]}"
151+
"{\"allMeetingTimes\":[{\"meetData\":{\"cap\":50,\"code\":\"STA238\",\"enrol\":15,\"extra\":0,\"instructor\":\"Instructor Name\",\"section\":\"LEC0101\",\"session\":\"F\",\"wait\":0},\"timeData\":[{\"endHour\":11,\"startHour\":10,\"timeLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"MP\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"MP\",\"buildingPostalCode\":\"A1A 1A1\"},\"timeSession\":\"F\",\"weekDay\":0},{\"endHour\":14,\"startHour\":13,\"timeLocation\":{\"buildingAddress\":\"N/A\",\"buildingCode\":\"SS\",\"buildingLat\":1,\"buildingLng\":1,\"buildingName\":\"SS\",\"buildingPostalCode\":\"A1A 1A1\"},\"timeSession\":\"F\",\"weekDay\":2}]}],\"breadth\":null,\"coreqs\":\"CSC108H1/ CSC110Y1/ CSC148H1 *Note: the corequisite may be completed either concurrently or in advance.\",\"description\":\"An introduction to statistical inference and practice. Statistical models and parameters, estimators of parameters and their statistical properties, methods of estimation, confidence intervals, hypothesis testing, likelihood function, the linear model. Use of statistical computation for data analysis and simulation.\",\"distribution\":null,\"exclusions\":\"ECO220Y1/ ECO227Y1/ GGR270H1/ PSY201H1/ SOC300H1/ SOC202H1/ SOC252H1/ STA220H1/ STA221H1/ STA255H1/ STA248H1/ STA261H1/ STA288H1/ EEB225H1/ STAB22H3/ STAB27H3/ STAB57H3/ STA220H5/ STA221H5/ STA258H5/ STA260H5/ ECO220Y5/ ECO227Y5\",\"name\":\"STA238H1\",\"prereqString\":\"STA237H1/ STA247H1/ STA257H1/ STAB52H3/ STA256H5\",\"title\":\"Probability, Statistics and Data Analysis II\",\"videoUrls\":[\"https://example.com/video1\",\"https://example.com/video2\"]}"
152152
),
153153

154154
("Course exists",
@@ -253,11 +253,11 @@ insertBuildings = mapM_ insertBuilding
253253
where
254254
insertBuilding code = insert_ Building {buildingCode = code, buildingName = code, buildingAddress = "N/A", buildingPostalCode = "A1A 1A1", buildingLat = 1.0, buildingLng = 1.0}
255255

256-
-- | Helper function to get a list of unique firstLocation' and secondLocation' values involved in a MeetTime
256+
-- | Helper function to get a list of unique locations involved in a MeetTime
257257
getUniqueBuildings :: [MeetTime] -> [T.Text]
258258
getUniqueBuildings = nub . concatMap getMeetBuildings
259259
where
260-
getMeetBuildings (MeetTime _ times') = mapMaybe firstLocation' times' ++ mapMaybe secondLocation' times'
260+
getMeetBuildings (MeetTime _ times') = mapMaybe timeLocation' times'
261261

262262
-- | List of test cases as (label, input courses, expected output)
263263
indexTestCases :: [(String, [T.Text], String)]

0 commit comments

Comments
 (0)