Compare commits

..

2 Commits

Author SHA1 Message Date
6eb918e0f5 Feat: can read exam config from yaml 2021-01-06 09:09:35 +01:00
56a669b2be Feat: remove exQty in prompt 2021-01-06 08:53:06 +01:00
2 changed files with 29 additions and 10 deletions

View File

@ -128,11 +128,6 @@ def prompt_exam(**kwrd):
validator=Validator.from_callable(lambda x: x.isdigit()), validator=Validator.from_callable(lambda x: x.isdigit()),
default=kwrd.get("term", "1"), default=kwrd.get("term", "1"),
) )
exam["ExQty"] = prompt(
"Nombre d'exercices: ",
validator=Validator.from_callable(lambda x: x.isdigit()),
default=kwrd.get("ExQty", "1"),
)
return exam return exam

View File

@ -7,9 +7,10 @@ import sys
import papermill as pm import papermill as pm
import pandas as pd import pandas as pd
from datetime import datetime from datetime import datetime
import yaml
from .getconfig import config, CONFIGPATH from .getconfig import config, CONFIGPATH
from .prompts import prompt_exam, prompt_exercise from .prompts import prompt_exam, prompt_exercise, prompt_validate
from ..config import NO_ST_COLUMNS from ..config import NO_ST_COLUMNS
@ -51,14 +52,37 @@ def exam_dict2row(exam):
) )
return rows return rows
def get_exam_name(exam):
""" Get exam name from exam data """
return f"{exam['date'].strftime('%y%m%d')}_{exam['name']}"
def get_tribe_path(exam):
""" Get tribe path from exam data """
return Path(config["source"]) / exam["tribe"]["name"]
def get_exam_path(exam, extention=""):
return get_tribe_path(exam)/ (get_exam_name(exam) + extention)
@cli.command() @cli.command()
def new_exam(): def new_exam():
""" Create new exam csv file """ """ Create new exam csv file """
exam = prompt_exam() exam = prompt_exam()
if get_exam_path(exam, ".yml").exists():
with open(get_exam_path(exam, ".yml"), "r") as f:
exam["exercices"] = yaml.load(f, Loader=yaml.SafeLoader)["exercices"]
else:
exam["exercices"] = [] exam["exercices"] = []
for ex in range(int(exam["ExQty"])):
exam["exercices"].append(prompt_exercise(ex + 1)) for i, ex in enumerate(exam["exercices"]):
exam["exercices"][i] = prompt_exercise(**ex)
new_exercise = prompt_validate("Ajouter un exercice? ")
while new_exercise:
exam["exercices"].append(prompt_exercise(len(exam["exercices"])+1))
new_exercise = prompt_validate("Ajouter un exercice? ")
rows = exam_dict2row(exam) rows = exam_dict2row(exam)
@ -72,7 +96,7 @@ def new_exam():
path = Path(config["source"]) / exam["tribe"]["name"] path = Path(config["source"]) / exam["tribe"]["name"]
path.mkdir(exist_ok=True) path.mkdir(exist_ok=True)
dest = path / f"{exam['date'].strftime('%y%m%d')}_{exam['name']}.csv" dest = path / get_exam_name(exam) + ".csv"
base_df.to_csv(dest, index=False) base_df.to_csv(dest, index=False)
print(f"Le fichier note a été enregistré à {dest}") print(f"Le fichier note a été enregistré à {dest}")