tests for notes_tools

This commit is contained in:
Benjamin Bertrand 2016-11-13 15:35:44 +03:00
parent ec469214da
commit 5e8c955867
9 changed files with 114 additions and 37 deletions

View File

@ -188,14 +188,15 @@ def compute_exo_marks(df):
>>> df["Mark"] = compute_marks(df) >>> df["Mark"] = compute_marks(df)
>>> compute_exo_marks(df) >>> compute_exo_marks(df)
Eleve Nom Exercice Date Trimestre Bareme Mark Question Niveau Eleve Nom Exercice Date Trimestre Bareme Mark Question Niveau
0 E1 N1 Ex1 16/09/2016 1 2 1.5 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 3.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 1.0 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 2.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 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 2.5 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 1.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 2.0 Total 0 7 E2 N2 Ex2 01/10/2016 1 2.0 2.0 Total 0
""" """
exo_pt = pd.pivot_table(df, exo_pt = pd.pivot_table(df,
@ -230,10 +231,10 @@ def compute_eval_marks(df):
>>> df_exo = compute_exo_marks(df) >>> df_exo = compute_exo_marks(df)
>>> compute_eval_marks(df_exo) >>> compute_eval_marks(df_exo)
Eleve Nom Date Trimestre Bareme Mark Exercice Niveau Eleve Nom Date Trimestre Bareme Mark Exercice Niveau
0 E1 N1 16/09/2016 1 6 5.0 Total 0 0 E1 N1 16/09/2016 1 6.0 5.0 Total 0
1 E1 N2 01/10/2016 1 4 3.0 Total 0 1 E1 N2 01/10/2016 1 4.0 3.0 Total 0
2 E2 N1 16/09/2016 1 6 4.5 Total 0 2 E2 N1 16/09/2016 1 6.0 4.5 Total 0
3 E2 N2 01/10/2016 1 4 3.5 Total 0 3 E2 N2 01/10/2016 1 4.0 3.5 Total 0
""" """
exo = df[df["Question"] == "Total"] exo = df[df["Question"] == "Total"]
@ -267,7 +268,7 @@ def digest_flat_df(flat_df):
df = flat_df.copy() df = flat_df.copy()
df["Mark"] = compute_marks(flat_df) df["Mark"] = compute_marks(flat_df)
df["Latex_rep"] = compute_latex_rep(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 = compute_exo_marks(df)
exo_df["Normalized"] = compute_normalized(exo_df) exo_df["Normalized"] = compute_normalized(exo_df)

View File

@ -16,12 +16,12 @@ def list_classes(path = notes_path):
List classes available in notes_path List classes available in notes_path
>>> list_classes() >>> list_classes()
['509', '503', '308', '312'] []
>>> p = Path("./") >>> p = Path("./samples/")
>>> list_classes(p) >>> list_classes(p)
['509', '503', '308', '312'] ['503', '312', '308']
>>> list_classes("./") >>> list_classes("./samples/")
['509', '503', '308', '312'] ['503', '312', '308']
""" """
try: try:
return [n.namebase for n in path.files("*.xlsx")] return [n.namebase for n in path.files("*.xlsx")]
@ -87,34 +87,32 @@ def flat_df_students(df, students):
flat_data.append(data) flat_data.append(data)
return pd.DataFrame.from_dict(flat_data) return pd.DataFrame.from_dict(flat_data)
def get_all_marks(ws, marks_sheetnames = ["Notes", "Connaissances", "Calcul mental"]): def parse_sheets(ws,
""" Extract marks from marks_sheetnames marks_sheetnames = ["Notes", "Connaissances", "Calcul mental"]):
""" Parse sheets from marks_sheetnames
:param ws: TODO :param ws: the worksheet
:returns: TODO :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 = [] sheets = []
for sheetname in marks_sheetnames: for sheetname in marks_sheetnames:
try: try:
sheets.append(ws.parse(sheetname)) sheets.append(ws.parse(sheetname))
except xlrd.biffh.XLRDError: except xlrd.biffh.XLRDError:
pass 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) students = check_students(sheets)

View File

@ -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

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
samples/README.md Normal file
View File

@ -0,0 +1,3 @@
# Notes on samples
- The file 308.xlxs should not work. The list of students between sheets is not homogeneous.