diff --git a/notes_tools/tools/df_marks_manip.py b/notes_tools/tools/df_marks_manip.py index 95bbaba..60b7538 100644 --- a/notes_tools/tools/df_marks_manip.py +++ b/notes_tools/tools/df_marks_manip.py @@ -294,9 +294,6 @@ def compute_eval_marks(df): 3 E2 N2 1 4.0 01/10/2016 3.5 Total 0 """ - #exo = df[df["Question"] == "Total"] - #eval_pt = pd.pivot_table(exo, - def date_format(dates): date_l = list(dates.unique()) if len(date_l) == 1: @@ -304,16 +301,25 @@ def compute_eval_marks(df): else: return "Trimestre" - eval_pt = pd.pivot_table(df, - #index = [ "Eleve", "Nom", "Date", "Trimestre"], - index = [ "Eleve", "Nom", "Trimestre"], - values = ["Bareme", "Mark", "Date"], - aggfunc={"Bareme": np.sum, "Mark": np.sum, "Date": date_format}, - ).applymap(round_half_point) + eval_m = pd.DataFrame() + for eval_name in df["Nom"].unique(): + eval_df = df[df["Nom"] == eval_name] + dates = eval_df["Date"].unique() + if len(dates) > 1: + # Les devoirs sur la durée, les NaN ne sont pas pénalisants + # On les enlèves + eval_df = eval_df.dropna(subset=["Mark"]) + dates = ["Trimestre"] + + eval_pt = pd.pivot_table(eval_df, + index = [ "Eleve", "Nom", "Trimestre"], + values = ["Bareme", "Mark", "Normalized", "Date"], + aggfunc={"Bareme": np.sum, "Mark": np.sum,"Normalized":np.mean, "Date":lambda x:dates[0]}, + ) + eval_pt = eval_pt.reset_index() + eval_m = pd.concat([eval_m, eval_pt]) + - eval_m = eval_pt.reset_index() - eval_m["Exercice"] = "Total" - eval_m["Niveau"] = 0 return eval_m def digest_flat_df(flat_df): diff --git a/samples/312.xlsx b/samples/312.xlsx index 7a8bcb2..7f825bc 100644 Binary files a/samples/312.xlsx and b/samples/312.xlsx differ diff --git a/samples/503.xlsx b/samples/503.xlsx index 95e86f8..4deb7b4 100644 Binary files a/samples/503.xlsx and b/samples/503.xlsx differ