2016-2017/Notes/Interact.ipynb

262 lines
5.7 KiB
Plaintext
Raw Normal View History

2017-06-16 06:49:23 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use(\"seaborn-notebook\")\n",
"from ipywidgets import interact, interactive, fixed\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"from extract import extract_flat_marks, get_class_ws, list_classes\n",
"from df_marks_manip import digest_flat_df, students_pov, round_half_point"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution 1"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def print_eval(evaluation):\n",
" ws = get_class_ws(clsW.value)\n",
" flat = extract_flat_marks(ws)\n",
" _,_,eval_m = digest_flat_df(flat)\n",
" print(\"Devoir sur \",eval_m[(eval_m[\"Nom\"]==evaluation) & (eval_m[\"Mark\"] > 0)][\"Bareme\"].iloc[0])\n",
" print(eval_m[eval_m[\"Nom\"]==evaluation][\"Mark\"].describe())\n",
"def select_classe(classe):\n",
" ws = get_class_ws(classe)\n",
" evals = extract_flat_marks(ws)[\"Nom\"].unique()\n",
" evalW.options = list(evals)"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"classes = list_classes()\n",
"clsW = widgets.Select(options=classes)\n",
"cls_init = clsW.value"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ws = get_class_ws(cls_init)\n",
"evals = extract_flat_marks(ws)[\"Nom\"].unique()\n",
"evalW = widgets.Dropdown(options = list(evals))"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Devoir sur 22.0\n",
"count 30.000000\n",
"mean 10.200000\n",
"std 3.786546\n",
"min 0.000000\n",
"25% 8.625000\n",
"50% 10.750000\n",
"75% 12.375000\n",
"max 15.500000\n",
"Name: Mark, dtype: float64\n"
]
}
],
"source": [
"j = widgets.interactive(print_eval, evaluation=evalW)\n",
"i = widgets.interactive(select_classe, classe=clsW)\n",
"display(i,j)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Quand on change de classe, l'évaluation n'est pas mis à jour"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution 2"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"classes = list_classes()\n",
"clsW = widgets.Select(options=classes)\n",
"cls_init = clsW.value"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ws = get_class_ws(cls_init)\n",
"evals = extract_flat_marks(ws)[\"Nom\"].unique()\n",
"evalW = widgets.Select(options = list(evals))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def update_evals(*args):\n",
" classe = clsW.value\n",
" ws = get_class_ws(classe)\n",
" evals = extract_flat_marks(ws)[\"Nom\"].unique()\n",
" evalW.options = list(evals)\n",
" \n",
"clsW.observe(update_evals, \"value\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def resume(classe, evaluation):\n",
" ws = get_class_ws(classe)\n",
" flat = extract_flat_marks(ws)\n",
" _,_,eval_m = digest_flat_df(flat)\n",
" print(\"Devoir sur \",eval_m[(eval_m[\"Nom\"]==evaluation) & (eval_m[\"Mark\"] > 0)][\"Bareme\"].iloc[0])\n",
" print(eval_m[eval_m[\"Nom\"]==evaluation][\"Mark\"].describe())\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Devoir sur 22.0\n",
"count 29.000000\n",
"mean 7.879310\n",
"std 4.787736\n",
"min 0.000000\n",
"25% 5.500000\n",
"50% 8.500000\n",
"75% 11.500000\n",
"max 15.500000\n",
"Name: Mark, dtype: float64\n"
]
},
{
"data": {
"text/plain": [
"<function __main__.resume>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"widgets.interact(resume, classe=clsW, evaluation=evalW)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"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.5.2"
},
"widgets": {
"state": {
"849ab02f915e4783b04221c9ed128d96": {
"views": [
{
"cell_index": 13
}
]
}
},
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}