{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "# ordo\n",
    "A lightweight feedback tool for Jupyter.\n",
    "\n",
    "### Installation\n",
    "Install and enable ordo on your Jupyter server\n",
    "\n",
    "```pip install ordo\n",
    "jupyter nbextension install --py ordo\n",
    "jupyter nbextension enable ordo --py```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Configuration\n",
    "You can configure ordo to have a system wide default feedback messages.  \n",
    "Just set the **ordo_default_success** or **ordo_default_failure** configuration options in your ```~/.jupyter/nbconfig/<section>.json```\n",
    "\n",
    "```json\n",
    "\"ordo_default_success\": \"You've done well to get the correct answer\",\n",
    "\"ordo_default_failure\": \"That answer is not correct, please try again\"\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 0,
        "height": 4,
        "hidden": false,
        "row": 0,
        "width": 4
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "The ordo grading tool allows authors to provide in line feedback to users of their notebook. The examples below illustrate key features of the notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Guide\n",
    "\n",
    "#### Toggle Modes\n",
    "<button class='btn fa fa-check'></button> - Enter **Feedback Mode** to run the cells and evauluate your input\n",
    "<button class='btn fa fa-pencil'></button> - Enter **Edit Mode** to create/edit your feedback messages\n",
    "#### In Feedback Mode\n",
    "<button class='btn fa fa-eye'></button> - Show solution for the current cell \n",
    "#### In Edit Mode\n",
    "<button type=\"button\" title=\"add solution\" class=\"btn btn-default fa fa-plus\"> Solution </button> - Add new solution\n",
    "<button type=\"button\" title=\"add success message\" class=\"btn btn-success fa fa-thumbs-o-up\"> Message </button> - Add success message for feedback\n",
    "<button type=\"button\" title=\"add failure message\" class=\"btn btn-danger fa fa-thumbs-down\"> Message </button> - Add failure message for feedback\n",
    "<button type=\"button\" class=\"btn btn-primary\">make solution</button> - Make what's in this cell the current solution\n",
    "<button class=\"btn fa fa-lightbulb-o\"></button> - Set the currently executed cells output to it's solution\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 4,
        "height": 4,
        "hidden": false,
        "row": 0,
        "width": 4
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "Once installed, the extension runs in any language within any Jupyter notebook. Beware, it will only grade **returned** values. `print` values in Python, for example, return `None` and are ignored."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    },
    "ordo_solution": {
     "text/plain": "9.0"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "5+4.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 8,
        "height": 4,
        "hidden": false,
        "row": 0,
        "width": 4
       },
       "report_default": {}
      }
     }
    },
    "ordo_solution": {
     "text/plain": "'Hello, World! This is an Ordo Test'"
    }
   },
   "outputs": [],
   "source": [
    "'Hello, World! This is an Ordo Test'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 0,
        "height": 4,
        "hidden": false,
        "row": 4,
        "width": 4
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "Only cells which have solution in the cell metadata are evaluated for grading."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [],
   "source": [
    "# this cell has no associated solution\n",
    "def addOne(n):\n",
    "  return n + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {
        "hidden": true
       }
      }
     }
    },
    "ordo_solution": {
     "text/plain": "7"
    }
   },
   "outputs": [],
   "source": [
    "# this cell is configured with a solution of 7\n",
    "addOne(6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 4,
        "height": 4,
        "hidden": false,
        "row": 4,
        "width": 4
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "When an answer is incorrect, student's will receive a different response."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {
        "hidden": true
       }
      }
     }
    },
    "ordo_solution": {
     "text/plain": "11"
    }
   },
   "outputs": [],
   "source": [
    "# this cell is configured with a solution of 7\n",
    "addOne(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 8,
        "height": 4,
        "hidden": false,
        "row": 4,
        "width": 4
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "Notebook authors can either use the default ordo messages above or, they can define specific ones they would like within the cell metadata with either the `ordo_success or ordo_failure` MIME types."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 0,
        "height": 4,
        "hidden": false,
        "row": 8,
        "width": 4
       },
       "report_default": {}
      }
     }
    },
    "ordo_failure": "Try that one again!",
    "ordo_solution": {
     "text/plain": "8"
    },
    "ordo_success": "Righto Chap!"
   },
   "outputs": [],
   "source": [
    "# this cell is configured with a solution of 7\n",
    "addOne(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "col": 4,
        "height": 4,
        "hidden": false,
        "row": 8,
        "width": 4
       },
       "report_default": {}
      }
     }
    },
    "ordo_failure": "Try that one again!",
    "ordo_solution": {
     "text/plain": "21"
    },
    "ordo_success": "Righto Chap!"
   },
   "outputs": [],
   "source": [
    "# this cell is configured with a solution of 7\n",
    "addOne(20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "An example of a cell with a pandas dataframe as a solution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ordo_solution": {
     "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>a</th>\n      <th>b</th>\n      <th>c</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>1</td>\n      <td>2</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
     "text/plain": "   a  b  c\n0  0  1  2"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "d = [{'b' : 1, 'a' : 0, 'c' : 2}]\n",
    "pd.DataFrame(d)"
   ]
  }
 ],
 "metadata": {
  "extensions": {
   "jupyter_dashboards": {
    "activeView": "grid_default",
    "version": 1,
    "views": {
     "grid_default": {
      "cellMargin": 10,
      "defaultCellHeight": 20,
      "maxColumns": 12,
      "name": "grid",
      "type": "grid"
     },
     "report_default": {
      "name": "report",
      "type": "report"
     }
    }
   }
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
