From 595102ecca98822353b0849d533a1af474ac7300 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 4 Aug 2019 16:25:44 +0200 Subject: [PATCH] Feat: cli to make a report --- recoconfig.yml | 4 ++ recopytex.py | 50 +++++++++++++++++++ templates/tpl_evaluation.ipynb | 90 ++++++++++++++++++++++++++++++++++ templates/tpl_student.ipynb | 81 ++++++++++++++++++++++++++++++ 4 files changed, 225 insertions(+) create mode 100644 recoconfig.yml create mode 100644 recopytex.py create mode 100644 templates/tpl_evaluation.ipynb create mode 100644 templates/tpl_student.ipynb diff --git a/recoconfig.yml b/recoconfig.yml new file mode 100644 index 0000000..9a64f7c --- /dev/null +++ b/recoconfig.yml @@ -0,0 +1,4 @@ +--- +source: sheets/ +output: reports/ +templates: templates/ diff --git a/recopytex.py b/recopytex.py new file mode 100644 index 0000000..dc3db95 --- /dev/null +++ b/recopytex.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import click +from pathlib import Path +import yaml +import sys +import papermill as pm + +with open("recoconfig.yml", "r") as config: + config = yaml.load(config, Loader=yaml.FullLoader) + + +@click.group() +def cli(): + pass + + +@cli.command() +def print_config(): + click.echo(config.key()) + + +@cli.command() +@click.argument("csv_file") +def report(csv_file): + csv = Path(csv_file) + if not csv.exists(): + click.echo(f"{csv_file} does not exists") + sys.exit(1) + if csv.suffix != ".csv": + click.echo(f"{csv_file} has to be a csv file") + sys.exit(1) + + *a, tribe, assessment_file = csv_file.split("/") + assessment_desc = assessment_file.split(".")[0] + assessment_name = assessment_desc.split("_")[-1].capitalize() + + template = Path(config["templates"]) / "tpl_evaluation.ipynb" + dest = Path(config["output"]) / tribe / assessment_name / f"{assessment_name}.ipynb" + + dest.parent.mkdir(parents=True, exist_ok=True) + + pm.execute_notebook( + str(template), str(dest), parameters=dict(tribe=tribe, assessment=assessment_name) + ) + + +if __name__ == "__main__": + cli() diff --git a/templates/tpl_evaluation.ipynb b/templates/tpl_evaluation.ipynb new file mode 100644 index 0000000..e411d53 --- /dev/null +++ b/templates/tpl_evaluation.ipynb @@ -0,0 +1,90 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "tribe = \"308\"\n", + "assessment = \"161114_dm2\"" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import Markdown as md\n", + "import pandas as pd\n", + "from pathlib import Path" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "csv_file = Path(f\"./sheets/{tribe}/{assessment}.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "# Ds1 pour 308" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "md(f\"# {assessment} pour {tribe}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "celltoolbar": "Tags", + "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.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/templates/tpl_student.ipynb b/templates/tpl_student.ipynb new file mode 100644 index 0000000..b98e8ed --- /dev/null +++ b/templates/tpl_student.ipynb @@ -0,0 +1,81 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "tribe = 308\n", + "student = \"ABDOU Asmahane\"" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import Markdown as md\n", + "import pandas as pd\n", + "from pathlib import Path" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "# ABDOU Asmahane en 308" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "md(f\"# {student} en {tribe}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "celltoolbar": "Tags", + "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.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}