From 1d234ea5fc931d500cf06d66d16191e057b1a4a8 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 18 Apr 2021 11:42:13 +0200 Subject: [PATCH] Feat: add column description --- recopytex/database/filesystem/loader.py | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/recopytex/database/filesystem/loader.py b/recopytex/database/filesystem/loader.py index c402cc8..a48a83b 100644 --- a/recopytex/database/filesystem/loader.py +++ b/recopytex/database/filesystem/loader.py @@ -43,6 +43,18 @@ class CSVLoader(Loader): """ Get config """ return self._config + @property + def exam_columns(self): + return pd.Index(['name', 'date', 'term', 'origin', 'tribe', 'id']) + + @property + def question_columns(self): + return pd.Index(['exercise', 'question', 'competence', 'theme', 'comment', 'score_rate', 'is_leveled', 'origin', 'exam_id', 'id']) + + @property + def score_columns(self): + return pd.Index(['term', 'exam', 'date', 'exercise', 'question', 'competence', 'theme', 'comment', 'score_rate', 'is_leveled', 'origin', 'exam_id', 'question_id', 'student_name', 'score']) + def rename_columns(self, dataframe): """Rename dataframe column to match with `csv_fields` @@ -84,8 +96,8 @@ class CSVLoader(Loader): :example: >>> loader = CSVLoader("./test_config.yml") >>> exams = loader.get_exams(["Tribe1"]) - >>> exams.columns - Index(['name', 'date', 'term', 'origin', 'tribe', 'id'], dtype='object') + >>> all(exams.columns == loader.exam_columns) + True >>> exams name date term origin tribe id 0 DS 12/01/2021 1 example/Tribe1/210112_DS.csv Tribe1 DS_Tribe1 @@ -118,10 +130,7 @@ class CSVLoader(Loader): :example: >>> loader = CSVLoader("./test_config.yml") >>> exams = loader.get_exams(["Tribe1"]) - >>> loader.get_exam_questions([exams.iloc[0]]).columns - Index(['exercise', 'question', 'competence', 'theme', 'comment', 'score_rate', - 'is_leveled', 'origin', 'exam_id', 'id'], - dtype='object') + >>> all(loader.get_exam_questions([exams.iloc[0]]).columns == loader.score_columns) >>> questions = loader.get_exam_questions(exams) >>> questions.iloc[0] exercise Exercice 1 @@ -172,11 +181,8 @@ class CSVLoader(Loader): >>> exams = loader.get_exams(["Tribe1"]) >>> questions = loader.get_exam_questions(exams) >>> scores = loader.get_questions_scores(questions) - >>> scores.columns - Index(['term', 'exam', 'date', 'exercise', 'question', 'competence', 'theme', - 'comment', 'score_rate', 'is_leveled', 'origin', 'exam_id', - 'question_id', 'student_name', 'score'], - dtype='object') + >>> all(scores.columns == loader.score_columns) + True >>> scores["student_name"].unique() array(['Star Tice', 'Umberto Dingate', 'Starlin Crangle', 'Humbert Bourcq', 'Gabriella Handyside', 'Stewart Eaves',