schedules module

class schedules.Schedule(project_id: str, schedule_id: typing.Optional[int] = None, label: str = l'New schedule')

Bases: object

A schedule is essentially a combination of courses stored as a master course, from which some events can be removed.

Parameters

project_id – the schedule id matching this of the Database it is currently saved in. This parameter is automatically set when the schedule is saved for the first time.

add_course(codes: Union[Iterable[str], str]) List[str]

Adds one or many courses to the schedule.

Parameters

codes (Union[Iterable[str], str])) – the codes of the course added

Returns

all the new codes added to the schedule

Return type

List[str]

add_custom_event(event: backend.events.CustomEvent)

Adds a custom event to the schedule.

Parameters

event (CustomEvent (or RecurringCustomEvent)) – the event to add

add_filter(code: str, filter: Union[Iterable[str], str])
compute_best(n_best: int = 5, safe_compute: bool = True) List[Iterable[backend.events.CustomEvent]]

Computes best schedules trying to minimize conflicts selecting, for each type of event, one event.

Parameters
  • n_best (int) – number of best schedules to produce

  • safe_compute (bool) – if True, ignore all redundant events at same time period

Returns

the n_best schedules, but maybe less if cannot find n_best different schedules

Return type

List[Iterable[evt.CustomEvent]]

get_courses() List[backend.courses.Course]

Returns all the courses of this schedule as a list.

Returns

the courses

Return type

List[Course]

get_custom_event(id: str) Optional[backend.events.CustomEvent]

Returns the custom event matching given id, or None if not found.

Parameters

id (str) – the unique id of the event

Returns

the custom event

Return type

Optional[CustomEvent]

get_custom_event_color(event: Optional[backend.events.CustomEvent] = None, id: Optional[str] = None) Optional[str]

Returns the color of a given custom event

Parameters
  • event (Optional[CustomEvent]) – the event to remove

  • id (Optional[str]) – the unique id of the event

Returns

the color

Return type

Optional[str]

get_events(json: bool = False, schedule_number: int = 0) List[ics.event.Event]

Extracts all the events matching ids in the filtered_subcodes list.

Parameters
  • json (bool) – whether or not the events are to be returned in a JSON format

  • schedule_number (int) – the # of the schedule, 0 for main and 1 for best one, 2 for second best, etc.

Returns

the events

Return type

List[events]

get_ics_file(schedule_number: int = 0)

Returns the .ics (iCalendar) representation of this Schedule.

Parameters

schedule_number (int) – the # of the schedule, 0 for main and 1 for best one, 2 for second best, etc.

Returns

iCalendar-formatted schedule

Return type

str

get_min_max_time_slots() Tuple[str, str]
get_option(option: str) bool
get_summary() Dict[str, Dict[str, Set[str]]]

Returns the summary of all activities within the schedule.

Returns

dict of course summaries

Return type

Dict[str, Dict[str, Set[str]]]

is_empty()
remove_course(code: str)

Removes a course from the schedule.

Parameters

code (str) – the code of the course to remove

remove_custom_event(event: Optional[backend.events.CustomEvent] = None, id: Optional[str] = None)

Removes a custom event from the schedule. If this event is present multiple times in the schedule, only delete the first occurrence.

Parameters
  • event (Optional[CustomEvent]) – the event to remove

  • id (Optional[str]) – the unique id of the event

remove_filter(code: str, filter: Union[Iterable[str], str])
reset_best_schedules()
reset_color_palette()
reset_filters(code)
set_custom_event_attributes(id: str, **kwargs: str)

Changes the custom event’s attributes.

Parameters
  • id (str) – the unique id of the event

  • kwargs (str) – the attributes and their value

set_option(option: str, value: bool)
schedules.default_dict_any_to_set() collections.defaultdict

Create a collections.defaultdict object mapping each key to a set.

Returns

the dictionary

Return type

collections.defaultdict

schedules.default_options() collections.defaultdict

Create a collections.defaultdict object mapping each key to a boolean. Default value is false.

Returns

the dictionary

Return type

collections.defaultdict

schedules.evaluate_week(week: Iterable[Iterable[backend.events.CustomEvent]], fts: Optional[Iterable[backend.events.CustomEvent]] = None) float

Evaluates how much a given week contains conflicts.

Parameters
  • week (Iterable[Iterable[evt.CustomEvent]]) – events in a week as provided by Schedule.compute_best()

  • fts (Iterable[evt.CustomEvent]) – additional events to take into account

Returns

the sum of all the conflicts

Return type

float