Compare commits

..

No commits in common. "6eb918e0f55779b89a2353f2b09545d9e582dd90" and "a5f22fc8cd0589901db7d3b551bae7ae6fb2c79e" have entirely different histories.

2 changed files with 10 additions and 29 deletions

View File

@ -128,6 +128,11 @@ 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,10 +7,9 @@ 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, prompt_validate from .prompts import prompt_exam, prompt_exercise
from ..config import NO_ST_COLUMNS from ..config import NO_ST_COLUMNS
@ -52,37 +51,14 @@ 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"])):
for i, ex in enumerate(exam["exercices"]): exam["exercices"].append(prompt_exercise(ex + 1))
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)
@ -96,7 +72,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 / get_exam_name(exam) + ".csv" dest = path / f"{exam['date'].strftime('%y%m%d')}_{exam['name']}.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}")