@@ -98,6 +98,32 @@ def create_section(depth: int, title: str, content: str, if_empty: str | None =
9898 return f"{ '#' * depth } { title } \n \n { content .strip ()} \n \n "
9999
100100
101+ def create_listing_link (row : pd .Series ):
102+ return f"[{ row ['course_code' ]} { row ['section' ]} ](https://coursetable.com/catalog?course-modal={ row ['season_code' ]} -{ row ['crn' ]} )"
103+
104+
105+ weekdays = {
106+ "Su" : 0 ,
107+ "M" : 1 ,
108+ "T" : 2 ,
109+ "W" : 3 ,
110+ "Th" : 4 ,
111+ "F" : 5 ,
112+ "Sa" : 6 ,
113+ }
114+
115+
116+ def print_days_of_week (days_of_week : int ):
117+ days = []
118+ for day , value in weekdays .items ():
119+ if days_of_week & (1 << value ):
120+ days .append (day )
121+ res = "" .join (days )
122+ if res == "MTWThF" :
123+ return "M–F"
124+ return res
125+
126+
101127# TODO: use this to print same_course changes
102128def analyze_partition_diff (old_partition : pd .Series , new_partition : pd .Series ):
103129 """
@@ -171,34 +197,28 @@ def print_course_changes(
171197 old_profs , new_profs = old ["professor_id" ], new ["professor_id" ]
172198 old_profs_info = prof_info .loc [old_profs ]
173199 new_profs_info = prof_info .loc [new_profs ]
174- res += f" - Professor: { ", " .join (old_profs_info ['name' ]) or "N/A" } -> { ", " .join (new_profs_info ['name' ]) or "N/A" } \n "
200+ res += f" - Professor: { ", " .join (old_profs_info ['name' ]) or "N/A" } → { ", " .join (new_profs_info ['name' ]) or "N/A" } \n "
175201 elif column == "flags" :
176202 old_flags , new_flags = old ["flag_id" ], new ["flag_id" ]
177203 old_flags_info = flag_info .loc [old_flags ]
178204 new_flags_info = flag_info .loc [new_flags ]
179- res += f" - Flags: { ", " .join (old_flags_info ['flag_text' ]) or "N/A" } -> { ", " .join (new_flags_info ['flag_text' ]) or "N/A" } \n "
205+ res += f" - Flags: { ", " .join (old_flags_info ['flag_text' ]) or "N/A" } → { ", " .join (new_flags_info ['flag_text' ]) or "N/A" } \n "
180206 elif column == "meetings" :
181207 old_meetings = old .apply (
182- lambda row : f"{ row ['days_of_week' ]} { row ['start_time' ]} –{ row ['end_time' ]} { location_info .loc [row ['location_id' ]]['name' ] if not pd .isna (row ['location_id' ]) else '' } " ,
208+ lambda row : f"{ print_days_of_week ( row ['days_of_week' ]) } { row ['start_time' ]} –{ row ['end_time' ]} { location_info .loc [row ['location_id' ]]['name' ] if not pd .isna (row ['location_id' ]) else '' } " ,
183209 axis = 1 ,
184210 )
185211 new_meetings = new .apply (
186- lambda row : f"{ row ['days_of_week' ]} { row ['start_time' ]} –{ row ['end_time' ]} { location_info .loc [row ['location_id' ]]['name' ] if not pd .isna (row ['location_id' ]) else '' } " ,
212+ lambda row : f"{ print_days_of_week ( row ['days_of_week' ]) } { row ['start_time' ]} –{ row ['end_time' ]} { location_info .loc [row ['location_id' ]]['name' ] if not pd .isna (row ['location_id' ]) else '' } " ,
187213 axis = 1 ,
188214 )
189- res += f" - Meetings: { ", " .join (old_meetings ) or "N/A" } -> { ", " .join (new_meetings ) or "N/A" } \n "
215+ res += f" - Meetings: { ", " .join (old_meetings ) or "N/A" } → { ", " .join (new_meetings ) or "N/A" } \n "
190216 elif column == "listings" :
191- old_listings = old .apply (
192- lambda row : f"[{ row ['course_code' ]} ](https://coursetable.com/catalog?course-modal={ row ["season_code" ]} -{ row ["crn" ]} )" ,
193- axis = 1 ,
194- )
195- new_listings = new .apply (
196- lambda row : f"[{ row ['course_code' ]} ](https://coursetable.com/catalog?course-modal={ row ["season_code" ]} -{ row ["crn" ]} )" ,
197- axis = 1 ,
198- )
199- res += f" - Listings: { " / " .join (old_listings ) or "N/A" } -> { " / " .join (new_listings ) or "N/A" } \n "
217+ old_listings = old .apply (create_listing_link , axis = 1 )
218+ new_listings = new .apply (create_listing_link , axis = 1 )
219+ res += f" - Listings: { " / " .join (old_listings ) or "N/A" } → { " / " .join (new_listings ) or "N/A" } \n "
200220 else :
201- res += f" - { column } : { old if not pd .isna (old ) else "N/A" } -> { new if not pd .isna (new ) else "N/A" } \n "
221+ res += f" - { column } : { old if not pd .isna (old ) else "N/A" } → { new if not pd .isna (new ) else "N/A" } \n "
202222 return res
203223
204224
@@ -220,7 +240,7 @@ def print_table_diff(
220240 continue
221241 old_val = table_old [table_old [pk ] == row [pk ]][column ].values [0 ]
222242 new_val = table_new [table_new [pk ] == row [pk ]][column ].values [0 ]
223- update += f" - { column } : { old_val if not pd .isna (old_val ) else 'N/A' } -> { new_val if not pd .isna (new_val ) else 'N/A' } \n "
243+ update += f" - { column } : { old_val if not pd .isna (old_val ) else 'N/A' } → { new_val if not pd .isna (new_val ) else 'N/A' } \n "
224244 if update :
225245 updates += f"{ identify_row (row )} { update } "
226246 changes = ""
@@ -243,10 +263,7 @@ def print_courses_diff(
243263 listings_already_exist = listings [
244264 listings ["listing_id" ].isin (tables_old ["listings" ]["listing_id" ])
245265 ]
246- links = listings .apply (
247- lambda row : f"[{ row ['course_code' ]} ](https://coursetable.com/catalog?course-modal={ row ["season_code" ]} -{ row ["crn" ]} )" ,
248- axis = 1 ,
249- )
266+ links = listings .apply (create_listing_link , axis = 1 )
250267 course_additions += (
251268 f"- { course .season_code } { " / " .join (links )} { course .title } \n "
252269 )
@@ -260,10 +277,7 @@ def print_courses_diff(
260277 listings_still_exist = listings [
261278 listings ["listing_id" ].isin (tables ["listings" ]["listing_id" ])
262279 ]
263- links = listings .apply (
264- lambda row : f"[{ row ['course_code' ]} ](https://coursetable.com/catalog?course-modal={ row ["season_code" ]} -{ row ["crn" ]} )" ,
265- axis = 1 ,
266- )
280+ links = listings .apply (create_listing_link , axis = 1 )
267281 course_removals += (
268282 f"- { course .season_code } { " / " .join (links )} { course .title } \n "
269283 )
@@ -335,10 +349,7 @@ def print_courses_diff(
335349 if not changes :
336350 continue
337351 listings = tables ["listings" ][tables ["listings" ]["course_id" ] == course_id ]
338- links = listings .apply (
339- lambda row : f"[{ row ['course_code' ]} ](https://coursetable.com/catalog?course-modal={ row ["season_code" ]} -{ row ["crn" ]} )" ,
340- axis = 1 ,
341- )
352+ links = listings .apply (create_listing_link , axis = 1 )
342353 course = tables ['courses' ][tables ['courses' ]['course_id' ] == course_id ]
343354 course_updates += f"- { course ["season_code" ].values [0 ]} { " / " .join (links )} { course ['title' ].values [0 ]} \n "
344355 course_updates += print_course_changes (
@@ -391,7 +402,7 @@ def print_diff(
391402 continue
392403 listing_changes += f"- [{ listing .season_code } { listing .course_code } { listing .section } ](https://coursetable.com/catalog?course-modal={ listing .season_code } -{ listing .crn } )\n "
393404 for column in columns_changed :
394- listing_changes += f" - { column } : { tables_old ['listings' ][tables_old ['listings' ]['listing_id' ] == listing .listing_id ][column ].values [0 ]} -> { tables ['listings' ][tables ['listings' ]['listing_id' ] == listing .listing_id ][column ].values [0 ]} \n "
405+ listing_changes += f" - { column } : { tables_old ['listings' ][tables_old ['listings' ]['listing_id' ] == listing .listing_id ][column ].values [0 ]} → { tables ['listings' ][tables ['listings' ]['listing_id' ] == listing .listing_id ][column ].values [0 ]} \n "
395406 if listing_changes :
396407 listing_changes = (
397408 "Here we only report listing information changes. Changes to their association with courses (the addition or removal of cross-listings, etc.) are reported in the courses section.\n \n "
0 commit comments