{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Creating and grading assignments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This guide walks an instructor through the workflow for generating an assignment and preparing it for release to students."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. contents:: Table of Contents\n",
    "   :depth: 2"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. versionadded:: 0.5.0\n",
    "\n",
    "    Much of the core functionality of nbgrader can now be accessed through the \"formgrader\" extension."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Accessing the formgrader extension"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`installation`\n",
    "        Instructions on how to install the formgrader extension."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The formgrader extension provides the core access to nbgrader's instructor tools. After the extension has been installed, you can access it through the tab in the notebook list:\n",
    "\n",
    "![](images/formgrader_tab.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Creating a new assignment"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`managing_the_database`\n",
    "        Instructions on how to manage assignments in the database from the command line\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-db-assignment-add`\n",
    "        Command line options for ``nbgrader db assignment add``"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the formgrader"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To create a new assignment, open the formgrader extension and click the \"Add new assignment...\" button at the bottom of the page. This will ask you to provide some information such as the name of the assignment and its due date. Then, you can add files to the assignment and edit them by clicking the name of the assignment:\n",
    "\n",
    "![](images/manage_assignments1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the command line"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "If you are not using the formgrader extension, you can add a new assignment simply by creating a folder in your course directory with the name of the assignment. You can specify the assignment metadata (such as the duedate) using the `nbgrader db assignment` command (see :doc:`managing_the_database`)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To simplify this example, two notebooks of the assignment have already been stored in the `source/ps1` folder:\n",
    "\n",
    "* [source/ps1/problem1.ipynb](source/ps1/problem1.ipynb)\n",
    "* [source/ps1/problem2.ipynb](source/ps1/problem2.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Developing assignments with the assignment toolbar"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Note**: As you are developing your assignments, you should save them\n",
    "into the `source/{assignment_id}/` folder of the nbgrader hierarchy,\n",
    "where `assignment_id` is the name of the assignment you are creating\n",
    "(e.g. \"ps1\")."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`philosophy`\n",
    "        More details on how the nbgrader hierarchy is structured.\n",
    "        \n",
    "    :doc:`/configuration/student_version`\n",
    "        Instructions for customizing how the student version of the assignment looks.\n",
    "\n",
    "Before you can begin developing assignments, you will need to actually\n",
    "install the nbgrader toolbar. If you do not have it installed, please\n",
    "first follow the :doc:`installation instructions <installation>`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once the toolbar has been installed, you should see it in the drop down \"View -> Cell Toolbar\" menu:\n",
    "\n",
    "![](images/assignment_toolbar.png)\n",
    "\n",
    "Selecting the \"Create Assignment\" toolbar will create a separate toolbar\n",
    "for each cell which by default will be a dropdown menu with the \"-\" item\n",
    "selected. For markdown cells, there are two additional options to choose\n",
    "from, either \"Manually graded answer\" or \"Read-only\":\n",
    "\n",
    "![](images/markdown_cell.png)\n",
    "\n",
    "For code cells, there are four options to choose from, including\n",
    "\"Manually graded answer\", \"Autograded answer\", \"Autograder tests\", and\n",
    "\"Read-only\":\n",
    "\n",
    "![](images/code_cell.png)\n",
    "\n",
    "The following sections go into detail about the different cell types,\n",
    "and show cells that are taken from a complete example of an assignment\n",
    "generated with the nbgrader toolbar extension:\n",
    "\n",
    "-   [source/ps1/problem1.ipynb](source/ps1/problem1.html)\n",
    "-   [source/ps1/problem2.ipynb](source/ps1/problem2.html)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _manually-graded-cells:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### \"Manually graded answer\" cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you select the \"Manually graded answer\" option (available for both\n",
    "markdown and code cells), the nbgrader extension will mark that cell as\n",
    "a cell that contains an answer that must be manually graded by a human\n",
    "grader. Here is an example of a manually graded answer cell:\n",
    "\n",
    "![](images/manually_graded_answer.png)\n",
    "\n",
    "The most common use case for this type of cell is for written\n",
    "free-response answers (for example, which interpret the results of code\n",
    "that may have been written and/or executed above)."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "When you specify a manually graded answer, you must additionally tell nbgrader how many points the answer is worth, and an id for the cell. Additionally, when creating the release version of the assignment (see :ref:`assign-and-release-an-assignment`), the bodies of answer cells will be replaced with a code or text stub indicating to the students that they should put their answer or solution there. Please see :doc:`/configuration/student_version` for details on how to customize this behavior."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Note: the blue border only shows up when the nbgrader extension toolbar\n",
    "is active; it will not be visible to students.*"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _manually-graded-task-cells:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### “Manually graded task” cells"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. versionadded:: 0.6.0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you select the “Manually graded task” option (available for markdown cells), \n",
    "the nbgrader extension will mark that cell as\n",
    "a cell that contains the description of a task that students have to perform.\n",
    "They must be manually graded by a human\n",
    "grader. Here is an example of a manually graded answer cell:\n",
    "\n",
    "![](images/task-cell-source.png)\n",
    "\n",
    "The difference with a manually graded answer is that the manually graded tasks cells are not edited by the student. A manually or automatically graded cell ask students to perform a task *in* one cell. A manually graded task asks students to perform a task *with* cells.\n",
    "\n",
    "The common use case for this type of cell is for tasks that require the\n",
    "student to create several cells such as \"Process the data and create a plot to illustrate your results.\" \n",
    "or to contain notebook-wide tasks such as \"adhere to the PEP8 style convention.\"\n",
    "\n",
    "*Note: the blue border only shows up when the nbgrader extension toolbar\n",
    "is active; it will not be visible to students.*"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _manually-graded-task-cell-mark-scheme:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### “Manually graded task” cells with mark scheme"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. versionadded:: 0.6.0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A mark scheme can be created through the use of a\n",
    "special syntax such as ``=== BEGIN MARK SCHEME ===`` and\n",
    "``=== END MARK SCHEME ===``. The section of text between the two markers will be removed from the student version,\n",
    "but will be visible at the grading stage and in the feedback."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _autograded-answer-cells:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### \"Autograded answer\" cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you select the \"Autograded answer\" option (available only for code\n",
    "cells), the nbgrader extension will mark that cell as a cell that\n",
    "contains an answer which will be autograded. Here is an example of an\n",
    "autograded graded answer cell:\n",
    "\n",
    "![](images/autograded_answer.png)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "As shown in the image above, solutions can be specified inline, through the use of a special syntax such as ``### BEGIN SOLUTION`` and ``### END SOLUTION``. When creating the release version (see :ref:`assign-and-release-an-assignment`), the region between the special syntax lines will be replaced with a code stub. If this special syntax is not used, then the entire contents of the cell will be replaced with the code stub. Please see :doc:`/configuration/student_version` for details on how to customize this behavior."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unlike manually graded answers, autograded answers aren't worth any\n",
    "points: instead, the points for autograded answers are specified for the\n",
    "particular tests that grade those answers. See the next section for\n",
    "further details.\n",
    "\n",
    "*Note: the blue border only shows up when the nbgrader extension toolbar\n",
    "is active; it will not be visible to students.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### \"Autograder tests\" cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you select the \"Autograder tests\" option (available only for code\n",
    "cells), the nbgrader extension will mark that cell as a cell that\n",
    "contains tests to be run during autograding. Here is an example of two\n",
    "test cells:\n",
    "\n",
    "![](images/autograder_tests.png)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Test cells should contain ``assert`` statements (or similar). When run through ``nbgrader autograde`` (see :ref:`autograde-assignments`), the cell will pass if no errors are raised, and fail otherwise. You must specify the number of points that each test cell is worth; then, if the tests pass during autograding, students will receive the specified number of points, and otherwise will receive zero points."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The lock icon on the left side of the cell toolbar indicates that the\n",
    "tests are \"read-only\". See the next section for further details on what\n",
    "this means."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "For tips on writing autograder tests, see :ref:`autograding-resources`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Note: the blue border only shows up when the nbgrader extension toolbar\n",
    "is active; it will not be visible to students.*"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _autograder-tests-cell-hidden-tests:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### \"Autograder tests\" cells with hidden tests"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. versionadded:: 0.5.0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tests in \"Autograder tests\" cells can be hidden through the use of a special syntax such as ``### BEGIN HIDDEN TESTS`` and ``### END HIDDEN TESTS``, for example:\n",
    "\n",
    "![](images/autograder_tests_hidden_tests.png)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "When creating the release version (see :ref:`assign-and-release-an-assignment`), the region between the special syntax lines will be removed. If this special syntax is not used, then the contents of the cell will remain as is. Please see :doc:`/configuration/student_version` for details on how to customize this behavior.\n",
    "\n",
    ".. note::\n",
    "\n",
    "    Keep in mind that wrapping all tests (for an \"Autograder tests\" cell) in this special syntax will remove all these tests in\n",
    "    the release version and the students will only see a blank cell. It is recommended to have at least one or more visible \n",
    "    tests, or a comment in the cell for the students to see.\n",
    "\n",
    "    These hidden tests are placed back into the \"Autograder tests\" cells when running ``nbgrader autograde``\n",
    "    (see :ref:`autograde-assignments`)."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _read-only-cells:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### \"Read-only\" cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you select the \"Read-only\" option (available for both code and\n",
    "markdown cells), the nbgrader extension will mark that cell as one that\n",
    "cannot be modified. This is indicated by a lock icon on the left side of\n",
    "the cell toolbar:\n",
    "\n",
    "![](images/read_only.png)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "However, this doesn't actually mean that it is truly read-only when opened in the notebook. Instead, what it means is that during the ``nbgrader generate_assignment`` step (see :ref:`assign-and-release-an-assignment`), the source of these cells will be recorded into the database. Then, during the ``nbgrader autograde`` step (see :ref:`autograde-assignments`), nbgrader will check whether the source of the student's version of the cell has changed. If it has, it will replace the cell's source with the version in the database, thus effectively overwriting any changes the student made.\n",
    "\n",
    ".. versionadded:: 0.4.0\n",
    "    Read-only cells (and test cells) are now truly read-only! However, at the moment this functionality will only work on the master version of the notebook (5.0.0.dev)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This functionality is particularly important for test cells, which are\n",
    "always marked as read-only. Because the mechanism for autograding is\n",
    "that students receive full credit if the tests pass, an easy way to get\n",
    "around this would be to simply delete or comment out the tests. This\n",
    "read-only functionality will reverse any such changes made by the\n",
    "student."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Validating the instructor version"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-validate`\n",
    "        Command line options for ``nbgrader validate``"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the validate extension"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Ideally, the solutions in the instructor version should be correct and pass all the test cases to ensure that you are giving your students tests that they can actually pass. To verify this is the case, you can use the validate extension:\n",
    "\n",
    "![](images/validate_extension.png)\n",
    "\n",
    "If your assignment passes all the tests, you'll get a success pop-up:\n",
    "\n",
    "![](images/validate_success.png)\n",
    "\n",
    "If it doesn't pass all the tests, you'll get a message telling you which cells failed:\n",
    "\n",
    "![](images/validate_failed.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the command line"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also validate assignments on the command line using the `nbgrader validate` command:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success! Your notebook passes all the tests.\n",
      "Success! Your notebook passes all the tests.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[ValidateApp | WARNING] No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)\n",
      "[ValidateApp | INFO] Validating '[NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/ps1/problem1.ipynb'\n",
      "[ValidateApp | INFO] Executing notebook with kernel: python\n",
      "[ValidateApp | INFO] Validating '[NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/ps1/problem2.ipynb'\n",
      "[ValidateApp | INFO] Executing notebook with kernel: python\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "nbgrader validate source/ps1/*.ipynb"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _assign-and-release-an-assignment:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Generate and release an assignment"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-generate-assignment`\n",
    "        Command line options for ``nbgrader generate_assignment``\n",
    "        \n",
    "    :doc:`philosophy`\n",
    "        Details about how the directory hierarchy is structured\n",
    "\n",
    "    :doc:`/configuration/config_options`\n",
    "        Details on ``nbgrader_config.py``"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the formgrader"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After an assignment has been created with the assignment toolbar, you will want to generate the version that students will receive. You can do this from the formgrader by clicking the \"generate\" button:\n",
    "\n",
    "![](images/manage_assignments2.png)\n",
    "\n",
    "This should succeed with a pop-up window containing log output:\n",
    "\n",
    "![](images/generate_assignment.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the command line"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "As described in :doc:`philosophy`, you need to organize your files in a particular way. For releasing assignments, you should have the master copy of your files saved (by default) in the following source directory structure:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "{course_directory}/source/{assignment_id}/{notebook_id}.ipynb\n",
    "```\n",
    "\n",
    "Note: The `student_id` is not included here because the source and release versions of the assignment are the same for all students.\n",
    "\n",
    "After running `nbgrader generate_assignment`, the release version of the notebooks will be:\n",
    "\n",
    "```\n",
    "{course_directory}/release/{assignment_id}/{notebook_id}.ipynb\n",
    "```\n",
    "\n",
    "As a reminder, the instructor is responsible for distributing this release version to their students using their institution's existing student communication and document distribution infrastructure."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When running `nbgrader generate_assignment`, the assignment name (which is \"ps1\") is passed. We also specify a *header* notebook (`source/header.ipynb`) to prepend at the beginning of each notebook in the assignment. By default, this command should be run from the root of the course directory:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[GenerateAssignmentApp | WARNING] No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)\n",
      "[GenerateAssignmentApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/./ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/release/./ps1/jupyter.png\n",
      "[GenerateAssignmentApp | INFO] Updating/creating assignment 'ps1': {}\n",
      "[GenerateAssignmentApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/./ps1/problem1.ipynb\n",
      "[GenerateAssignmentApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/release/./ps1/problem1.ipynb\n",
      "[GenerateAssignmentApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/./ps1/problem2.ipynb\n",
      "[GenerateAssignmentApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/release/./ps1/problem2.ipynb\n",
      "[GenerateAssignmentApp | INFO] Setting destination file permissions to 644\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "nbgrader generate_assignment \"ps1\" --IncludeHeaderFooter.header=source/header.ipynb --force"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Preview the student version"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After generating the student version of assignment, you should preview it to make sure that it looks correct. You can do this from the formgrader extension by clicking the \"preview\" button:\n",
    "\n",
    "![](images/manage_assignments3.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Under the hood, there will be a new folder called `release` with the same structure as `source`. The `release` folder contains the actual release version of the assignment files:\n",
    "\n",
    "* [release/ps1/problem1.ipynb](release/ps1/problem1.ipynb)\n",
    "* [release/ps1/problem2.ipynb](release/ps1/problem2.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you are working on the command line, you may want to formally verify the student version as well. Ideally, all the tests should fail in the student version if the student hasn't implemented anything. To verify that this is in fact the case, we can use the `nbgrader validate --invert` command:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success! The notebook does not pass any tests.\n",
      "Success! The notebook does not pass any tests.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[ValidateApp | WARNING] No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)\n",
      "[ValidateApp | INFO] Validating '[NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/release/ps1/problem1.ipynb'\n",
      "[ValidateApp | INFO] Executing notebook with kernel: python\n",
      "[ValidateApp | INFO] Validating '[NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/release/ps1/problem2.ipynb'\n",
      "[ValidateApp | INFO] Executing notebook with kernel: python\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "nbgrader validate --invert release/ps1/*.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the notebook fails all the test cases, you should see the message \"Success! The notebook does not pass any tests.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Releasing files to students and collecting submissions"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`managing_assignment_files`\n",
    "        Guide to releasing and collecting submissions.\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-release-assignment`\n",
    "        Command line options for ``nbgrader release_assignment``\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-collect`\n",
    "        Command line options for ``nbgrader collect``\n",
    "        \n",
    "    :doc:`philosophy`\n",
    "        Details about how the directory hierarchy is structured\n",
    "\n",
    "    :doc:`/configuration/config_options`\n",
    "        Details on ``nbgrader_config.py``"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "Note: the :doc:`Managing Assignment Files Guide <managing_assignment_files>` goes into greater depth on how to release and collect assignments, and the various options that are available to do you for doing so."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "At this point you will be able to take the files in the ``release`` folder and distribute them to students. If you are using nbgrader with JupyterHub, you can do this with either with the formgrader extension or with the ``nbgrader release_assignment`` command (see :doc:`managing_assignment_files`). Otherwise, you will need to do this manually.\n",
    "\n",
    "Similarly, to collect submissions, you can do this either with the formgrader extension or with the ``nbgrader collect`` command. Otherwise, you will need to manually place submitted files into the ``submitted`` directory. As described in :doc:`philosophy`, you need to organize your files in a particular way. For submitted assignments, you should have the submitted versions of students' assignments organized as follows:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "submitted/{student_id}/{assignment_id}/{notebook_id}.ipynb\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Please note**: Students must use version 3 or greater of the IPython/Jupyter notebook for nbgrader to work properly. If they are not using version 3 or greater, it is possible for them to delete cells that contain important metadata for nbgrader. With version 3 or greater, there is a feature in the notebook that prevents cells from being deleted. See [this issue](https://github.com/jupyter/nbgrader/issues/424) for more details.\n",
    "\n",
    "To ensure that students have a recent enough version of the notebook, you can include a cell such as the following in each notebook of the assignment:\n",
    "\n",
    "```python\n",
    "import IPython\n",
    "assert IPython.version_info[0] >= 3, \"Your version of IPython is too old, please update it.\"\n",
    "```"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. _autograde-assignments:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Autograde assignments"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-autograde`\n",
    "        Command line options for ``nbgrader autograde``\n",
    "        \n",
    "    :doc:`philosophy`\n",
    "        Details about how the directory hierarchy is structured\n",
    "\n",
    "    :doc:`/configuration/config_options`\n",
    "        Details on ``nbgrader_config.py``"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the following example, we have an assignment with two notebooks. There are two submissions of the assignment:\n",
    "\n",
    "Submission 1:\n",
    "\n",
    "* [submitted/bitdiddle/ps1/problem1.ipynb](submitted/bitdiddle/ps1/problem1.ipynb)\n",
    "* [submitted/bitdiddle/ps1/problem2.ipynb](submitted/bitdiddle/ps1/problem2.ipynb)\n",
    "\n",
    "Submission 2:\n",
    "\n",
    "* [submitted/hacker/ps1/problem1.ipynb](submitted/hacker/ps1/problem1.ipynb)\n",
    "* [submitted/hacker/ps1/problem2.ipynb](submitted/hacker/ps1/problem2.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the formgrader"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can autograde individual submissions from the formgrader directly. To do so, click on the the number of submissions in the \"Manage Assignments\" view:\n",
    "\n",
    "![](images/manage_assignments4.png)\n",
    "\n",
    "This will take you to a new page where you can see all the submissions. For a particular submission, click the \"autograde\" button to autograde it:\n",
    "\n",
    "![](images/manage_submissions1.png)\n",
    "\n",
    "After autograding completes, you will see a pop-up window with log output:\n",
    "\n",
    "![](images/autograde_assignment.png)\n",
    "\n",
    "And back on the submissions screen, you will see that the status of the submission has changed to \"needs manual grading\" and there is now a reported score as well: \n",
    "\n",
    "![](images/manage_submissions2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From the command line"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can run the autograder for all students at once from the command line:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[AutogradeApp | WARNING] No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)\n",
      "[AutogradeApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/bitdiddle/ps1/timestamp.txt -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/timestamp.txt\n",
      "[AutogradeApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/bitdiddle/ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/jupyter.png\n",
      "[AutogradeApp | INFO] Creating/updating student with ID 'bitdiddle': {}\n",
      "[AutogradeApp | INFO] SubmittedAssignment<ps1 for bitdiddle> submitted at [timestamp]\n",
      "[AutogradeApp | INFO] Overwriting files with master versions from the source directory\n",
      "[AutogradeApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/./ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/jupyter.png\n",
      "[AutogradeApp | INFO] Sanitizing [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/bitdiddle/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/bitdiddle/ps1/problem1.ipynb\n",
      "[AutogradeApp | WARNING] Attribute 'checksum' for cell correct_squares has changed! (should be: 8f41dd0f9c8fd2da8e8708d73e506b3a, got: 845d4666cabb30b6c75fc534f7375bf5)\n",
      "[AutogradeApp | WARNING] Attribute 'checksum' for cell squares_invalid_input has changed! (should be: 23c2b667d3b60eff3be46eb3290a6b4a, got: 123394e73f33a622ec057e2eae51a54a)\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Autograding [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Executing notebook with kernel: python\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Sanitizing [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/bitdiddle/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/bitdiddle/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Autograding [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Executing notebook with kernel: python\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Setting destination file permissions to 444\n",
      "[AutogradeApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/hacker/ps1/timestamp.txt -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/timestamp.txt\n",
      "[AutogradeApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/hacker/ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/jupyter.png\n",
      "[AutogradeApp | INFO] Creating/updating student with ID 'hacker': {}\n",
      "[AutogradeApp | INFO] SubmittedAssignment<ps1 for hacker> submitted at [timestamp]\n",
      "[AutogradeApp | INFO] Overwriting files with master versions from the source directory\n",
      "[AutogradeApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/source/./ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/jupyter.png\n",
      "[AutogradeApp | INFO] Sanitizing [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/hacker/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/hacker/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Autograding [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Executing notebook with kernel: python\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem1.ipynb\n",
      "[AutogradeApp | INFO] Sanitizing [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/hacker/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/submitted/hacker/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Autograding [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Executing notebook with kernel: python\n",
      "[AutogradeApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem2.ipynb\n",
      "[AutogradeApp | INFO] Setting destination file permissions to 444\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "nbgrader autograde \"ps1\" --force"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When grading the submission for `Bitdiddle`, you'll see some warnings that look like \"Checksum for grade cell correct_squares has changed!\". What's happening here is that nbgrader has recorded what the *original* contents of the grade cell `correct_squares` (when `nbgrader generate_assignment` was run), and is checking the submitted version against this original version. It has found that the submitted version changed (perhaps this student tried to cheat by commenting out the failing tests), and has therefore overwritten the submitted version of the tests with the original version of the tests.\n",
    "\n",
    "You may also notice that there is a note saying \"ps1 for Bitdiddle is 21503.948203 seconds late\". What is happening here is that nbgrader is detecting a file in Bitdiddle's submission called `timestamp.txt`, reading in that timestamp, and saving it into the database. From there, it can compare the timestamp to the duedate of the problem set, and compute whether the submission is at all late.\n",
    "\n",
    "Once the autograding is complete, there will be new directories for the autograded versions of the submissions:\n",
    "\n",
    "```\n",
    "autograded/{student_id}/{assignment_id}/{notebook_id}.ipynb\n",
    "```\n",
    "\n",
    "Autograded submission 1:\n",
    "\n",
    "* [autograded/bitdiddle/ps1/problem1.ipynb](autograded/bitdiddle/ps1/problem1.ipynb)\n",
    "* [autograded/bitdiddle/ps1/problem2.ipynb](autograded/bitdiddle/ps1/problem2.ipynb)\n",
    "\n",
    "Autograded submission 2:\n",
    "\n",
    "* [autograded/hacker/ps1/problem1.ipynb](autograded/hacker/ps1/problem1.ipynb)\n",
    "* [autograded/hacker/ps1/problem2.ipynb](autograded/hacker/ps1/problem2.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Manual grading"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`philosophy`\n",
    "        More details on how the nbgrader hierarchy is structured.\n",
    "\n",
    "    :doc:`/configuration/config_options`\n",
    "        Details on ``nbgrader_config.py``"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "After assignments have been autograded, they will saved into an ``autograded`` directory (see :doc:`philosophy` for details):"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After running `nbgrader autograde`, the autograded version of the\n",
    "notebooks will be:\n",
    "\n",
    "    autograded/{student_id}/{assignment_id}/{notebook_id}.ipynb\n",
    "\n",
    "We can manually grade assignments through the formgrader as well, by clicking on the \"Manual Grading\" navigation button. This will provide you with an interface for hand grading assignments that it finds in the directory listed above. Note that this applies to *all* assignments as well -- as long as the autograder has been run on the assignment, it will be available for manual grading via the formgrader."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Generate feedback on assignments"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. seealso::\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-generate-feedback`\n",
    "        Command line options for ``nbgrader generate_feedback``\n",
    "        \n",
    "    :doc:`/command_line_tools/nbgrader-release-feedback`\n",
    "        Command line options for ``nbgrader release_feedback``\n",
    "        \n",
    "    :doc:`philosophy`\n",
    "        Details about how the directory hierarchy is structured\n",
    "\n",
    "    :doc:`/configuration/config_options`\n",
    "        Details on ``nbgrader_config.py``"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "As mentioned before, after assignments have been autograded and/or manually graded, they will located in the `autograded` directory (see :doc:`philosophy` for details):"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "autograded/{student_id}/{assignment_id}/{notebook_id}.ipynb\n",
    "```\n",
    "\n",
    "Creating feedback for students is divided into two parts:\n",
    "\n",
    "* generate feedback\n",
    "* release feedback\n",
    "\n",
    "Generating feedback will create HTML files in the local instructor directory. Releasing feedback will copy those HTML files to the nbgrader exchange.\n",
    "\n",
    "We can generate feedback based on the graded notebooks by running the `nbgrader generate_feedback` command, which will produce HTML versions of these notebooks at the following location:\n",
    "\n",
    "```\n",
    "feedback/{student_id}/{assignment_id}/{notebook_id}.html\n",
    "```\n",
    "\n",
    "The `nbgrader generate_feedback` is available by clicking the Generate Feedback button on either the Manage Assignments view (to generate feedback for all graded submissions), or on the individual student's Manage Submission page (to generate feedback for that specific individual)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can release the generated feedback by running the `nbgrader release_feedback` command, which will send the generated HTML files to the nbgrader exchange.\n",
    "\n",
    "The `nbgrader release_feedback` is available by clicking the Release Feedback button on either the Manage Assignments view (to release feedback for all generated feedback), or on the individual student's Manage Submission page (to release feedback for that specific individual)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Workflow example: Instructor returning feedback to students"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In some scenarios, you may not want to (or be able to) use the exchange to deliver student feedback. This sections describes a workflow for manually returning generated feedback.\n",
    "\n",
    "In the following example, we have an assignment with two notebooks. There are two submissions of the assignment that have been graded:\n",
    "\n",
    "Autograded submission 1:\n",
    "\n",
    "* [autograded/bitdiddle/ps1/problem1.ipynb](autograded/bitdiddle/ps1/problem1.ipynb)\n",
    "* [autograded/bitdiddle/ps1/problem2.ipynb](autograded/bitdiddle/ps1/problem2.ipynb)\n",
    "\n",
    "Autograded submission 2:\n",
    "\n",
    "* [autograded/hacker/ps1/problem1.ipynb](autograded/hacker/ps1/problem1.ipynb)\n",
    "* [autograded/hacker/ps1/problem2.ipynb](autograded/hacker/ps1/problem2.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Generating feedback is fairly straightforward (and as with the other nbgrader commands for instructors, this must be run from the root of the course directory):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[GenerateFeedbackApp | WARNING] No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)\n",
      "[GenerateFeedbackApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/timestamp.txt -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/bitdiddle/ps1/timestamp.txt\n",
      "[GenerateFeedbackApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/bitdiddle/ps1/jupyter.png\n",
      "[GenerateFeedbackApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.ipynb\n",
      "[GenerateFeedbackApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/bitdiddle/ps1/problem1.html\n",
      "[GenerateFeedbackApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem2.ipynb\n",
      "[GenerateFeedbackApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/bitdiddle/ps1/problem2.html\n",
      "[GenerateFeedbackApp | INFO] Setting destination file permissions to 644\n",
      "[GenerateFeedbackApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/timestamp.txt -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/hacker/ps1/timestamp.txt\n",
      "[GenerateFeedbackApp | INFO] Copying [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/jupyter.png -> [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/hacker/ps1/jupyter.png\n",
      "[GenerateFeedbackApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem1.ipynb\n",
      "[GenerateFeedbackApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/hacker/ps1/problem1.html\n",
      "[GenerateFeedbackApp | INFO] Converting notebook [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem2.ipynb\n",
      "[GenerateFeedbackApp | INFO] Writing [size] bytes to [NB_GRADER_ROOT]/nbgrader/docs/source/user_guide/feedback/hacker/ps1/problem2.html\n",
      "[GenerateFeedbackApp | INFO] Setting destination file permissions to 644\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "nbgrader generate_feedback \"ps1\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once the feedback has been generated, there will be new directories and HTML files corresponding to each notebook in each submission:\n",
    "\n",
    "Feedback for submission 1:\n",
    "\n",
    "* [feedback/bitdiddle/ps1/problem1.html](feedback/bitdiddle/ps1/problem1.html)\n",
    "* [feedback/bitdiddle/ps1/problem2.html](feedback/bitdiddle/ps1/problem2.html)\n",
    "\n",
    "Feedback for submission 2:\n",
    "\n",
    "* [feedback/hacker/ps1/problem1.html](feedback/hacker/ps1/problem1.html)\n",
    "* [feedback/hacker/ps1/problem2.html](feedback/hacker/ps1/problem2.html)\n",
    "\n",
    "If the exchange is available, one would of course use `nbgrader release_feedback`. However if not available, you can now deliver these generated HTML feedback files via whatever mechanism you wish."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting grades from the database"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    ".. versionadded:: 0.4.0\n",
    "\n",
    ".. seealso::\n",
    "\n",
    "    :doc:`/command_line_tools/nbgrader-export`\n",
    "        Command line options for ``nbgrader export``\n",
    "        \n",
    "    :doc:`/plugins/export-plugin`\n",
    "        Details on how to write your own custom exporter."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition to creating feedback for the students, you may need to upload grades to whatever learning management system your school uses (e.g. Canvas, Blackboard, etc.). nbgrader provides a way to export grades to CSV out of the box, with the `nbgrader export` command:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[ExportApp | WARNING] No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)\n",
      "[ExportApp | INFO] Using exporter: CsvExportPlugin\n",
      "[ExportApp | INFO] Exporting grades to grades.csv\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "nbgrader export"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After running `nbgrader export`, you will see the grades in a CSV file called `grades.csv`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "assignment,duedate,timestamp,student_id,last_name,first_name,email,raw_score,late_submission_penalty,score,max_score\n",
      "ps1,,[timestamp],bitdiddle,,,,1.5,0.0,1.5,13.0\n",
      "ps1,,[timestamp],hacker,,,,3.0,0.0,3.0,13.0\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "\n",
    "cat grades.csv"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "If you need to customize how the grades are exported, you can :doc:`write your own exporter </plugins/export-plugin>`."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python",
   "language": "python",
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
