Trait trane::graph::UnitGraph

source ·
pub trait UnitGraph {
Show 16 methods // Required methods fn add_course(&mut self, course_id: &Ustr) -> Result<()>; fn add_lesson(&mut self, lesson_id: &Ustr, course_id: &Ustr) -> Result<()>; fn add_exercise( &mut self, exercise_id: &Ustr, lesson_id: &Ustr ) -> Result<()>; fn add_dependencies( &mut self, unit_id: &Ustr, unit_type: UnitType, dependencies: &[Ustr] ) -> Result<()>; fn get_unit_type(&self, unit_id: &Ustr) -> Option<UnitType>; fn get_course_lessons(&self, course_id: &Ustr) -> Option<UstrSet>; fn update_starting_lessons(&mut self); fn get_starting_lessons(&self, course_id: &Ustr) -> Option<UstrSet>; fn get_lesson_course(&self, lesson_id: &Ustr) -> Option<Ustr>; fn get_lesson_exercises(&self, lesson_id: &Ustr) -> Option<UstrSet>; fn get_exercise_lesson(&self, exercise_id: &Ustr) -> Option<Ustr>; fn get_dependencies(&self, unit_id: &Ustr) -> Option<UstrSet>; fn get_dependents(&self, unit_id: &Ustr) -> Option<UstrSet>; fn get_dependency_sinks(&self) -> UstrSet; fn check_cycles(&self) -> Result<()>; fn generate_dot_graph(&self) -> String;
}
Expand description

Stores the units and their dependency relationships (for lessons and courses only, since exercises do not define any dependencies). It provides basic functions to update the graph and retrieve information about it for use during scheduling and student’s requests.

The write operations are only used when reading the Trane library during startup. A user that copies new courses to an existing and currently opened library will need to restart the interface for Trane. That limitation might change in the future, but it’s not a high priority as the process takes only a couple of seconds.

Required Methods§

source

fn add_course(&mut self, course_id: &Ustr) -> Result<()>

Adds a new course to the unit graph.

source

fn add_lesson(&mut self, lesson_id: &Ustr, course_id: &Ustr) -> Result<()>

Adds a new lesson to the unit graph. It also takes the ID of the course to which this lesson belongs.

source

fn add_exercise(&mut self, exercise_id: &Ustr, lesson_id: &Ustr) -> Result<()>

Adds a new exercise to the unit graph. It also takes the ID of the lesson to which this exercise belongs.

source

fn add_dependencies( &mut self, unit_id: &Ustr, unit_type: UnitType, dependencies: &[Ustr] ) -> Result<()>

Takes a unit and its dependencies and updates the graph accordingly. Returns an error if unit_type is UnitType::Exercise as only courses and lessons are allowed to have dependencies. An error is also returned if the unit was not previously added by calling one of add_course or add_lesson.

source

fn get_unit_type(&self, unit_id: &Ustr) -> Option<UnitType>

Returns the type of the given unit.

source

fn get_course_lessons(&self, course_id: &Ustr) -> Option<UstrSet>

Returns the lessons belonging to the given course.

source

fn update_starting_lessons(&mut self)

Updates the starting lessons for all courses. The starting lessons of the course are those of its lessons that should be practiced first when the course is introduced to the student. The scheduler uses them to traverse through the other lessons in the course in the correct order. This function should be called once after all the courses and lessons have been added to the graph.

source

fn get_starting_lessons(&self, course_id: &Ustr) -> Option<UstrSet>

Returns the starting lessons for the given course.

source

fn get_lesson_course(&self, lesson_id: &Ustr) -> Option<Ustr>

Returns the course to which the given lesson belongs.

source

fn get_lesson_exercises(&self, lesson_id: &Ustr) -> Option<UstrSet>

Returns the exercises belonging to the given lesson.

source

fn get_exercise_lesson(&self, exercise_id: &Ustr) -> Option<Ustr>

Returns the lesson to which the given exercise belongs.

source

fn get_dependencies(&self, unit_id: &Ustr) -> Option<UstrSet>

Returns the dependencies of the given unit.

source

fn get_dependents(&self, unit_id: &Ustr) -> Option<UstrSet>

Returns all the units which depend on the given unit.

source

fn get_dependency_sinks(&self) -> UstrSet

Returns the dependency sinks of the graph. A dependency sink is a unit with no dependencies from which a walk of the entire unit graph needs to start. Because the lessons in a course implicitly depend on their course, properly initialized lessons do not belong to this set.

This set also includes the units that are mentioned as dependencies of other units but are never added to the graph because they are missing from the course library. Those units are added as dependency sinks so that the scheduler can reach their dependents, which are part of the library.

source

fn check_cycles(&self) -> Result<()>

Performs a cycle check on the graph, done currently when opening the Trane library to prevent any infinite traversal of the graph and immediately inform the user of the issue.

source

fn generate_dot_graph(&self) -> String

Generates a DOT graph of the dependent graph. DOT files are used by Graphviz to visualize a graph, in this case the dependent graph. This operation was suggested in issue #13 in the trane-cli repo.

This allows users to have some way to visualize the graph without having to implement such a feature and depend on Graphviz instead.

The dependent graph is outputted instead of the dependency graph so that the output is easier to read. If you follow the arrows, then you are traversing the path that students must take to master a skill.

Implementors§