Compare commits
No commits in common. "27d7c459800b490c2d6f3797640b679efd2ab011" and "6eb918e0f55779b89a2353f2b09545d9e582dd90" have entirely different histories.
27d7c45980
...
6eb918e0f5
@ -5,14 +5,14 @@ templates: templates/
|
||||
|
||||
competences:
|
||||
Calculer:
|
||||
name: Calculer
|
||||
abrv: Cal
|
||||
name: Calculer
|
||||
abrv: Cal
|
||||
Représenter:
|
||||
name: Représenter
|
||||
abrv: Rep
|
||||
name: Représenter
|
||||
abrv: Rep
|
||||
Modéliser:
|
||||
name: Modéliser
|
||||
abrv: Mod
|
||||
name: Modéliser
|
||||
abrv: Mod
|
||||
Raisonner:
|
||||
name: Raisonner
|
||||
abrv: Rai
|
||||
|
@ -1,132 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from prompt_toolkit import HTML
|
||||
import yaml
|
||||
from .getconfig import config
|
||||
|
||||
|
||||
class Exam:
|
||||
def __init__(self, name, tribename, date, term, **kwrds):
|
||||
self._name = name
|
||||
self._tribename = tribename
|
||||
try:
|
||||
self._date = datetime.strptime(date, "%y%m%d")
|
||||
except:
|
||||
self._date = date
|
||||
|
||||
self._term = term
|
||||
|
||||
self._exercises = {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def tribename(self):
|
||||
return self._tribename
|
||||
|
||||
@property
|
||||
def date(self):
|
||||
return self._date
|
||||
|
||||
@property
|
||||
def term(self):
|
||||
return self._term
|
||||
|
||||
def add_exercise(self, name, questions):
|
||||
""" Add key with questions in ._exercises """
|
||||
try:
|
||||
self._exercises[name]
|
||||
except KeyError:
|
||||
self._exercises[name] = questions
|
||||
else:
|
||||
raise KeyError("The exercise already exsists. Use modify_exercise")
|
||||
|
||||
def modify_exercise(self, name, questions, append=False):
|
||||
"""Modify questions of an exercise
|
||||
|
||||
If append==True, add questions to the exercise questions
|
||||
|
||||
"""
|
||||
try:
|
||||
self._exercises[name]
|
||||
except KeyError:
|
||||
raise KeyError("The exercise already exsists. Use modify_exercise")
|
||||
else:
|
||||
if append:
|
||||
self._exercises[name] += questions
|
||||
else:
|
||||
self._exercises[name] = questions
|
||||
|
||||
@property
|
||||
def exercices(self):
|
||||
return self._exercises
|
||||
|
||||
@property
|
||||
def tribe_path(self):
|
||||
return Path(config["source"]) / self.tribename
|
||||
|
||||
@property
|
||||
def tribe_student_path(self):
|
||||
return (
|
||||
Path(config["source"])
|
||||
/ [t["students"] for t in config["tribes"] if t["name"] == self.tribename][
|
||||
0
|
||||
]
|
||||
)
|
||||
|
||||
@property
|
||||
def long_name(self):
|
||||
""" Get exam name with date inside """
|
||||
return f"{self.date.strftime('%y%m%d')}_{self.name}"
|
||||
|
||||
def path(self, extention=""):
|
||||
return self.tribe_path / (self.long_name + extention)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"name": self.name,
|
||||
"tribename": self.tribename,
|
||||
"date": self.date,
|
||||
"term": self.term,
|
||||
"exercices": self.exercices,
|
||||
}
|
||||
|
||||
def to_row(self):
|
||||
rows = []
|
||||
for ex, questions in self.exercices.items():
|
||||
for q in questions:
|
||||
rows.append(
|
||||
{
|
||||
"term": self.term,
|
||||
"assessment": self.name,
|
||||
"date": self.date.strftime("%d/%m/%Y"),
|
||||
"exercise": ex,
|
||||
"question": q["id"],
|
||||
**q,
|
||||
}
|
||||
)
|
||||
return rows
|
||||
|
||||
@property
|
||||
def themes(self):
|
||||
themes = set()
|
||||
for questions in self._exercises.values():
|
||||
themes.update([q["theme"] for q in questions])
|
||||
return themes
|
||||
|
||||
def display_exercise(self, name):
|
||||
pass
|
||||
|
||||
def display(self, name):
|
||||
pass
|
||||
|
||||
def write(self):
|
||||
print(f"Sauvegarde temporaire dans {self.path('.yml')}")
|
||||
self.tribe_path.mkdir(exist_ok=True)
|
||||
with open(self.path(".yml"), "w") as f:
|
||||
f.write(yaml.dump(self.to_dict()))
|
@ -133,18 +133,18 @@ def prompt_exam(**kwrd):
|
||||
|
||||
|
||||
@prompt_until_validate()
|
||||
def prompt_exercise(number=1, completer={}, **kwrd):
|
||||
exercise = {}
|
||||
def prompt_exercise(number=1, **kwrd):
|
||||
try:
|
||||
kwrd["name"]
|
||||
except KeyError:
|
||||
print(HTML("<b>Nouvel exercice</b>"))
|
||||
exercise["name"] = prompt(
|
||||
"Nom de l'exercice: ", default=kwrd.get("name", f"Exercice {number}")
|
||||
)
|
||||
else:
|
||||
print(HTML(f"<b>Modification de l'exercice: {kwrd['name']}</b>"))
|
||||
exercise["name"] = kwrd["name"]
|
||||
|
||||
exercise = {}
|
||||
exercise["name"] = prompt(
|
||||
"Nom de l'exercice: ", default=kwrd.get("name", f"Exercice {number}")
|
||||
)
|
||||
|
||||
exercise["questions"] = []
|
||||
|
||||
@ -157,9 +157,7 @@ def prompt_exercise(number=1, completer={}, **kwrd):
|
||||
else:
|
||||
for ques in kwrd["questions"]:
|
||||
try:
|
||||
exercise["questions"].append(
|
||||
prompt_question(completer=completer, **ques)
|
||||
)
|
||||
exercise["questions"].append(prompt_question(**ques))
|
||||
except CancelError:
|
||||
print("Cette question a été supprimée")
|
||||
last_question_id = exercise["questions"][-1]["id"]
|
||||
@ -169,9 +167,7 @@ def prompt_exercise(number=1, completer={}, **kwrd):
|
||||
)
|
||||
while appending:
|
||||
try:
|
||||
exercise["questions"].append(
|
||||
prompt_question(last_question_id, completer=completer)
|
||||
)
|
||||
exercise["questions"].append(prompt_question(last_question_id))
|
||||
except CancelError:
|
||||
print("Cette question a été supprimée")
|
||||
else:
|
||||
@ -184,14 +180,16 @@ def prompt_exercise(number=1, completer={}, **kwrd):
|
||||
|
||||
|
||||
@prompt_until_validate(cancelable=True)
|
||||
def prompt_question(last_question_id="1a", completer={}, **kwrd):
|
||||
def prompt_question(last_question_id="1a", **kwrd):
|
||||
try:
|
||||
kwrd["id"]
|
||||
except KeyError:
|
||||
print(HTML("<b>Nouvel élément de notation</b>"))
|
||||
else:
|
||||
print(
|
||||
HTML(f"<b>Modification de l'élément {kwrd['id']} ({kwrd['comment']})</b>")
|
||||
HTML(
|
||||
f"<b>Modification de l'élément {kwrd['id']} ({kwrd['comment']})</b>"
|
||||
)
|
||||
)
|
||||
|
||||
question = {}
|
||||
@ -210,7 +208,7 @@ def prompt_question(last_question_id="1a", completer={}, **kwrd):
|
||||
question["theme"] = prompt(
|
||||
"Domaine: ",
|
||||
default=kwrd.get("theme", ""),
|
||||
completer=WordCompleter(completer.get("theme", [])),
|
||||
# completer
|
||||
)
|
||||
|
||||
question["comment"] = prompt(
|
||||
|
@ -12,7 +12,6 @@ import yaml
|
||||
from .getconfig import config, CONFIGPATH
|
||||
from .prompts import prompt_exam, prompt_exercise, prompt_validate
|
||||
from ..config import NO_ST_COLUMNS
|
||||
from .exam import Exam
|
||||
|
||||
|
||||
@click.group()
|
||||
@ -36,53 +35,70 @@ def setup():
|
||||
print(f"The file {tribe['students']} does not exists")
|
||||
|
||||
|
||||
def exam_dict2row(exam):
|
||||
""" Transform an exam in dictionnary for into list of rows to evaluate"""
|
||||
rows = []
|
||||
for ex in exam["exercices"]:
|
||||
for q in ex["questions"]:
|
||||
rows.append(
|
||||
{
|
||||
"term": exam["term"],
|
||||
"assessment": exam["name"],
|
||||
"date": exam["date"].strftime("%d/%m/%Y"),
|
||||
"exercise": ex["name"],
|
||||
"question": q["id"],
|
||||
**q,
|
||||
}
|
||||
)
|
||||
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 = Exam(**prompt_exam())
|
||||
exam = prompt_exam()
|
||||
|
||||
if exam.path(".yml").exists():
|
||||
print(f"Fichier sauvegarde trouvé à {exam.path('.yml')} -- importation")
|
||||
with open(exam.path(".yml"), "r") as f:
|
||||
for name, questions in yaml.load(f, Loader=yaml.SafeLoader)[
|
||||
"exercices"
|
||||
].items():
|
||||
exam.add_exercise(name, questions)
|
||||
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"] = []
|
||||
|
||||
print(exam.themes)
|
||||
# print(yaml.dump(exam.to_dict()))
|
||||
|
||||
exam.write()
|
||||
|
||||
for name, questions in exam.exercices.items():
|
||||
exam.modify_exercise(
|
||||
**prompt_exercise(
|
||||
name=name, completer={"theme": exam.themes}, questions=questions
|
||||
)
|
||||
)
|
||||
exam.write()
|
||||
for i, ex in enumerate(exam["exercices"]):
|
||||
exam["exercices"][i] = prompt_exercise(**ex)
|
||||
|
||||
new_exercise = prompt_validate("Ajouter un exercice? ")
|
||||
while new_exercise:
|
||||
exam.add_exercise(
|
||||
**prompt_exercise(len(exam.exercices) + 1, completer={"theme": exam.themes})
|
||||
)
|
||||
exam.write()
|
||||
exam["exercices"].append(prompt_exercise(len(exam["exercices"])+1))
|
||||
new_exercise = prompt_validate("Ajouter un exercice? ")
|
||||
|
||||
rows = exam.to_row()
|
||||
|
||||
rows = exam_dict2row(exam)
|
||||
|
||||
base_df = pd.DataFrame.from_dict(rows)[NO_ST_COLUMNS.keys()]
|
||||
base_df.rename(columns=NO_ST_COLUMNS, inplace=True)
|
||||
|
||||
students = pd.read_csv(exam.tribe_student_path)["Nom"]
|
||||
students = pd.read_csv(exam["tribe"]["students"])["Nom"]
|
||||
for student in students:
|
||||
base_df[student] = ""
|
||||
|
||||
exam.tribe_path.mkdir(exist_ok=True)
|
||||
path = Path(config["source"]) / exam["tribe"]["name"]
|
||||
path.mkdir(exist_ok=True)
|
||||
|
||||
base_df.to_csv(exam.path(".csv"), index=False)
|
||||
print(f"Le fichier note a été enregistré à {exam.path('.csv')}")
|
||||
dest = path / get_exam_name(exam) + ".csv"
|
||||
base_df.to_csv(dest, index=False)
|
||||
print(f"Le fichier note a été enregistré à {dest}")
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
Loading…
Reference in New Issue
Block a user