2016-2017/Notes/Bilan trimestriel.ipynb

189 lines
4.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"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",
"\n",
"from ipywidgets import interact, interactive, fixed\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"import notes_tools.tools as tools\n",
"from notes_tools.generate_bilan import texenv\n",
"from notes_tools.tools.df_marks_manip import round_half_point"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"classe = \"509\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ws = tools.get_class_ws(classe)\n",
"flat = tools.extract_flat_marks(ws)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"quest_pov, exo_pov, eval_pov = tools.digest_flat_df(flat)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Création des bilans trimestriels"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def create_summary_table(pv_table, coefs = \"\"):\n",
" if coefs:\n",
" cols = [(\"Evaluations\",[\"Note\", \"Note sur 20\", \"Coefficient\"])]\n",
" else:\n",
" cols = [(\"Evaluations\",[\"Note\", \"Note sur 20\"])]\n",
" for k,v in pv_table.iterrows():\n",
" if coefs:\n",
" cols.append((k[1], [\"{}/{}\".format(v.iloc[1], v.iloc[0]), \"\", coefs[k[1]]]))\n",
" else:\n",
" cols.append((k[1], [\"{}/{}\".format(v.iloc[1], v.iloc[0]), \"\"]))\n",
" #cols[k[1]] = [\"{}/{}\".format(v.iloc[1], v.iloc[0]), \"\"]\n",
" #df = pd.DataFrame.from_dict(cols)\n",
" df = pd.DataFrame.from_items(cols)\n",
" #return df.set_index('Evaluations')\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def build_latex_content(eval_pov, coefs=\"\"):\n",
" table = pd.pivot_table(eval_pov,\n",
" index = [\"Eleve\", \"Nom\"],\n",
" values = [\"Mark\", \"Bareme\"],\n",
" #columns = [\"Nom\"],\n",
" )\n",
" content = {}\n",
" content[\"students\"] = []\n",
" for e in eval_pov[\"Eleve\"].unique():\n",
" eleve = {\"name\":e}\n",
" e_table = table.query('Eleve == \"{}\"'.format(e))\n",
" summary = create_summary_table(e_table, coefs)\n",
" \n",
" col_format = \"|\"+\"c|\"*len(summary.columns)\n",
" #print(len(summary.columns))\n",
" eleve['latex_table'] = summary.to_latex(index=False, column_format=col_format)\n",
" content[\"students\"].append(eleve)\n",
" return content"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"coefs = {\"DM1\":0.5, \"DM2\":0.5, \"DS1\":1, \"DS2\":1, \"ConnT1\":1}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#build_latex_content(eval_pov)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#content = build_latex_content(eval_pov, coefs)\n",
"content = build_latex_content(eval_pov)\n",
"tpl = texenv.get_template(\"./tpl_bilan_trim.tex\")\n",
"with open(\"./{}/trim1.tex\".format(classe), \"w\") as f:\n",
" f.write(tpl.render(content))"
]
},
{
"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"
}
},
"nbformat": 4,
"nbformat_minor": 1
}