From 7d2cde304d22d26f8fef519a59a2cb7e7db5ba7f Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 22 Jan 2020 19:49:08 +0100 Subject: [PATCH] Feat: Prepare prompt to creat new csv score file --- recopytex/scripts/config.py | 10 +++ recopytex/scripts/prepare_csv.py | 120 +++++++++++++++++++++++++++++++ recopytex/scripts/recopytex.py | 33 ++++++--- 3 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 recopytex/scripts/config.py create mode 100644 recopytex/scripts/prepare_csv.py diff --git a/recopytex/scripts/config.py b/recopytex/scripts/config.py new file mode 100644 index 0000000..9ac61ef --- /dev/null +++ b/recopytex/scripts/config.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import yaml + +CONFIGPATH = "recoconfig.yml" + +with open(CONFIGPATH, "r") as configfile: + config = yaml.load(configfile, Loader=yaml.FullLoader) + diff --git a/recopytex/scripts/prepare_csv.py b/recopytex/scripts/prepare_csv.py new file mode 100644 index 0000000..309109e --- /dev/null +++ b/recopytex/scripts/prepare_csv.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import click +from pathlib import Path +from datetime import datetime +from PyInquirer import prompt, print_json + +from .config import config + +def prepare_csv(): + click.echo(f"Préparation d'un nouveau devoir") + + eval_questions = [ + { + "type": "input", + "name": "evalname", + "message": "Nom de l'évaluation", + }, + { + "type": "input", + "name": "tribe", + "message": "Classe concernée", + }, + { + "type": "input", + "name": "date", + "message": "Date du devoir", + "filter": lambda val: datetime.strptime(val, "%y%m%d") + }, + { + "type": "list", + "name": "term", + "message": "Trimestre", + "choices": ["1", "2", "3"], + } + ] + + exercise_questions = [ + { + "type": "input", + "name": "exercisename", + "message": "Nom de l'exercice" + }, + ] + + item_questions = [ + { + "type": "input", + "name": "itemname", + "message": "Nom de l'item", + }, + { + "type": "input", + "name": "comment", + "message": "Description", + }, + { + "type": "list", + "name": "competence", + "message": "Competence", + "choices": ["Cher", "Rep", "Mod", "Rai", "Cal", "Com"], + }, + { + "type": "input", + "name": "domain", + "message": "Domaine", + }, + { + "type": "confirm", + "name": "is_leveled", + "message": "Évaluation par niveau", + "default": True + }, + { + "type": "input", + "name": "scorerate", + "message": "Bareme" + }, + { + "type": "confirm", + "name": "correct", + "message": "Tout est correct?", + "default": True + }, + { + "type": "confirm", + "name": "add_item", + "message": "Ajouter un autre item", + "default": True, + }, + ] + + eval_ans = prompt(eval_questions) + + + items = [] + add_exo = True + while add_exo: + click.echo(f"Nouvel exercice") + exercise_ans = prompt(exercise_questions) + + add_item = True + while add_item: + click.echo(f"Nouvelle question pour l'exercice {exercise_ans['exercisename']}") + item_ans = prompt(item_questions) + if item_ans["correct"]: + add_item = item_ans["add_item"] + item_ans.update(eval_ans) + item_ans.update(exercise_ans) + items.append(item_ans) + + add_exo = prompt([{ + "type": "confirm", + "name": "add_exo", + "message": "Ajouter un autre exercice", + "default": True + }])["add_exo"] + + return items diff --git a/recopytex/scripts/recopytex.py b/recopytex/scripts/recopytex.py index fc8ab11..65bee8c 100644 --- a/recopytex/scripts/recopytex.py +++ b/recopytex/scripts/recopytex.py @@ -8,10 +8,8 @@ import sys import papermill as pm from datetime import datetime -CONFIGPATH = "recoconfig.yml" - -with open(CONFIGPATH, "r") as config: - config = yaml.load(config, Loader=yaml.FullLoader) +from .prepare_csv import prepare_csv +from .config import config @click.group() @@ -27,7 +25,7 @@ def print_config(): def reporting(csv_file): - #csv_file = Path(csv_file) + # csv_file = Path(csv_file) tribe_dir = csv_file.parent csv_filename = csv_file.name.split(".")[0] @@ -50,10 +48,14 @@ def reporting(csv_file): str(template), str(dest / f"{assessment}.ipynb"), parameters=dict( - tribe=tribe, assessment=assessment, date=f"{date:%d/%m/%y}", csv_file=str(csv_file.absolute()) + tribe=tribe, + assessment=assessment, + date=f"{date:%d/%m/%y}", + csv_file=str(csv_file.absolute()), ), ) + @cli.command() @click.argument("target", required=False) def report(target=""): @@ -72,9 +74,9 @@ def report(target=""): sys.exit(1) csvs = [csv] else: - csvs = list(Path(target).glob('**/*.csv')) + csvs = list(Path(target).glob("**/*.csv")) except AttributeError: - csvs = list(Path(config["source"]).glob('**/*.csv')) + csvs = list(Path(config["source"]).glob("**/*.csv")) for csv in csvs: click.echo(f"Processing {csv}") @@ -83,3 +85,18 @@ def report(target=""): except pm.exceptions.PapermillExecutionError as e: click.echo(f"Error with {csv}: {e}") + +@cli.command() +def prepare(): + """ Prepare csv file """ + + items = prepare_csv() + + click.echo(items) + + +@cli.command() +@click.argument("tribe") +def random_pick(tribe): + """ Randomly pick a student """ + pass