Feat: remove relative imports and simplify get_unstack_scores

This commit is contained in:
Bertrand Benjamin 2021-04-18 17:20:54 +02:00
parent 2031ade1ab
commit 9e0ea14d05
2 changed files with 6 additions and 10 deletions

View File

@ -47,7 +47,7 @@ def update_scores_store(exam):
if not exam:
return [[], [], [], {}]
exam = pd.DataFrame.from_dict([json.loads(exam)])
scores = get_unstack_scores(exam, "score", "student_name")
scores = get_unstack_scores(exam)
fixed_columns = [
"exercise",
"question",

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python
# encoding: utf-8
from ....database.filesystem.loader import CSVLoader
from recopytex.database.filesystem.loader import CSVLoader
from recopytex.lib.dataframe import column_values_to_column
LOADER = CSVLoader("./test_config.yml")
@ -18,15 +19,10 @@ def get_record_scores(exam):
return LOADER.get_exam_scores(exam)
def get_unstack_scores(exam, value_column="score", unstack_column="student_name"):
def get_unstack_scores(exam):
flat_scores = LOADER.get_exam_scores(exam)
pivot_columns = [col for col in LOADER.score_columns if col != value_column]
unstacked_df = (
flat_scores.set_index(pivot_columns)[value_column]
.unstack(unstack_column)
.reset_index()
)
return unstacked_df
kept_columns = [col for col in LOADER.score_columns if col != "score"]
return column_values_to_column(flat_scores, "student_name", "score", kept_columns)
def get_students_from_exam(exam):