{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "25b1d95f", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:07.404860Z", "iopub.status.busy": "2022-09-27T11:48:07.404445Z", "iopub.status.idle": "2022-09-27T11:48:07.901434Z", "shell.execute_reply": "2022-09-27T11:48:07.901038Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.551055, "end_time": "2022-09-27T11:48:07.901510", "exception": false, "start_time": "2022-09-27T11:48:07.350455", "status": "completed" }, "slideshow": { "slide_type": "skip" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Markdown as md\n", "from IPython.display import display, HTML\n", "import pandas as pd\n", "import numpy as np\n", "import ipywidgets as widgets\n", "from pathlib import Path\n", "from datetime import datetime\n", "from recopytex import flat_df_students, pp_q_scores\n", "from datetime import datetime\n", "\n", "\n", "import chart_studio.plotly as py\n", "import plotly.graph_objects as go\n", "import plotly.figure_factory as ff\n", "\n", "from plotly.offline import iplot, init_notebook_mode\n", "init_notebook_mode()" ] }, { "cell_type": "code", "execution_count": 2, "id": "3a865047", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:08.053625Z", "iopub.status.busy": "2022-09-27T11:48:08.053234Z", "iopub.status.idle": "2022-09-27T11:48:08.054561Z", "shell.execute_reply": "2022-09-27T11:48:08.054913Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.080662, "end_time": "2022-09-27T11:48:08.054996", "exception": false, "start_time": "2022-09-27T11:48:07.974334", "status": "completed" }, "slideshow": { "slide_type": "skip" }, "tags": [ "parameters" ] }, "outputs": [], "source": [ "tribe = \"ES\"\n", "assessment = \"ds2\"\n", "date = \"14/10/19\"\n", "csv_file = Path(f\"../{tribe}/191014_{assessment}.csv\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "05307eef", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:08.209887Z", "iopub.status.busy": "2022-09-27T11:48:08.209511Z", "iopub.status.idle": "2022-09-27T11:48:08.210992Z", "shell.execute_reply": "2022-09-27T11:48:08.211278Z" }, "papermill": { "duration": 0.081194, "end_time": "2022-09-27T11:48:08.211363", "exception": false, "start_time": "2022-09-27T11:48:08.130169", "status": "completed" }, "tags": [ "injected-parameters" ] }, "outputs": [], "source": [ "# Parameters\n", "tribe = \"2gt1\"\n", "assessment = \"Ds1\"\n", "date = \"22/09/22\"\n", "csv_file = \"/home/lafrite/Cours/2022-2023/Notes/2gt1/220922_DS1.csv\"\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "63832c37", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:08.364719Z", "iopub.status.busy": "2022-09-27T11:48:08.364307Z", "iopub.status.idle": "2022-09-27T11:48:08.366470Z", "shell.execute_reply": "2022-09-27T11:48:08.366084Z" }, "papermill": { "duration": 0.081448, "end_time": "2022-09-27T11:48:08.366554", "exception": false, "start_time": "2022-09-27T11:48:08.285106", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/lafrite/Cours/2022-2023/Notes/2gt1/220922_DS1\n" ] } ], "source": [ "date = datetime.strptime(date, \"%d/%m/%y\")\n", "output_path = Path(csv_file[:-4])\n", "print(output_path)" ] }, { "cell_type": "code", "execution_count": 5, "id": "2a41f502", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:08.528130Z", "iopub.status.busy": "2022-09-27T11:48:08.527692Z", "iopub.status.idle": "2022-09-27T11:48:08.530503Z", "shell.execute_reply": "2022-09-27T11:48:08.530107Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": false } } } }, "papermill": { "duration": 0.086523, "end_time": "2022-09-27T11:48:08.530574", "exception": false, "start_time": "2022-09-27T11:48:08.444051", "status": "completed" }, "slideshow": { "slide_type": "slide" }, "tags": [] }, "outputs": [ { "data": { "text/markdown": [ "# Ds1 (22/09/22) pour 2gt1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "if date is None:\n", " display(md(f\"# {assessment} pour {tribe}\"))\n", "else:\n", " display(md(f\"# {assessment} ({date:%y/%m/%d}) pour {tribe}\"))" ] }, { "cell_type": "code", "execution_count": 6, "id": "3149dc30", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:08.693503Z", "iopub.status.busy": "2022-09-27T11:48:08.689514Z", "iopub.status.idle": "2022-09-27T11:48:08.856891Z", "shell.execute_reply": "2022-09-27T11:48:08.857282Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.252227, "end_time": "2022-09-27T11:48:08.857420", "exception": false, "start_time": "2022-09-27T11:48:08.605193", "status": "completed" }, "slideshow": { "slide_type": "skip" }, "tags": [] }, "outputs": [], "source": [ "stack_scores = pd.read_csv(csv_file, encoding=\"UTF8\")\n", "#comments = stack_scores.iloc[0]\n", "#stack_scores.drop([0], inplace=True)\n", "scores = flat_df_students(stack_scores).dropna(subset=[\"Score\"])\n", "scores = pp_q_scores(scores)\n", "#scores.head()\n", "#comments.drop()" ] }, { "cell_type": "code", "execution_count": 7, "id": "48cb4a36", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:09.016836Z", "iopub.status.busy": "2022-09-27T11:48:09.016417Z", "iopub.status.idle": "2022-09-27T11:48:09.019573Z", "shell.execute_reply": "2022-09-27T11:48:09.019900Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.083936, "end_time": "2022-09-27T11:48:09.019986", "exception": false, "start_time": "2022-09-27T11:48:08.936050", "status": "completed" }, "slideshow": { "slide_type": "skip" }, "tags": [] }, "outputs": [], "source": [ "exercises_scores = scores.groupby([\"Exercice\", \"Eleve\"]).agg({\"Note\": \"sum\", \"Bareme\": \"sum\"})" ] }, { "cell_type": "code", "execution_count": 8, "id": "15025186", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:09.187514Z", "iopub.status.busy": "2022-09-27T11:48:09.186992Z", "iopub.status.idle": "2022-09-27T11:48:09.189105Z", "shell.execute_reply": "2022-09-27T11:48:09.189578Z" }, "papermill": { "duration": 0.095135, "end_time": "2022-09-27T11:48:09.189692", "exception": false, "start_time": "2022-09-27T11:48:09.094557", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NoteBareme
ExerciceEleve
Exercice 1ACHOUR Ilyes1.676.0
BELARBI Islem6.006.0
BEN ELALLID Hajar3.006.0
BISWAS Lina6.006.0
BOULAABA Rayan6.006.0
\n", "
" ], "text/plain": [ " Note Bareme\n", "Exercice Eleve \n", "Exercice 1 ACHOUR Ilyes 1.67 6.0\n", " BELARBI Islem 6.00 6.0\n", " BEN ELALLID Hajar 3.00 6.0\n", " BISWAS Lina 6.00 6.0\n", " BOULAABA Rayan 6.00 6.0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "exercises_scores.head()" ] }, { "cell_type": "code", "execution_count": 9, "id": "71c672c0", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:09.363728Z", "iopub.status.busy": "2022-09-27T11:48:09.362462Z", "iopub.status.idle": "2022-09-27T11:48:09.365125Z", "shell.execute_reply": "2022-09-27T11:48:09.365454Z" }, "papermill": { "duration": 0.084156, "end_time": "2022-09-27T11:48:09.365544", "exception": false, "start_time": "2022-09-27T11:48:09.281388", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "assessment_scores = scores.groupby([\"Eleve\"]).agg({\"Note\": \"sum\", \"Bareme\": \"sum\"})" ] }, { "cell_type": "code", "execution_count": 10, "id": "d8a02878", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:09.522024Z", "iopub.status.busy": "2022-09-27T11:48:09.521610Z", "iopub.status.idle": "2022-09-27T11:48:09.523450Z", "shell.execute_reply": "2022-09-27T11:48:09.523770Z" }, "papermill": { "duration": 0.082504, "end_time": "2022-09-27T11:48:09.523877", "exception": false, "start_time": "2022-09-27T11:48:09.441373", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Index(['Nom', 'Trimestre', 'Date', 'Exercice', 'Question', 'Competence',\n", " 'Domaine', 'Commentaire', 'Est_nivele', 'Bareme', 'Eleve', 'Score',\n", " 'Note', 'Niveau', 'Normalise'],\n", " dtype='object')" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scores.columns" ] }, { "cell_type": "code", "execution_count": 11, "id": "b6717594", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:09.691236Z", "iopub.status.busy": "2022-09-27T11:48:09.690814Z", "iopub.status.idle": "2022-09-27T11:48:09.694418Z", "shell.execute_reply": "2022-09-27T11:48:09.694696Z" }, "papermill": { "duration": 0.089071, "end_time": "2022-09-27T11:48:09.694783", "exception": false, "start_time": "2022-09-27T11:48:09.605712", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "domain_scores = scores.groupby([\"Eleve\", \"Domaine\"]).agg({\"Note\": \"sum\", \"Bareme\": \"sum\"})\n", "domain_scores[\"Normalized\"] = domain_scores[\"Note\"] / domain_scores[\"Bareme\"]" ] }, { "cell_type": "code", "execution_count": 12, "id": "d87553e1", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:09.850813Z", "iopub.status.busy": "2022-09-27T11:48:09.850377Z", "iopub.status.idle": "2022-09-27T11:48:09.852015Z", "shell.execute_reply": "2022-09-27T11:48:09.852364Z" }, "papermill": { "duration": 0.082291, "end_time": "2022-09-27T11:48:09.852464", "exception": false, "start_time": "2022-09-27T11:48:09.770173", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "#domain_scores" ] }, { "cell_type": "code", "execution_count": 13, "id": "61a49219", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:10.009566Z", "iopub.status.busy": "2022-09-27T11:48:10.009081Z", "iopub.status.idle": "2022-09-27T11:48:10.012664Z", "shell.execute_reply": "2022-09-27T11:48:10.013001Z" }, "papermill": { "duration": 0.084194, "end_time": "2022-09-27T11:48:10.013088", "exception": false, "start_time": "2022-09-27T11:48:09.928894", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "competence_scores = scores.groupby([\"Eleve\", \"Competence\"]).agg({\"Note\": \"sum\", \"Bareme\": \"sum\"})\n", "competence_scores[\"Normalized\"] = competence_scores[\"Note\"] / competence_scores[\"Bareme\"]" ] }, { "cell_type": "code", "execution_count": 14, "id": "7c8ad2c9", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:10.174584Z", "iopub.status.busy": "2022-09-27T11:48:10.174109Z", "iopub.status.idle": "2022-09-27T11:48:10.176537Z", "shell.execute_reply": "2022-09-27T11:48:10.176214Z" }, "papermill": { "duration": 0.087483, "end_time": "2022-09-27T11:48:10.176614", "exception": false, "start_time": "2022-09-27T11:48:10.089131", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NoteBaremeNormalized
EleveCompetence
THORAL FannyRaisonner0.003.00.00
Représenter1.335.50.24
TROPHARDY ElineCalculer10.5011.50.91
Raisonner3.003.01.00
Représenter5.175.50.94
\n", "
" ], "text/plain": [ " Note Bareme Normalized\n", "Eleve Competence \n", "THORAL Fanny Raisonner 0.00 3.0 0.00\n", " Représenter 1.33 5.5 0.24\n", "TROPHARDY Eline Calculer 10.50 11.5 0.91\n", " Raisonner 3.00 3.0 1.00\n", " Représenter 5.17 5.5 0.94" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "competence_scores.tail()" ] }, { "cell_type": "markdown", "id": "3437315d", "metadata": { "papermill": { "duration": 0.08402, "end_time": "2022-09-27T11:48:10.337276", "exception": false, "start_time": "2022-09-27T11:48:10.253256", "status": "completed" }, "tags": [] }, "source": [ "### Bilans personnalisés" ] }, { "cell_type": "code", "execution_count": 15, "id": "dd4fa512", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:10.498622Z", "iopub.status.busy": "2022-09-27T11:48:10.498181Z", "iopub.status.idle": "2022-09-27T11:48:10.510477Z", "shell.execute_reply": "2022-09-27T11:48:10.510137Z" }, "papermill": { "duration": 0.092685, "end_time": "2022-09-27T11:48:10.510553", "exception": false, "start_time": "2022-09-27T11:48:10.417868", "status": "completed" }, "scrolled": true, "tags": [] }, "outputs": [], "source": [ "import pytex\n", "#scores.head()" ] }, { "cell_type": "code", "execution_count": 16, "id": "6a667215", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:10.677612Z", "iopub.status.busy": "2022-09-27T11:48:10.677122Z", "iopub.status.idle": "2022-09-27T11:48:10.753701Z", "shell.execute_reply": "2022-09-27T11:48:10.753283Z" }, "papermill": { "duration": 0.167512, "end_time": "2022-09-27T11:48:10.753786", "exception": false, "start_time": "2022-09-27T11:48:10.586274", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "datas = {\n", " \"assessment\": {\n", " \"name\": assessment,\n", " \"date\": date\n", " },\n", " #\"exercises\": scores[\"Exercice\"].unique(),\n", " #\"questions\": scores[[\"Exercice\", 'Question', 'Competence', 'Domaine', 'Commentaire', 'Bareme', 'Est_nivele']],\n", " \"eleves\": {}\n", "}\n", "for e in scores[\"Eleve\"].unique():\n", " edatas = {\n", " \"e\": e,\n", " \"assessment\": assessment_scores.loc[e],\n", " \"exercices\": exercises_scores.xs(e, level=\"Eleve\"), \"exercices\": exercises_scores.xs(e, level=\"Eleve\"),\n", " \"domains\": domain_scores.xs(e, level=\"Eleve\"),\n", " \"competences\": competence_scores.xs(e, level=\"Eleve\"),\n", " \"exscores\": {}\n", " }\n", " for i, ex in edatas[\"exercices\"].iterrows():\n", " edatas[\"exscores\"][i] = scores.loc[(scores.Exercice==i) & (scores.Eleve==e)]\n", " datas[\"eleves\"][e] = edatas" ] }, { "cell_type": "code", "execution_count": 17, "id": "16b39fd6", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:10.910252Z", "iopub.status.busy": "2022-09-27T11:48:10.909846Z", "iopub.status.idle": "2022-09-27T11:48:10.911748Z", "shell.execute_reply": "2022-09-27T11:48:10.911352Z" }, "papermill": { "duration": 0.083031, "end_time": "2022-09-27T11:48:10.911821", "exception": false, "start_time": "2022-09-27T11:48:10.828790", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "score_template = r\"\"\"\n", "\\documentclass[a5paper,10pt]{article}\n", "\\usepackage{fullpage}\n", "\\usepackage{booktabs}\n", "\\usepackage{longtable}\n", "\\usepackage{tikz}\n", "\\usepackage{multicol}\n", "\n", "\\usepackage{geometry}\n", "\\geometry{left=10mm,right=10mm, top=10mm}\n", "\n", "\\renewcommand{\\arraystretch}{1}\n", "\\setlength{\\columnseprule}{0pt}\n", "\n", "\\pagestyle{empty}\n", "\n", "\n", "\\begin{document}\n", "\n", "\n", " \\section*{\\Var{assessment.name} \\hfill \\Var{e} \\hfill \\Var{sc.assessment.Note}/\\Var{sc.assessment.Bareme}}\n", " %- for i,ex in sc.exercices.iterrows() \n", " \\subsection*{\\Var{i}: \\hfill \\Var{ex.Note} / \\Var{ex.Bareme}}\n", " \\begin{center}\n", " \\Var{sc.exscores[i].to_latex(index=False, columns=[\"Question\", \"Domaine\", \"Commentaire\", \"Note\", \"Bareme\"])}\n", " \\end{center}\n", " %- endfor\n", " \n", " \\subsection*{Compétences}\n", " \\begin{multicols}{2}\n", " %- for i,dom in sc.competences.iterrows()\n", " \\noindent\n", " \\Var{i} \\hfill\n", " \\begin{tikzpicture}[scale=0.7]\n", " \\draw [](0,0) rectangle (3, 1);\n", " \\draw [fill=black!20] (0, 0) rectangle (\\Var{dom.Normalized*3}, 1);\n", " \\end{tikzpicture}\n", " \\hfill\n", " %\\Var{dom.Normalized}\n", " \n", " %- endfor\n", " \\end{multicols}\n", "\n", "\\end{document}\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 18, "id": "e7d7716e", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:11.072567Z", "iopub.status.busy": "2022-09-27T11:48:11.072064Z", "iopub.status.idle": "2022-09-27T11:48:16.097307Z", "shell.execute_reply": "2022-09-27T11:48:16.095616Z" }, "papermill": { "duration": 5.109438, "end_time": "2022-09-27T11:48:16.097377", "exception": false, "start_time": "2022-09-27T11:48:10.987939", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Wrote 220922_Ds1_ACHOUR Ilyes.tex\n", "Wrote 220922_Ds1_BELARBI Islem.tex\n", "Wrote 220922_Ds1_BEN ELALLID Hajar.tex\n", "Wrote 220922_Ds1_BISWAS Lina.tex\n", "Wrote 220922_Ds1_BOULAABA Rayan.tex\n", "Wrote 220922_Ds1_BREZUN Ines.tex\n", "Wrote 220922_Ds1_BUGNON Enzo.tex\n", "Wrote 220922_Ds1_CALLEWAERT Idaline.tex\n", "Wrote 220922_Ds1_CATTIN Clément.tex\n", "Wrote 220922_Ds1_CHRISTMANN Nathan.tex\n", "Wrote 220922_Ds1_DECOSTER Clément.tex\n", "Wrote 220922_Ds1_DEHIMAT Launy.tex\n", "Wrote 220922_Ds1_DUPONT Jessica.tex\n", "Wrote 220922_Ds1_GASAN Jéssica.tex\n", "Wrote 220922_Ds1_GEORGET Raphaël.tex\n", "Wrote 220922_Ds1_HABBAZ Hajar.tex\n", "Wrote 220922_Ds1_JACQUEMIER Samuel.tex\n", "Wrote 220922_Ds1_JACQUIER Juliette.tex\n", "Wrote 220922_Ds1_JOVIC Atanase.tex\n", "Wrote 220922_Ds1_KASSI Cheïma.tex\n", "Wrote 220922_Ds1_KICHENASSAMY Sanjay.tex\n", "Wrote 220922_Ds1_LE VEUZIT Adrien.tex\n", "Wrote 220922_Ds1_LETIF Ilef.tex\n", "Wrote 220922_Ds1_MANJALI Hiba.tex\n", "Wrote 220922_Ds1_MUTTONI Lou.tex\n", "Wrote 220922_Ds1_NEIVA Hugo.tex\n", "Wrote 220922_Ds1_OLLIET Gioia.tex\n", "Wrote 220922_Ds1_PERNOT Gabin.tex\n", "Wrote 220922_Ds1_RIZZI Elisa.tex\n", "Wrote 220922_Ds1_ROSTANT Emma.tex\n", "Wrote 220922_Ds1_SIBABA Moaad.tex\n", "Wrote 220922_Ds1_SOUJOL Damien.tex\n", "Wrote 220922_Ds1_THORAL Fanny.tex\n", "Wrote 220922_Ds1_TROPHARDY Eline.tex\n" ] } ], "source": [ "tpl = pytex.texenv.from_string(score_template)\n", "\n", "for e,sc in datas['eleves'].items():\n", " reportfilename = f\"{date:%y%m%d}_{assessment}_{e}.tex\"\n", " with open(output_path / reportfilename, \"w\") as f:\n", " f.write(tpl.render(sc=sc, e=e,**datas))\n", " print(f\"Wrote {reportfilename}\")\n", " pytex.pdflatex(reportfilename)" ] }, { "cell_type": "markdown", "id": "dfaf5d3d", "metadata": { "papermill": { "duration": 0.211414, "end_time": "2022-09-27T11:48:16.462524", "exception": false, "start_time": "2022-09-27T11:48:16.251110", "status": "completed" }, "tags": [] }, "source": [ "## Envoie des bilans par mail" ] }, { "cell_type": "code", "execution_count": 19, "id": "76384db8", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:16.782829Z", "iopub.status.busy": "2022-09-27T11:48:16.781664Z", "iopub.status.idle": "2022-09-27T11:48:16.784344Z", "shell.execute_reply": "2022-09-27T11:48:16.784663Z" }, "papermill": { "duration": 0.164784, "end_time": "2022-09-27T11:48:16.784751", "exception": false, "start_time": "2022-09-27T11:48:16.619967", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bian du devoir Ds1\n", "Bonsoir,\n", "En pièce jointe, vous trouverez un document détaillant la note du devoir.\n", "B.Bertrand\n", "\n" ] } ], "source": [ "mailfrom = \"benjamin.bertrand@ac-lyon.fr\"\n", "subject = f\"Bian du devoir {assessment}\"\n", "message = \"\"\"Bonsoir,\n", "En pièce jointe, vous trouverez un document détaillant la note du devoir.\n", "B.Bertrand\n", "\"\"\"\n", "print(subject)\n", "print(message)" ] }, { "cell_type": "code", "execution_count": 20, "id": "71eb9a2b", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:17.100522Z", "iopub.status.busy": "2022-09-27T11:48:17.100107Z", "iopub.status.idle": "2022-09-27T11:48:17.102673Z", "shell.execute_reply": "2022-09-27T11:48:17.103005Z" }, "papermill": { "duration": 0.163488, "end_time": "2022-09-27T11:48:17.103104", "exception": false, "start_time": "2022-09-27T11:48:16.939616", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import smtplib\n", "import os\n", "import sys\n", "from email.message import EmailMessage\n", "import mimetypes\n", "import time\n", "import random" ] }, { "cell_type": "code", "execution_count": 21, "id": "f2834e6b", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:17.420901Z", "iopub.status.busy": "2022-09-27T11:48:17.420509Z", "iopub.status.idle": "2022-09-27T11:48:17.421953Z", "shell.execute_reply": "2022-09-27T11:48:17.422265Z" }, "papermill": { "duration": 0.164253, "end_time": "2022-09-27T11:48:17.422351", "exception": false, "start_time": "2022-09-27T11:48:17.258098", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def build_msg(subj, to_addr, from_addr, body, att):\n", " msg = EmailMessage()\n", " msg[\"Subject\"] = subj\n", " msg[\"To\"] = to_addr\n", " #msg[\"To\"] = \"lafrite26@gmail.com\"\n", " msg[\"From\"] = from_addr\n", " msg.set_content(body)\n", "\n", " if att != []:\n", " ctype, encoding = mimetypes.guess_type(att)\n", " if ctype is None or encoding is not None:\n", " ctype = 'application/octet-stream'\n", " maintype, subtype = ctype.split('/', 1)\n", " with open(att, \"rb\") as f:\n", " msg.add_attachment(f.read(),\n", " maintype=maintype,\n", " subtype=subtype,\n", " filename=att.name)\n", " return msg\n" ] }, { "cell_type": "code", "execution_count": 22, "id": "30311066", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:17.745613Z", "iopub.status.busy": "2022-09-27T11:48:17.745207Z", "iopub.status.idle": "2022-09-27T11:48:17.747015Z", "shell.execute_reply": "2022-09-27T11:48:17.746650Z" }, "papermill": { "duration": 0.16894, "end_time": "2022-09-27T11:48:17.747088", "exception": false, "start_time": "2022-09-27T11:48:17.578148", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "send = 0\n", "fake = 1" ] }, { "cell_type": "code", "execution_count": 23, "id": "d31598c3", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:18.064312Z", "iopub.status.busy": "2022-09-27T11:48:18.063922Z", "iopub.status.idle": "2022-09-27T11:48:18.066069Z", "shell.execute_reply": "2022-09-27T11:48:18.065585Z" }, "papermill": { "duration": 0.1633, "end_time": "2022-09-27T11:48:18.066161", "exception": false, "start_time": "2022-09-27T11:48:17.902861", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "if send:\n", " if fake:\n", " server = smtplib.SMTP(\"localhost\", 8025)\n", " server.ehlo()\n", " else:\n", " server = smtplib.SMTP(\"smtps.ac-lyon.fr\", 587)\n", " server.ehlo()\n", " server.starttls()\n", " server.ehlo()\n", " server.login(\"bbertrand\", os.popen(\"pass Prof/Lyon/bbertrand\").read()[:-1]) " ] }, { "cell_type": "code", "execution_count": 24, "id": "ca5690d7", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:18.388603Z", "iopub.status.busy": "2022-09-27T11:48:18.388156Z", "iopub.status.idle": "2022-09-27T11:48:18.389976Z", "shell.execute_reply": "2022-09-27T11:48:18.389545Z" }, "papermill": { "duration": 0.168321, "end_time": "2022-09-27T11:48:18.390057", "exception": false, "start_time": "2022-09-27T11:48:18.221736", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "try:\n", " eleves_data = pd.read_csv(f\"../../{tribe}.csv\")\n", "except FileNotFoundError:\n", " try:\n", " eleves_data = pd.read_csv(f\"../{tribe}.csv\")\n", " except FileNotFoundError:\n", " eleves_data = pd.read_csv(f\"{tribe}.csv\")\n", "eleves_data.fillna(\"\", inplace=True)\n", "#eleves_data" ] }, { "cell_type": "code", "execution_count": 25, "id": "b676f878", "metadata": { "execution": { "iopub.execute_input": "2022-09-27T11:48:18.712395Z", "iopub.status.busy": "2022-09-27T11:48:18.711804Z", "iopub.status.idle": "2022-09-27T11:48:18.718564Z", "shell.execute_reply": "2022-09-27T11:48:18.718888Z" }, "papermill": { "duration": 0.170407, "end_time": "2022-09-27T11:48:18.718993", "exception": false, "start_time": "2022-09-27T11:48:18.548586", "status": "completed" }, "tags": [] }, "outputs": [ { "ename": "KeyError", "evalue": "'mail'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m~/.venv/enseignements/lib/python3.10/site-packages/pandas/core/indexes/base.py:3361\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3360\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 3361\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_engine\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3362\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n", "File \u001b[0;32m~/.venv/enseignements/lib/python3.10/site-packages/pandas/_libs/index.pyx:76\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32m~/.venv/enseignements/lib/python3.10/site-packages/pandas/_libs/index.pyx:108\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:5198\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:5206\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: 'mail'", "\nThe above exception was the direct cause of the following exception:\n", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [25]\u001b[0m, in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPas de rapport pour \u001b[39m\u001b[38;5;132;01m{\u001b[39;00me[\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNom\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43me\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmail\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m send:\n\u001b[1;32m 10\u001b[0m msg \u001b[38;5;241m=\u001b[39m build_msg(subject, e[\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmail\u001b[39m\u001b[38;5;124m\"\u001b[39m], mailfrom, message, reportfilename)\n", "File \u001b[0;32m~/.venv/enseignements/lib/python3.10/site-packages/pandas/core/series.py:942\u001b[0m, in \u001b[0;36mSeries.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 939\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[key]\n\u001b[1;32m 941\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m key_is_scalar:\n\u001b[0;32m--> 942\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_value\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 944\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_hashable(key):\n\u001b[1;32m 945\u001b[0m \u001b[38;5;66;03m# Otherwise index.get_value will raise InvalidIndexError\u001b[39;00m\n\u001b[1;32m 946\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 947\u001b[0m \u001b[38;5;66;03m# For labels that don't resolve as scalars like tuples and frozensets\u001b[39;00m\n", "File \u001b[0;32m~/.venv/enseignements/lib/python3.10/site-packages/pandas/core/series.py:1051\u001b[0m, in \u001b[0;36mSeries._get_value\u001b[0;34m(self, label, takeable)\u001b[0m\n\u001b[1;32m 1048\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[label]\n\u001b[1;32m 1050\u001b[0m \u001b[38;5;66;03m# Similar to Index.get_value, but we do not fall back to positional\u001b[39;00m\n\u001b[0;32m-> 1051\u001b[0m loc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindex\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlabel\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1052\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindex\u001b[38;5;241m.\u001b[39m_get_values_for_loc(\u001b[38;5;28mself\u001b[39m, loc, label)\n", "File \u001b[0;32m~/.venv/enseignements/lib/python3.10/site-packages/pandas/core/indexes/base.py:3363\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3361\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[1;32m 3362\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[0;32m-> 3363\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[1;32m 3365\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_scalar(key) \u001b[38;5;129;01mand\u001b[39;00m isna(key) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhasnans:\n\u001b[1;32m 3366\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key)\n", "\u001b[0;31mKeyError\u001b[0m: 'mail'" ] } ], "source": [ "for e in eleves_data.iterrows():\n", " reportfilename = Path(f\"{date:%y%m%d}_{assessment}_{e[1]['Nom']}.pdf\")\n", " try:\n", " assert reportfilename.exists()\n", " except:\n", " print(f\"Pas de rapport pour {e[1]['Nom']}\")\n", " else:\n", " if e[1][\"mail\"] != \"\":\n", " if send:\n", " msg = build_msg(subject, e[1][\"mail\"], mailfrom, message, reportfilename)\n", " server.send_message(msg)\n", " print(f\"\\tBilan envoyé à {e[1]['Nom']}\")\n", " else:\n", " print(f\"Pas de mail pour {e[1]['Nom']}\")\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "78e914c1", "metadata": { "papermill": { "duration": 0.158787, "end_time": "2022-09-27T11:48:19.033692", "exception": false, "start_time": "2022-09-27T11:48:18.874905", "status": "completed" }, "tags": [] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "24ff9733", "metadata": { "papermill": { "duration": 0.166951, "end_time": "2022-09-27T11:48:19.360034", "exception": false, "start_time": "2022-09-27T11:48:19.193083", "status": "completed" }, "tags": [] }, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Diaporama", "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 (ipykernel)", "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.10.7" }, "papermill": { "duration": 13.463594, "end_time": "2022-09-27T11:48:19.827083", "environment_variables": {}, "exception": null, "input_path": "templates/tpl_evaluation.ipynb", "output_path": "2gt1/220922_DS1/Ds1.ipynb", "parameters": { "assessment": "Ds1", "csv_file": "/home/lafrite/Cours/2022-2023/Notes/2gt1/220922_DS1.csv", "date": "22/09/22", "tribe": "2gt1" }, "start_time": "2022-09-27T11:48:06.363489", "version": "1.2.1" } }, "nbformat": 4, "nbformat_minor": 5 }