Juggling commited on
Commit
d83795d
·
verified ·
1 Parent(s): 1402066

Sort availability dict before trying to assign people to workshops

Browse files
Files changed (1) hide show
  1. workshops.py +28 -6
workshops.py CHANGED
@@ -141,11 +141,13 @@ def find_all_schedules(people: list, availability: dict, schedule_obj: Schedule,
141
  # Unchoose (remove that person from the timeslot)
142
  schedule_obj.remove(person, time)
143
  # NOTE: this will not generate a full timeslot, but could still lead to a good schedule
 
144
  else:
145
  if len(people) == 1:
146
  find_all_schedules([], availability, schedule_obj, capacity, schedules, max_timeslots_list, max_workshops_list)
147
  else:
148
  find_all_schedules(people[1:len(people)], availability, schedule_obj, capacity, schedules, max_timeslots_list, max_workshops_list)
 
149
 
150
  return
151
 
@@ -348,16 +350,34 @@ def main(df, capacity:int, num_results: int, og_slots: list):
348
  res = convert_df(df)
349
  people = res[0]
350
  availability = res[1]
351
- print(availability)
 
 
 
 
 
 
 
 
 
 
352
 
353
  partial_names = []
354
 
355
  timeslots = initialize_timeslots(df)
356
-
357
  schedules = []
358
  schedule_obj = Schedule(timeslots)
359
- max_timeslots_list = [0]
360
- max_workshops_list = [0]
 
 
 
 
 
 
 
 
 
361
 
362
  find_all_schedules(people, availability, schedule_obj, capacity, schedules, max_timeslots_list, max_workshops_list)
363
 
@@ -426,8 +446,10 @@ theme = gr.themes.Soft(
426
  )
427
 
428
  ### Connect to Supabase ###
429
- URL = os.environ['URL']
430
- API_KEY = os.environ['API_KEY']
 
 
431
  client = supabase.create_client(URL, API_KEY)
432
 
433
 
 
141
  # Unchoose (remove that person from the timeslot)
142
  schedule_obj.remove(person, time)
143
  # NOTE: this will not generate a full timeslot, but could still lead to a good schedule
144
+ '''
145
  else:
146
  if len(people) == 1:
147
  find_all_schedules([], availability, schedule_obj, capacity, schedules, max_timeslots_list, max_workshops_list)
148
  else:
149
  find_all_schedules(people[1:len(people)], availability, schedule_obj, capacity, schedules, max_timeslots_list, max_workshops_list)
150
+ '''
151
 
152
  return
153
 
 
350
  res = convert_df(df)
351
  people = res[0]
352
  availability = res[1]
353
+
354
+ # Sorts a dictionary by length of the values such that the
355
+ # key associated with the shortest value is first in the list {orders}
356
+ order = sorted(availability, key=lambda k: len(availability[k]))
357
+
358
+ # The idea is start with people who are the LEAST available to teach,
359
+ # then put the more available instructors into the available slots
360
+ new_dict = {}
361
+ for instructor in order:
362
+ new_dict[instructor] = availability[instructor]
363
+ availability = new_dict
364
 
365
  partial_names = []
366
 
367
  timeslots = initialize_timeslots(df)
 
368
  schedules = []
369
  schedule_obj = Schedule(timeslots)
370
+
371
+ # Get the bare minimum of workshops that will be taught
372
+ distinct_slots = set()
373
+ for curr_list in availability.values():
374
+ for elem in curr_list:
375
+ distinct_slots.add(elem)
376
+ num_distinct_slots = len(distinct_slots)
377
+
378
+
379
+ max_timeslots_list = [num_distinct_slots]
380
+ max_workshops_list = [num_distinct_slots]
381
 
382
  find_all_schedules(people, availability, schedule_obj, capacity, schedules, max_timeslots_list, max_workshops_list)
383
 
 
446
  )
447
 
448
  ### Connect to Supabase ###
449
+ # URL = os.environ['URL'] # TODO
450
+ URL = 'https://ubngctgvhjgxkvimdmri.supabase.co'
451
+ #API_KEY = os.environ['API_KEY']
452
+ API_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVibmdjdGd2aGpneGt2aW1kbXJpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzQ5MjAwOTQsImV4cCI6MjA1MDQ5NjA5NH0.NtGdfP8GYNuYdPdsaLW5GjgfB0_7Q1kNBIDJtPhO8nY'
453
  client = supabase.create_client(URL, API_KEY)
454
 
455