diff --git a/notes_tools/df_marks_manip.py b/notes_tools/df_marks_manip.py index 478bbb6..d472b59 100644 --- a/notes_tools/df_marks_manip.py +++ b/notes_tools/df_marks_manip.py @@ -188,14 +188,15 @@ def compute_exo_marks(df): >>> df["Mark"] = compute_marks(df) >>> compute_exo_marks(df) Eleve Nom Exercice Date Trimestre Bareme Mark Question Niveau - 0 E1 N1 Ex1 16/09/2016 1 2 1.5 Total 0 - 1 E1 N1 Ex2 16/09/2016 1 4 3.5 Total 0 - 2 E1 N2 Ex1 01/10/2016 1 2 1.0 Total 0 - 3 E1 N2 Ex2 01/10/2016 1 2 2.0 Total 0 - 4 E2 N1 Ex1 16/09/2016 1 2 2.0 Total 0 - 5 E2 N1 Ex2 16/09/2016 1 4 2.5 Total 0 - 6 E2 N2 Ex1 01/10/2016 1 2 1.5 Total 0 - 7 E2 N2 Ex2 01/10/2016 1 2 2.0 Total 0 + 0 E1 N1 Ex1 16/09/2016 1 2.0 1.5 Total 0 + 1 E1 N1 Ex2 16/09/2016 1 4.0 3.5 Total 0 + 2 E1 N2 Ex1 01/10/2016 1 2.0 1.0 Total 0 + 3 E1 N2 Ex2 01/10/2016 1 2.0 2.0 Total 0 + 4 E2 N1 Ex1 16/09/2016 1 2.0 2.0 Total 0 + 5 E2 N1 Ex2 16/09/2016 1 4.0 2.5 Total 0 + 6 E2 N2 Ex1 01/10/2016 1 2.0 1.5 Total 0 + 7 E2 N2 Ex2 01/10/2016 1 2.0 2.0 Total 0 + """ exo_pt = pd.pivot_table(df, @@ -230,10 +231,10 @@ def compute_eval_marks(df): >>> df_exo = compute_exo_marks(df) >>> compute_eval_marks(df_exo) Eleve Nom Date Trimestre Bareme Mark Exercice Niveau - 0 E1 N1 16/09/2016 1 6 5.0 Total 0 - 1 E1 N2 01/10/2016 1 4 3.0 Total 0 - 2 E2 N1 16/09/2016 1 6 4.5 Total 0 - 3 E2 N2 01/10/2016 1 4 3.5 Total 0 + 0 E1 N1 16/09/2016 1 6.0 5.0 Total 0 + 1 E1 N2 01/10/2016 1 4.0 3.0 Total 0 + 2 E2 N1 16/09/2016 1 6.0 4.5 Total 0 + 3 E2 N2 01/10/2016 1 4.0 3.5 Total 0 """ exo = df[df["Question"] == "Total"] @@ -267,7 +268,7 @@ def digest_flat_df(flat_df): df = flat_df.copy() df["Mark"] = compute_marks(flat_df) df["Latex_rep"] = compute_latex_rep(flat_df) - df["Normalized"] = compute_normalized(flat_df) + df["Normalized"] = compute_normalized(df) exo_df = compute_exo_marks(df) exo_df["Normalized"] = compute_normalized(exo_df) diff --git a/notes_tools/extract.py b/notes_tools/extract.py index 2d2864a..7621d14 100644 --- a/notes_tools/extract.py +++ b/notes_tools/extract.py @@ -16,12 +16,12 @@ def list_classes(path = notes_path): List classes available in notes_path >>> list_classes() - ['509', '503', '308', '312'] - >>> p = Path("./") + [] + >>> p = Path("./samples/") >>> list_classes(p) - ['509', '503', '308', '312'] - >>> list_classes("./") - ['509', '503', '308', '312'] + ['503', '312', '308'] + >>> list_classes("./samples/") + ['503', '312', '308'] """ try: return [n.namebase for n in path.files("*.xlsx")] @@ -87,34 +87,32 @@ def flat_df_students(df, students): flat_data.append(data) return pd.DataFrame.from_dict(flat_data) -def get_all_marks(ws, marks_sheetnames = ["Notes", "Connaissances", "Calcul mental"]): - """ Extract marks from marks_sheetnames +def parse_sheets(ws, + marks_sheetnames = ["Notes", "Connaissances", "Calcul mental"]): + """ Parse sheets from marks_sheetnames - :param ws: TODO - :returns: TODO + :param ws: the worksheet + :param marks_sheetnames: names of sheets for extracting """ - for sheetname in marks_sheetnames: - try: - marks = ws.parse(sheetname) - except xlrd.biffh.XLRDError: - pass - -def extract_flat_marks(ws): - """ Extract, flat and contact marks from the worksheet - - :param ws: TODO - :returns: TODO - - """ - marks_sheetnames = ["Notes", "Connaissances", "Calcul mental"] - sheets = [] for sheetname in marks_sheetnames: try: sheets.append(ws.parse(sheetname)) except xlrd.biffh.XLRDError: pass + return sheets + +def extract_flat_marks(ws, + marks_sheetnames=["Notes", "Connaissances", "Calcul mental"]): + """ Extract, flat and contact marks from the worksheet + + :param ws: the worksheet + :param marks_sheetnames: name of worksheets + :returns: TODO + + """ + sheets = parse_sheets(ws, marks_sheetnames) students = check_students(sheets) diff --git a/notes_tools/test/test_df_marks_manip.py b/notes_tools/test/test_df_marks_manip.py new file mode 100644 index 0000000..0b81053 --- /dev/null +++ b/notes_tools/test/test_df_marks_manip.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +from notes_tools import df_marks_manip + + +# TODO: faire des tests unitaire |mar. nov. 8 11:20:57 EAT 2016 + + + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/notes_tools/test/test_extract.py b/notes_tools/test/test_extract.py new file mode 100644 index 0000000..c2271c6 --- /dev/null +++ b/notes_tools/test/test_extract.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +from notes_tools import extract +import pandas +import pytest + + +sample_path = "./samples/" + +def test_list_classes(): + clss = extract.list_classes(sample_path) + assert clss == ["503", "312", "308"] + +def test_get_class_ws_raise(): + with pytest.raises(Exception) as e_info: + extract.get_class_ws("312") + +def test_parse_sheets(): + ws = extract.get_class_ws("312", sample_path) + sheets = extract.parse_sheets(ws) + assert len(sheets) == 2 + assert type(sheets[0]) == pandas.core.frame.DataFrame + +def test_extract_students(): + ws = extract.get_class_ws("312", sample_path) + sheets = extract.parse_sheets(ws) + students = extract.extract_students(sheets[0]) + _students = pandas.Index(['Eleve 1', 'Eleve 10', 'Eleve 2', 'Eleve 3', 'Eleve 4', 'Eleve 5', 'Eleve 6', 'Eleve 7', 'Eleve 8', 'Eleve 9'], dtype='object') + assert list(students) == list(_students) + +def test_check_students(): + ws = extract.get_class_ws("312", sample_path) + sheets = extract.parse_sheets(ws) + students = extract.check_students(sheets) + _students = pandas.Index(['Eleve 1', 'Eleve 10', 'Eleve 2', 'Eleve 3', 'Eleve 4', 'Eleve 5', 'Eleve 6', 'Eleve 7', 'Eleve 8', 'Eleve 9'], dtype='object') + assert list(students) == list(_students) + + + ws = extract.get_class_ws("308", sample_path) + sheets = extract.parse_sheets(ws) + with pytest.raises(Exception) as e_info: + students = extract.check_students(sheets) + +def test_flat_df_students(): + ws = extract.get_class_ws("312", sample_path) + sheets = extract.parse_sheets(ws) + students = extract.check_students(sheets) + + # Sheets[1] is the sheet Connaissances + flat_df = extract.flat_df_students(sheets[1], students) + assert len(flat_df) == 80 + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/samples/308.xlsx b/samples/308.xlsx index d0966af..e6ee259 100644 Binary files a/samples/308.xlsx and b/samples/308.xlsx differ diff --git a/samples/312.xlsx b/samples/312.xlsx index ce1de1c..c8af3e6 100644 Binary files a/samples/312.xlsx and b/samples/312.xlsx differ diff --git a/samples/503.xlsx b/samples/503.xlsx index c2beb84..95e86f8 100644 Binary files a/samples/503.xlsx and b/samples/503.xlsx differ diff --git a/samples/509.xlsx b/samples/509.xlsx deleted file mode 100644 index a84d78b..0000000 Binary files a/samples/509.xlsx and /dev/null differ diff --git a/samples/README.md b/samples/README.md new file mode 100644 index 0000000..f564e5e --- /dev/null +++ b/samples/README.md @@ -0,0 +1,3 @@ +# Notes on samples + +- The file 308.xlxs should not work. The list of students between sheets is not homogeneous.