Compare commits
No commits in common. "1fe76657534e9ba13e8da5be5abaf316e626524b" and "e0ca1a458b07dd29fc5dbfd49856eec3ea3648af" have entirely different histories.
1fe7665753
...
e0ca1a458b
@ -4,9 +4,9 @@ output: ./
|
|||||||
templates: templates/
|
templates: templates/
|
||||||
|
|
||||||
competences:
|
competences:
|
||||||
Chercher:
|
Calculer:
|
||||||
name: Chercher
|
name: Calculer
|
||||||
abrv: Cher
|
abrv: Cal
|
||||||
Représenter:
|
Représenter:
|
||||||
name: Représenter
|
name: Représenter
|
||||||
abrv: Rep
|
abrv: Rep
|
||||||
|
@ -1,269 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# encoding: utf-8
|
|
||||||
|
|
||||||
import dash
|
|
||||||
import dash_html_components as html
|
|
||||||
import dash_core_components as dcc
|
|
||||||
import dash_table
|
|
||||||
from datetime import date, datetime
|
|
||||||
import uuid
|
|
||||||
import pandas as pd
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from ...scripts.getconfig import config
|
|
||||||
from ...config import NO_ST_COLUMNS
|
|
||||||
from ..app import app
|
|
||||||
from ...scripts.exam import Exam
|
|
||||||
|
|
||||||
QUESTION_COLUMNS = [
|
|
||||||
{"id": "id", "name": "Question"},
|
|
||||||
{
|
|
||||||
"id": "competence",
|
|
||||||
"name": "Competence",
|
|
||||||
"presentation": "dropdown",
|
|
||||||
},
|
|
||||||
{"id": "theme", "name": "Domaine"},
|
|
||||||
{"id": "comment", "name": "Commentaire"},
|
|
||||||
{"id": "score_rate", "name": "Bareme"},
|
|
||||||
{"id": "is_leveled", "name": "Est_nivele"},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def get_current_year_limit():
|
|
||||||
today = date.today()
|
|
||||||
if today.month > 8:
|
|
||||||
return {
|
|
||||||
"min_date_allowed": date(today.year, 9, 1),
|
|
||||||
"max_date_allowed": date(today.year + 1, 7, 15),
|
|
||||||
"initial_visible_month": today,
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"min_date_allowed": date(today.year - 1, 9, 1),
|
|
||||||
"max_date_allowed": date(today.year, 7, 15),
|
|
||||||
"initial_visible_month": today,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
layout = html.Div(
|
|
||||||
[
|
|
||||||
html.Header(
|
|
||||||
children=[
|
|
||||||
html.H1("Création d'une évaluation"),
|
|
||||||
html.P("Pas encore de sauvegarde", id="is-saved"),
|
|
||||||
html.Button("Enregistrer dans csv", id="save-csv"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
html.Main(
|
|
||||||
children=[
|
|
||||||
html.Form(
|
|
||||||
id="new-exam",
|
|
||||||
children=[
|
|
||||||
html.Label(
|
|
||||||
children=[
|
|
||||||
"Classe",
|
|
||||||
dcc.Dropdown(
|
|
||||||
id="tribe",
|
|
||||||
options=[
|
|
||||||
{"label": t["name"], "value": t["name"]}
|
|
||||||
for t in config["tribes"]
|
|
||||||
],
|
|
||||||
value=config["tribes"][0]["name"],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
html.Label(
|
|
||||||
children=[
|
|
||||||
"Nom de l'évaluation",
|
|
||||||
dcc.Input(
|
|
||||||
id="exam_name",
|
|
||||||
type="text",
|
|
||||||
placeholder="Nom de l'évaluation",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
html.Label(
|
|
||||||
children=[
|
|
||||||
"Date",
|
|
||||||
dcc.DatePickerSingle(
|
|
||||||
id="date",
|
|
||||||
date=date.today(),
|
|
||||||
**get_current_year_limit(),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
html.Label(
|
|
||||||
children=[
|
|
||||||
"Trimestre",
|
|
||||||
dcc.Dropdown(
|
|
||||||
id="term",
|
|
||||||
options=[
|
|
||||||
{"label": i + 1, "value": i + 1}
|
|
||||||
for i in range(3)
|
|
||||||
],
|
|
||||||
value=1,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
html.Div(
|
|
||||||
id="exercises",
|
|
||||||
children=[],
|
|
||||||
),
|
|
||||||
html.Button(
|
|
||||||
"Ajouter un exercice",
|
|
||||||
id="add-exercise",
|
|
||||||
className="add-exercise",
|
|
||||||
),
|
|
||||||
html.Div(
|
|
||||||
id="summary",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
dcc.Store(id="exam_store"),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
|
||||||
dash.dependencies.Output("exercises", "children"),
|
|
||||||
dash.dependencies.Input("add-exercise", "n_clicks"),
|
|
||||||
dash.dependencies.State("exercises", "children"),
|
|
||||||
)
|
|
||||||
def add_exercise(n_clicks, children):
|
|
||||||
if n_clicks is None:
|
|
||||||
return children
|
|
||||||
element_table = pd.DataFrame(columns=[c["id"] for c in QUESTION_COLUMNS])
|
|
||||||
element_table = element_table.append(pd.Series(name=0))
|
|
||||||
new_exercise = html.Div(
|
|
||||||
children=[
|
|
||||||
html.Div(
|
|
||||||
children=[
|
|
||||||
dcc.Input(
|
|
||||||
id={"type": "exercice", "index": str(n_clicks)},
|
|
||||||
type="text",
|
|
||||||
value=f"Exercice {len(children)+1}",
|
|
||||||
placeholder="Nom de l'exercice",
|
|
||||||
className="exercise-name",
|
|
||||||
),
|
|
||||||
html.Button(
|
|
||||||
"X",
|
|
||||||
id={"type": "rm_exercice", "index": str(n_clicks)},
|
|
||||||
className="delete-exercise",
|
|
||||||
),
|
|
||||||
],
|
|
||||||
className="exercise-head",
|
|
||||||
),
|
|
||||||
dash_table.DataTable(
|
|
||||||
id={"type": "elements", "index": str(n_clicks)},
|
|
||||||
columns=QUESTION_COLUMNS,
|
|
||||||
data=element_table.to_dict("records"),
|
|
||||||
editable=True,
|
|
||||||
row_deletable=True,
|
|
||||||
dropdown={
|
|
||||||
"Competence": {
|
|
||||||
"options": [
|
|
||||||
{"label": i, "value": i} for i in config["competences"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
style_cell={
|
|
||||||
"whiteSpace": "normal",
|
|
||||||
"height": "auto",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
html.Button(
|
|
||||||
"Ajouter un élément de notation",
|
|
||||||
id={"type": "add-element", "index": str(n_clicks)},
|
|
||||||
className="add-element",
|
|
||||||
),
|
|
||||||
],
|
|
||||||
className="exercise",
|
|
||||||
id=f"exercise-{n_clicks}",
|
|
||||||
)
|
|
||||||
children.append(new_exercise)
|
|
||||||
return children
|
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
|
||||||
dash.dependencies.Output(
|
|
||||||
{"type": "elements", "index": dash.dependencies.MATCH}, "data"
|
|
||||||
),
|
|
||||||
dash.dependencies.Input(
|
|
||||||
{"type": "add-element", "index": dash.dependencies.MATCH}, "n_clicks"
|
|
||||||
),
|
|
||||||
[
|
|
||||||
dash.dependencies.State(
|
|
||||||
{"type": "elements", "index": dash.dependencies.MATCH}, "data"
|
|
||||||
),
|
|
||||||
],
|
|
||||||
prevent_initial_call=True,
|
|
||||||
)
|
|
||||||
def add_element(n_clicks, elements):
|
|
||||||
if n_clicks is None or n_clicks < len(elements):
|
|
||||||
return elements
|
|
||||||
|
|
||||||
df = pd.DataFrame.from_records(elements)
|
|
||||||
df = df.append(pd.Series(name=n_clicks))
|
|
||||||
return df.to_dict("records")
|
|
||||||
|
|
||||||
|
|
||||||
def exam_generalities(tribe, exam_name, date, term, exercices=[], elements=[]):
|
|
||||||
return [
|
|
||||||
html.H1(f"{exam_name} pour les {tribe}"),
|
|
||||||
html.P(f"Fait le {date} (Trimestre {term})"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def exercise_summary(identifier, name, elements=[]):
|
|
||||||
df = pd.DataFrame.from_records(elements)
|
|
||||||
return html.Div(
|
|
||||||
[
|
|
||||||
html.H2(name),
|
|
||||||
dash_table.DataTable(
|
|
||||||
columns=[{"id": c, "name": c} for c in df], data=elements
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
|
||||||
dash.dependencies.Output("exam_store", "data"),
|
|
||||||
[
|
|
||||||
dash.dependencies.Input("tribe", "value"),
|
|
||||||
dash.dependencies.Input("exam_name", "value"),
|
|
||||||
dash.dependencies.Input("date", "date"),
|
|
||||||
dash.dependencies.Input("term", "value"),
|
|
||||||
dash.dependencies.Input(
|
|
||||||
{"type": "exercice", "index": dash.dependencies.ALL}, "value"
|
|
||||||
),
|
|
||||||
dash.dependencies.Input(
|
|
||||||
{"type": "elements", "index": dash.dependencies.ALL}, "data"
|
|
||||||
),
|
|
||||||
],
|
|
||||||
dash.dependencies.State({"type": "elements", "index": dash.dependencies.ALL}, "id"),
|
|
||||||
)
|
|
||||||
def store_exam(tribe, exam_name, date, term, exercices, elements, elements_id):
|
|
||||||
exam = Exam(exam_name, tribe, date, term)
|
|
||||||
for (i, name) in enumerate(exercices):
|
|
||||||
ex_elements_id = [el for el in elements_id if el["index"] == str(i + 1)][0]
|
|
||||||
index = elements_id.index(ex_elements_id)
|
|
||||||
ex_elements = elements[index]
|
|
||||||
exam.add_exercise(name, ex_elements)
|
|
||||||
|
|
||||||
print(yaml.dump(exam.to_dict()))
|
|
||||||
return exam.to_dict()
|
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
|
||||||
dash.dependencies.Output("is-saved", "children"),
|
|
||||||
dash.dependencies.Input("save-csv", "n_clicks"),
|
|
||||||
dash.dependencies.State("exam_store", "data"),
|
|
||||||
prevent_initial_call=True,
|
|
||||||
)
|
|
||||||
def save_to_csv(n_clicks, data):
|
|
||||||
exam = Exam(**data)
|
|
||||||
csv = exam.path(".csv")
|
|
||||||
exam.write_csv()
|
|
||||||
return [f"Dernière sauvegarde {datetime.today()} dans {csv}"]
|
|
@ -15,7 +15,7 @@ import numpy as np
|
|||||||
|
|
||||||
from ... import flat_df_students, pp_q_scores
|
from ... import flat_df_students, pp_q_scores
|
||||||
from ...config import NO_ST_COLUMNS
|
from ...config import NO_ST_COLUMNS
|
||||||
from ...scripts.getconfig import config
|
from ...scripts.getconfig import config, CONFIGPATH
|
||||||
from ..app import app
|
from ..app import app
|
||||||
|
|
||||||
COLORS = {
|
COLORS = {
|
||||||
|
@ -4,7 +4,6 @@ from dash.dependencies import Input, Output
|
|||||||
|
|
||||||
from .app import app
|
from .app import app
|
||||||
from .exam_analysis import app as exam_analysis
|
from .exam_analysis import app as exam_analysis
|
||||||
from .create_exam import app as create_exam
|
|
||||||
|
|
||||||
|
|
||||||
app.layout = html.Div(
|
app.layout = html.Div(
|
||||||
@ -16,8 +15,6 @@ app.layout = html.Div(
|
|||||||
def display_page(pathname):
|
def display_page(pathname):
|
||||||
if pathname == "/":
|
if pathname == "/":
|
||||||
return exam_analysis.layout
|
return exam_analysis.layout
|
||||||
elif pathname == "/create-exam":
|
|
||||||
return create_exam.layout
|
|
||||||
else:
|
else:
|
||||||
return "404"
|
return "404"
|
||||||
|
|
||||||
|
@ -4,36 +4,22 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from prompt_toolkit import HTML
|
from prompt_toolkit import HTML
|
||||||
from ..config import NO_ST_COLUMNS
|
|
||||||
import pandas as pd
|
|
||||||
import yaml
|
import yaml
|
||||||
from .getconfig import config
|
from .getconfig import config
|
||||||
|
|
||||||
|
|
||||||
def try_parsing_date(text, formats=["%Y-%m-%d", "%Y.%m.%d", "%Y/%m/%d"]):
|
|
||||||
for fmt in formats:
|
|
||||||
try:
|
|
||||||
return datetime.strptime(text[:10], fmt)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
raise ValueError("no valid date format found")
|
|
||||||
|
|
||||||
|
|
||||||
class Exam:
|
class Exam:
|
||||||
def __init__(self, name, tribename, date, term, **kwrds):
|
def __init__(self, name, tribename, date, term, **kwrds):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._tribename = tribename
|
self._tribename = tribename
|
||||||
|
try:
|
||||||
self._date = try_parsing_date(date)
|
self._date = datetime.strptime(date, "%y%m%d")
|
||||||
|
except:
|
||||||
|
self._date = date
|
||||||
|
|
||||||
self._term = term
|
self._term = term
|
||||||
|
|
||||||
try:
|
self._exercises = {}
|
||||||
kwrds["exercices"]
|
|
||||||
except KeyError:
|
|
||||||
self._exercises = {}
|
|
||||||
else:
|
|
||||||
self._exercises = kwrds["exercices"]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -139,21 +125,8 @@ class Exam:
|
|||||||
def display(self, name):
|
def display(self, name):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def write_yaml(self):
|
def write(self):
|
||||||
print(f"Sauvegarde temporaire dans {self.path('.yml')}")
|
print(f"Sauvegarde temporaire dans {self.path('.yml')}")
|
||||||
self.tribe_path.mkdir(exist_ok=True)
|
self.tribe_path.mkdir(exist_ok=True)
|
||||||
with open(self.path(".yml"), "w") as f:
|
with open(self.path(".yml"), "w") as f:
|
||||||
f.write(yaml.dump(self.to_dict()))
|
f.write(yaml.dump(self.to_dict()))
|
||||||
|
|
||||||
def write_csv(self):
|
|
||||||
rows = self.to_row()
|
|
||||||
|
|
||||||
base_df = pd.DataFrame.from_dict(rows)[NO_ST_COLUMNS.keys()]
|
|
||||||
base_df.rename(columns=NO_ST_COLUMNS, inplace=True)
|
|
||||||
|
|
||||||
students = pd.read_csv(self.tribe_student_path)["Nom"]
|
|
||||||
for student in students:
|
|
||||||
base_df[student] = ""
|
|
||||||
|
|
||||||
self.tribe_path.mkdir(exist_ok=True)
|
|
||||||
base_df.to_csv(self.path(".csv"), index=False)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user