Feat: remove relative imports and simplify get_unstack_scores
This commit is contained in:
parent
2031ade1ab
commit
9e0ea14d05
@ -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",
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user