Compare commits
2 Commits
a5f22fc8cd
...
6eb918e0f5
Author | SHA1 | Date | |
---|---|---|---|
6eb918e0f5 | |||
56a669b2be |
@ -128,11 +128,6 @@ def prompt_exam(**kwrd):
|
||||
validator=Validator.from_callable(lambda x: x.isdigit()),
|
||||
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
|
||||
|
||||
|
@ -7,9 +7,10 @@ import sys
|
||||
import papermill as pm
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
import yaml
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -51,14 +52,37 @@ def exam_dict2row(exam):
|
||||
)
|
||||
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()
|
||||
def new_exam():
|
||||
""" Create new exam csv file """
|
||||
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"] = []
|
||||
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)
|
||||
|
||||
@ -72,7 +96,7 @@ def new_exam():
|
||||
path = Path(config["source"]) / exam["tribe"]["name"]
|
||||
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)
|
||||
print(f"Le fichier note a été enregistré à {dest}")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user