def compute_trajectory_smoothness(trajectory):
    """
    Returns the total and per step change in the orientation (in degrees)
    of the agent during the duration of the trajectory
        input : trajectory (a list of states)

        output : total change in orientation,
                 avg change in orientation
    """

    change_in_orientation = 0.0
    prev_orientation = None
    for state in trajectory:

        if prev_orientation is None:
            prev_orientation = state["agent_head_dir"]

        change_in_orientation += abs(
            prev_orientation - state["agent_head_dir"]
        )
        prev_orientation = state["agent_head_dir"]

    return change_in_orientation, change_in_orientation / len(trajectory)