129 lines
3.5 KiB
Python
129 lines
3.5 KiB
Python
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
|
|
import sqlite3
|
|
import pandas as pd
|
|
import numpy as np
|
|
from math import ceil
|
|
|
|
NOANSWER = "."
|
|
NOTRATED = ""
|
|
COMPETENCES = {
|
|
"Cher": {"fullname": "Chercher", "latex": "\\Cher"},
|
|
"Mod": {"fullname": "Modéliser", "latex": "\\Mod"},
|
|
"Rep": {"fullname": "Représenter", "latex": "\\Rep"},
|
|
"Rai": {"fullname": "Raisonner", "latex": "\\Rai"},
|
|
"Cal": {"fullname": "Calculer", "latex": "\\Cal"},
|
|
"Com": {"fullname": "Communiquer", "latex": "\\Com"},
|
|
"Con": {"fullname": "Connaître", "latex": "\\Con"},
|
|
}
|
|
|
|
# Pick from db
|
|
|
|
def df_from_db(eval_id):
|
|
db = "recopytex.db"
|
|
conn = sqlite3.connect(db)
|
|
df = pd.read_sql_query("SELECT \
|
|
student.name as name,\
|
|
student.surname as surname,\
|
|
score.value as value, \
|
|
question.competence as competence,\
|
|
question.name as question,\
|
|
question.comment as comment,\
|
|
exercise.name as exercise, \
|
|
eval.name as eval\
|
|
FROM score\
|
|
JOIN question ON score.question_id==question.id \
|
|
JOIN exercise ON question.exercise_id==exercise.id \
|
|
JOIN eval ON exercise.eval_id==eval.id \
|
|
JOIN student ON score.student_id==student.id\
|
|
WHERE eval.id == (?)",
|
|
conn,
|
|
params = (eval_id,))
|
|
return df
|
|
|
|
def prepare_df(df):
|
|
df = df[df["value"]!=NOTRATED]
|
|
df["score"] = df.apply(col2score, axis=1)
|
|
df["fullname"] = df["name"] + " " + df["surname"]
|
|
df['competence'] = df["competence"].astype("category",
|
|
categories = list(COMPETENCES.keys()), ordered=True,)
|
|
#df["abv_competence"] = df["competence"]
|
|
#df["competence"] = df.apply(competence_fullname, axis=1)
|
|
df["latex"] = df.apply(col2latex, axis=1)
|
|
#df["latex_competence"] = df.apply(competence_latex, axis=1)
|
|
return df
|
|
|
|
# Value transformations
|
|
|
|
def val2score(x):
|
|
if x == '.':
|
|
return 0
|
|
if x not in [0, 1, 2, 3]:
|
|
raise ValueError(f"The evaluation is out of range. Got {x}")
|
|
return x
|
|
|
|
def val2latex(x):
|
|
latex_caract = ["\\NoRep", "\\RepZ", "\\RepU", "\\RepD", "\\RepT"]
|
|
if x == NOANSWER:
|
|
return latex_caract[0]
|
|
elif x in range(4):
|
|
return latex_caract[int(x)+1]
|
|
return x
|
|
val2latex.__name__ = "Aquisition"
|
|
|
|
def rounded_mean(x, rounded=0):
|
|
""" Rounded x mean """
|
|
mean = np.mean(x)
|
|
return round(mean, rounded)
|
|
rounded_mean.__name__ = "Moyenne discrète"
|
|
|
|
# Columns transformations
|
|
|
|
def col2score(x):
|
|
return val2score(x["value"])
|
|
|
|
def col2latex(x):
|
|
return val2latex(x["value"])
|
|
|
|
def competence_fullname(x):
|
|
try:
|
|
return COMPETENCES[x['competence']]["fullname"]
|
|
except KeyError:
|
|
return ""
|
|
|
|
def competence_latex(x):
|
|
try:
|
|
return COMPETENCES[x['competence']]["latex"]
|
|
except KeyError:
|
|
return ""
|
|
|
|
|
|
# Df transforms
|
|
|
|
def competence_report(df):
|
|
report_comp = pd.pivot_table(df,
|
|
index=["competence"],
|
|
columns = ['fullname'],
|
|
values = ["score"],
|
|
aggfunc = [rounded_mean])
|
|
return report_comp.dropna()
|
|
|
|
def exercise_gpby(df):
|
|
""" Group the dataframe in exercise POV """
|
|
pass
|
|
|
|
def eval_gpby(df):
|
|
""" Group the dataframe in eval POV """
|
|
pass
|
|
|
|
def term_gpby(df):
|
|
""" Group the dataframe in term POV """
|
|
pass
|
|
|
|
|
|
# -----------------------------
|
|
# Reglages pour 'vim'
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
# cursor: 16 del
|