Append diff between empty and na.

Add warning if note > bareme
This commit is contained in:
Benjamin Bertrand 2017-03-23 19:16:22 +03:00
parent d0bc842a2a
commit 7446739301
2 changed files with 12 additions and 5 deletions

View File

@ -7,6 +7,9 @@ from math import ceil, floor
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
NOANSWER = "na"
NORATED = ""
# Values manipulations # Values manipulations
def round_half_point(val): def round_half_point(val):
@ -49,7 +52,7 @@ def note_to_rep(x):
'\\RepU' '\\RepU'
""" """
if x["Niveau"]: if x["Niveau"]:
if pd.isnull(x["Note"]): if x["Note"] == NOANSWER:
return latex_caract[0] return latex_caract[0]
elif x["Note"] in range(4): elif x["Note"] in range(4):
return latex_caract[int(x["Note"])+1] return latex_caract[int(x["Note"])+1]
@ -78,7 +81,12 @@ def note_to_mark(x):
""" """
if x["Niveau"]: if x["Niveau"]:
if x["Note"] == NOANSWER:
return 0
return x["Note"] * x["Bareme"] / 3 return x["Note"] * x["Bareme"] / 3
if x["Note"] > x["Bareme"]:
logger.warning(f"The note ({x['Note']}) is greated than the rating scale ({x['Bareme']}) at {x}")
return x["Note"] return x["Note"]
def note_to_level(x): def note_to_level(x):
@ -112,8 +120,7 @@ def note_to_level(x):
>>> note_to_level(df.loc[10]) >>> note_to_level(df.loc[10])
2 2
""" """
if x["Note"] == NOANSWER:
if pd.isnull(x["Note"]):
return "na" return "na"
if pd.isnull(x["Bareme"]) or x["Bareme"] == 0: if pd.isnull(x["Bareme"]) or x["Bareme"] == 0:
@ -468,8 +475,8 @@ def digest_flat_df(flat_df):
2 0 E1 N2 1 4.0 01/10/2016 3.0 0.75 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
""" """
# Remove data with "nn" (non notés) df = flat_df.dropna(subset=["Note"])
df = flat_df.copy()[flat_df["Note"].astype("object") != "nn"]
df["Mark"] = compute_marks(df) df["Mark"] = compute_marks(df)
df["Level"] = compute_level(df) df["Level"] = compute_level(df)
df["Latex_rep"] = compute_latex_rep(df) df["Latex_rep"] = compute_latex_rep(df)

Binary file not shown.