{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2020-10-04T07:26:57.870820Z", "iopub.status.busy": "2020-10-04T07:26:57.869670Z", "iopub.status.idle": "2020-10-04T07:26:58.499789Z", "shell.execute_reply": "2020-10-04T07:26:58.500257Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.66457, "end_time": "2020-10-04T07:26:58.500489", "exception": false, "start_time": "2020-10-04T07:26:57.835919", "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, "metadata": { "execution": { "iopub.execute_input": "2020-10-04T07:26:58.701039Z", "iopub.status.busy": "2020-10-04T07:26:58.700150Z", "iopub.status.idle": "2020-10-04T07:26:58.703382Z", "shell.execute_reply": "2020-10-04T07:26:58.702696Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.105904, "end_time": "2020-10-04T07:26:58.703518", "exception": false, "start_time": "2020-10-04T07:26:58.597614", "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, "metadata": { "execution": { "iopub.execute_input": "2020-10-04T07:26:58.908180Z", "iopub.status.busy": "2020-10-04T07:26:58.907084Z", "iopub.status.idle": "2020-10-04T07:26:58.911239Z", "shell.execute_reply": "2020-10-04T07:26:58.910123Z" }, "papermill": { "duration": 0.110363, "end_time": "2020-10-04T07:26:58.911455", "exception": false, "start_time": "2020-10-04T07:26:58.801092", "status": "completed" }, "tags": [ "injected-parameters" ] }, "outputs": [], "source": [ "# Parameters\n", "tribe = \"TST1\"\n", "assessment = \"Ds3\"\n", "date = \"13/11/20\"\n", "csv_file = \"/home/lafrite/Cours/2020-2021/Notes/TST1/201113_DS3.csv\"\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2020-10-04T07:26:59.130362Z", "iopub.status.busy": "2020-10-04T07:26:59.129790Z", "iopub.status.idle": "2020-10-04T07:26:59.131451Z", "shell.execute_reply": "2020-10-04T07:26:59.130977Z" }, "papermill": { "duration": 0.109746, "end_time": "2020-10-04T07:26:59.131570", "exception": false, "start_time": "2020-10-04T07:26:59.021824", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/lafrite/Cours/2020-2021/Notes/TST1/201113_DS3\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, "metadata": { "execution": { "iopub.execute_input": "2020-10-04T07:26:59.353722Z", "iopub.status.busy": "2020-10-04T07:26:59.353175Z", "iopub.status.idle": "2020-10-04T07:26:59.356913Z", "shell.execute_reply": "2020-10-04T07:26:59.356386Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": false } } } }, "papermill": { "duration": 0.122626, "end_time": "2020-10-04T07:26:59.357021", "exception": false, "start_time": "2020-10-04T07:26:59.234395", "status": "completed" }, "slideshow": { "slide_type": "slide" }, "tags": [] }, "outputs": [ { "data": { "text/markdown": [ "# Ds3 (20/11/13) pour TST1" ], "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": 45, "metadata": { "execution": { "iopub.execute_input": "2020-10-04T07:26:59.584153Z", "iopub.status.busy": "2020-10-04T07:26:59.583420Z", "iopub.status.idle": "2020-10-04T07:26:59.842267Z", "shell.execute_reply": "2020-10-04T07:26:59.840480Z" }, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": 0.385376, "end_time": "2020-10-04T07:26:59.842589", "exception": true, "start_time": "2020-10-04T07:26:59.457213", "status": "failed" }, "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": 8, "metadata": { "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": {}, "report_default": { "hidden": true } } } }, "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "slideshow": { "slide_type": "skip" }, "tags": [] }, "outputs": [], "source": [ "exercises_scores = scores.groupby([\"Exercice\", \"Eleve\"]).agg({\"Note\": \"sum\", \"Bareme\": \"sum\"})" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "outputs": [], "source": [ "assessment_scores = scores.groupby([\"Eleve\"]).agg({\"Note\": \"sum\", \"Bareme\": \"sum\"})" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "source": [ "### Bilans personnalisés" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "scrolled": true, "tags": [] }, "outputs": [], "source": [ "import pytex\n", "#scores.head()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "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", " \"assessment\": assessment_scores.loc[e],\n", " \"exercices\": exercises_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": 22, "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "outputs": [], "source": [ "score_template = r\"\"\"\n", "\\documentclass[a5paper,10pt]{article}\n", "\\usepackage{fullpage}\n", "\\usepackage{booktabs}\n", "\\usepackage{longtable}\n", "\n", "\\usepackage{geometry}\n", "\\geometry{left=10mm,right=10mm, top=10mm}\n", "\n", "\\renewcommand{\\arraystretch}{1}\n", "\\setlength{\\columnseprule}{0pt}\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*{Exercice \\Var{i}: \\Var{ex.Note} / \\Var{ex.Bareme}}\n", " \\Var{sc.exscores[i].to_latex(index=False, columns=[\"Question\", \"Domaine\", \"Commentaire\", \"Note\", \"Bareme\"])}\n", " %#\\Var{sc.exscores}\n", " %- endfor\n", "\n", "\\end{document}\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Wrote 201113_Ds3_AIOUAZ Ahmed.tex\n", "Wrote 201113_Ds3_BAHBAH Zakaria.tex\n", "Wrote 201113_Ds3_BENHATTAL Chakir.tex\n", "Wrote 201113_Ds3_CLAIN Avinash.tex\n", "Wrote 201113_Ds3_COLASSI Alexis.tex\n", "Wrote 201113_Ds3_COUBAT Alexis.tex\n", "Wrote 201113_Ds3_COULLON Anis.tex\n", "Wrote 201113_Ds3_DINGER Sölen.tex\n", "Wrote 201113_Ds3_EYRAUD Cynthia.tex\n", "Wrote 201113_Ds3_FERREIRA Léo.tex\n", "Wrote 201113_Ds3_FILALI Zakaria.tex\n", "Wrote 201113_Ds3_FOIGNY Romain.tex\n", "Wrote 201113_Ds3_HIPOLITO DA SILVA Andréa.tex\n", "Wrote 201113_Ds3_HUMBERT Rayan.tex\n", "Wrote 201113_Ds3_MASSON Grace.tex\n", "Wrote 201113_Ds3_MOKHTARI Nissrine.tex\n", "Wrote 201113_Ds3_MOUFAQ Amine.tex\n", "Wrote 201113_Ds3_ONAL Yakub.tex\n", "Wrote 201113_Ds3_SORIANO Laura.tex\n", "Wrote 201113_Ds3_VECCHIO Léa.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, **datas))\n", " print(f\"Wrote {reportfilename}\")\n", " pytex.pdflatex(reportfilename)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "source": [ "## Envoie des bilans par mail" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bian du devoir Ds3\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": 25, "metadata": {}, "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": 26, "metadata": {}, "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": null, "metadata": {}, "outputs": [], "source": [ "send = 0\n", "fake = 1" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "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": 40, "metadata": {}, "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": 39, "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pas de rapport pour BALLOFFET Kenza\n", "Pas de mail pour FOIGNY Romain\n", "Pas de mail pour HUMBERT Rayan\n" ] } ], "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, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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", "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.9.7" }, "papermill": { "duration": 4.26524, "end_time": "2020-10-04T07:27:01.280572", "environment_variables": {}, "exception": true, "input_path": "templates/tpl_evaluation.ipynb", "output_path": "TST1/200930_DS1/Ds1.ipynb", "parameters": { "assessment": "Ds1", "csv_file": "/home/lafrite/Cours/2020-2021/Notes/TST1/200930_DS1.csv", "date": "30/09/20", "tribe": "TST1" }, "start_time": "2020-10-04T07:26:57.015332", "version": "1.2.1" } }, "nbformat": 4, "nbformat_minor": 2 }