pass doctests

This commit is contained in:
Benjamin Bertrand 2017-01-27 17:52:58 +03:00
parent 603e6cab84
commit a761770510
2 changed files with 51 additions and 50 deletions

View File

@ -29,7 +29,7 @@ def note_to_rep(x):
... "Trimestre": ["1"]*12, ... "Trimestre": ["1"]*12,
... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2, ... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2,
... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2, ... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2,
... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.666, 1, 1.5, 1, 2, 3], ... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.67, 1, 1.5, 1, 2, 3],
... } ... }
>>> df = pd.DataFrame(d) >>> df = pd.DataFrame(d)
>>> note_to_rep(df.loc[0]) >>> note_to_rep(df.loc[0])
@ -136,18 +136,18 @@ def compute_marks(df):
... } ... }
>>> df = pd.DataFrame(d) >>> df = pd.DataFrame(d)
>>> compute_marks(df) >>> compute_marks(df)
0 1.000000 0 1.00
1 0.330000 1 0.33
2 2.000000 2 2.00
3 1.500000 3 1.50
4 0.666667 4 0.67
5 2.000000 5 2.00
6 0.666000 6 0.67
7 1.000000 7 1.00
8 1.500000 8 1.50
9 1.000000 9 1.00
10 1.333333 10 1.33
11 2.000000 11 2.00
dtype: float64 dtype: float64
""" """
return df[["Note", "Niveau", "Bareme"]].apply(note_to_mark, axis=1) return df[["Note", "Niveau", "Bareme"]].apply(note_to_mark, axis=1)
@ -175,7 +175,7 @@ def compute_latex_rep(df):
3 1.5 3 1.5
4 \RepU 4 \RepU
5 \RepT 5 \RepT
6 0.666 6 0.67
7 1 7 1
8 1.5 8 1.5
9 1 9 1
@ -203,18 +203,18 @@ def compute_normalized(df):
>>> df = pd.DataFrame(d) >>> df = pd.DataFrame(d)
>>> df["Mark"] = compute_marks(df) >>> df["Mark"] = compute_marks(df)
>>> compute_normalized(df) >>> compute_normalized(df)
0 1.000000 0 1.00
1 0.330000 1 0.33
2 1.000000 2 1.00
3 0.750000 3 0.75
4 0.333333 4 0.33
5 1.000000 5 1.00
6 0.666000 6 0.67
7 1.000000 7 1.00
8 0.750000 8 0.75
9 0.500000 9 0.50
10 0.666667 10 0.67
11 1.000000 11 1.00
dtype: float64 dtype: float64
""" """
return df["Mark"] / df["Bareme"] return df["Mark"] / df["Bareme"]
@ -239,7 +239,7 @@ def compute_exo_marks(df):
... "Trimestre": ["1"]*12, ... "Trimestre": ["1"]*12,
... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2, ... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2,
... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2, ... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2,
... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.666, 1, 1.5, 1, 2, 3], ... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.67, 1, 1.5, 1, 2, 3],
... } ... }
>>> df = pd.DataFrame(d) >>> df = pd.DataFrame(d)
>>> df["Mark"] = compute_marks(df) >>> df["Mark"] = compute_marks(df)
@ -281,7 +281,7 @@ def compute_eval_marks(df):
... "Trimestre": ["1"]*12, ... "Trimestre": ["1"]*12,
... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2, ... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2,
... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2, ... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2,
... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.666, 1, 1.5, 1, 2, 3], ... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.67, 1, 1.5, 1, 2, 3],
... } ... }
>>> df = pd.DataFrame(d) >>> df = pd.DataFrame(d)
>>> df["Mark"] = compute_marks(df) >>> df["Mark"] = compute_marks(df)
@ -341,34 +341,34 @@ def digest_flat_df(flat_df):
>>> df = pd.DataFrame(d) >>> df = pd.DataFrame(d)
>>> quest_df, exo_df, eval_df = digest_flat_df(df) >>> quest_df, exo_df, eval_df = digest_flat_df(df)
>>> quest_df[['Eleve', "Nom", "Mark", "Latex_rep", "Normalized", "Uniq_quest"]] >>> quest_df[['Eleve', "Nom", "Mark", "Latex_rep", "Normalized", "Uniq_quest"]]
Eleve Nom Mark Latex_rep Normalized Uniq_quest Eleve Nom Mark Latex_rep Normalized Uniq_quest
0 E1 N1 1.000000 1 1.000000 Ex1 Q1 0 E1 N1 1.00 1 1.00 Ex1 Q1
1 E1 N1 0.330000 0.33 0.330000 Ex1 Q2 1 E1 N1 0.33 0.33 0.33 Ex1 Q2
2 E1 N1 2.000000 2 1.000000 Ex2 Q1 2 E1 N1 2.00 2 1.00 Ex2 Q1
3 E1 N1 1.500000 1.5 0.750000 Ex2 Q2 3 E1 N1 1.50 1.5 0.75 Ex2 Q2
4 E1 N2 0.666667 \RepU 0.333333 Ex1 Q1 4 E1 N2 0.67 \RepU 0.33 Ex1 Q1
5 E1 N2 2.000000 \RepT 1.000000 Ex2 Q1 5 E1 N2 2.00 \RepT 1.00 Ex2 Q1
6 E2 N1 NaN ?? NaN Ex1 Q1 6 E2 N1 NaN ?? NaN Ex1 Q1
7 E2 N1 0.000000 0 0.000000 Ex1 Q2 7 E2 N1 0.00 0 0.00 Ex1 Q2
8 E2 N1 0.000000 0 0.000000 Ex2 Q1 8 E2 N1 0.00 0 0.00 Ex2 Q1
9 E2 N1 NaN ?? NaN Ex2 Q2 9 E2 N1 NaN ?? NaN Ex2 Q2
10 E2 N2 NaN \NoRep NaN Ex1 Q1 10 E2 N2 NaN \NoRep NaN Ex1 Q1
11 E2 N2 NaN \NoRep NaN Ex2 Q1 11 E2 N2 NaN \NoRep NaN Ex2 Q1
>>> exo_df[['Eleve', "Nom", "Exercice", "Mark", "Normalized"]] >>> exo_df[['Eleve', "Nom", "Exercice", "Mark", "Normalized"]]
Eleve Nom Exercice Mark Normalized Eleve Nom Exercice Mark Normalized
0 E1 N1 Ex1 1.5 0.750 0 E1 N1 Ex1 1.5 0.75
1 E1 N1 Ex2 3.5 0.875 1 E1 N1 Ex2 3.5 0.88
2 E1 N2 Ex1 1.0 0.500 2 E1 N2 Ex1 1.0 0.50
3 E1 N2 Ex2 2.0 1.000 3 E1 N2 Ex2 2.0 1.00
4 E2 N1 Ex1 0.0 0.000 4 E2 N1 Ex1 0.0 0.00
5 E2 N1 Ex2 0.0 0.000 5 E2 N1 Ex2 0.0 0.00
6 E2 N2 Ex1 NaN NaN 6 E2 N2 Ex1 NaN NaN
7 E2 N2 Ex2 NaN NaN 7 E2 N2 Ex2 NaN NaN
>>> eval_df >>> eval_df
index Eleve Nom Trimestre Bareme Date Mark Normalized index Eleve Nom Trimestre Bareme Date Mark Normalized
0 0 E1 N1 1 6.0 16/09/2016 5.0 0.833333 0 0 E1 N1 1 6.0 16/09/2016 5.0 0.83
1 1 E2 N1 1 6.0 16/09/2016 0.0 0.000000 1 1 E2 N1 1 6.0 16/09/2016 0.0 0.00
2 0 E1 N2 1 4.0 01/10/2016 3.0 0.750000 2 0 E1 N2 1 4.0 01/10/2016 3.0 0.75
3 1 E2 N2 1 4.0 01/10/2016 NaN NaN 3 1 E2 N2 1 4.0 01/10/2016 NaN NaN
""" """
df = flat_df.copy() df = flat_df.copy()

View File

@ -50,6 +50,7 @@ def keep_only_presents(quest_df, exo_df, eval_df, presents):
def students_pov(quest_df, exo_df, eval_df): def students_pov(quest_df, exo_df, eval_df):
""" """
>>> from .df_marks_manip import digest_flat_df
>>> d = {"Eleve":["E1"]*6 + ["E2"]*6, >>> d = {"Eleve":["E1"]*6 + ["E2"]*6,
... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2, ... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2,
... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"], ... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"],