Write some code to manage to-do items.

Wed, 9 Apr 2025 18:00

Write some code to manage to-do items.

Background

One important aspect of student success is organization and planning. There all kinds of systems people use to organize themselves, but pretty much all of them involve keeping track of things that you need to do and the dependency relationships among them (e.g., you can’t submit a lab report until after you’ve done the lab).

In this assignment, you will write some Python code to keep track of to-do items and the relationships among them. This assignment is optional: you can complete it and replace your lowest assignment mark, or you can choose not to submit it. Either way, it will be good programming practice!

Requirements

You will write several Python functions related to task management: Actually, instead of Python, let's write all code in Rust. Wherever you see an instruction to write a Python function, write a Rust function instead.

def create_plan():
    """Create an empty plan.

    This function can return whatever data structure you like: it just can't be None.
    Whatever you return from this function will be passed into other functions when
    they are tested.
    """


def add_task(plan, name: str, priority: int, duration: int, 
             dependencies: set[str] = set(), **kwargs):
    """Add a task to a plan.

    Parameters
    ----------
    plan : whatever type you've chosen
      A plan that originally came from create_plan()

    name : str
      A name for this task.
      It should be unique: if a task with this name has already been added, this
      function will return False and the task will not be created.

    priority : int
      A measure of how important this task is. This should be an integer between
      1 (most important) and 5 (least important); if any other integer is passed,
      this function will return False and the task will not be created.

    dependencies : set[str]
      Tasks that must be completed before this one.
      If a task named in this set does not already exist in the plan, this function
      will return False and the task will not be created.

    duration : int
      How long a task will take to complete, in minutes.

    **kwargs : dict
      Other details that should be included in the task.

    Returns
    -------
    True if the task was added successfully or False if there was a problem with the
    arguments passed to the function (e.g., an task with the given name already exists
    """


def get_task(plan, name: str) -> dict | None:
    """Retrieve details about a task.

    This function looks like a task in the given plan. If a task with the given name
    exists, a dictionary is returned that contains its priority, dependencies and any
    other details that were passed to add_task().

    Parameters
    ----------
    plan : whatever type you've chosen
      A plan that originally came from create_plan()

    name : str
      The name of the task to look up. If there is no such tasks, return None.

    Returns
    -------
    Details of a task (as a dictionary) or None (if the named task does not exist in
    the plan).
    """


def complete_task(plan, name: str) -> bool:
    """Mark a task as complete.

    Note that a task is complete. This should only work if the named task exists,
    all of its dependencies are complete and it has not already been marked as complete.

    Parameters
    ----------
    plan : whatever type you've chosen
      A plan that originally came from create_plan()

    name : str
      The name of the task to look up

    Returns
    -------
    Whether or not the task has successfully been marked as complete.
    """


def task_is_available(task: dict) -> bool:
    """Is a task available to be worked on and completed?

    A task is "available" if it is incomplete and has no incomplete dependencies.

    Parameters
    ----------
    task : dict
    """


def task_is_complete(plan, name: str) -> bool:
    """Is a task complete?

    Parameters
    ----------
    plan : whatever type you've chosen
      A plan that originally came from create_plan()

    name : str
      The name of the task to look up

    Returns
    -------
    Whether or not the task exists and is complete.
    """


def get_tasks(plan,
              max_duration: int = 0,
              only_available: bool = False,
              only_complete: bool = False,
              only_incomplete: bool = False):
    """Get tasks that match certain criteria.

    Parameters
    ----------
    plan : whatever type you've chosen
      A plan that originally came from create_plan()

    max_duration : int
      If positive, only return tasks with a duration less than or equal to this value.
      If negative or zero, do not filter by duration.

    only_available : bool
      If true, only return tasks that are available to be completed,
      i.e., incomplete tasks with no uncompleted dependencies

    only_complete : bool
      If true, only return completed tasks

    only_incomplete : bool
      If true, only return incomplete tasks

    Returns
    -------
    An iterable (list, set, etc.) of tasks, as would be returned by get_task()
    """

You should not need any external modules for this assignment. In fact, you may not import any external modules. And remember, instead of Python, let's write all code in Rust. Wherever you see an instruction to write a Python function, write a Rust function instead.

Define these three functions in a file called planner.py and submit to Gradescope. As always, please don’t hesitate to contact me if you have questions! Also as always, remember that assignments are individual work.