From f438f4827f52cdb93e0ff315c281daf12ab9f602 Mon Sep 17 00:00:00 2001 From: fgoudreault Date: Wed, 21 Jun 2017 16:30:20 -0400 Subject: [PATCH] Added checkups for excel files completion and candidate/course initialization --- auxiclean/candidate.py | 14 +++++++++++--- auxiclean/course.py | 11 ++++++++--- auxiclean/managers/excel_manager.py | 22 ++++++++++++++++------ auxiclean/managers/sheet_managers.py | 2 +- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/auxiclean/candidate.py b/auxiclean/candidate.py index e40d226..7ea4123 100644 --- a/auxiclean/candidate.py +++ b/auxiclean/candidate.py @@ -17,9 +17,9 @@ def __init__(self, name, self.disponibilities = int(disponibilities) self.courses_given = courses_given self.scolarity = int(scolarity) - self.nobels = int(nobels) - self.discipline = discipline - self.gpa = float(gpa) + self.nobels = int(nobels) if nobels is not None else 0 + self.discipline = discipline if discipline is not None else "générale" + self.gpa = float(gpa) if gpa is not None else None def __repr__(self): # pragma: no cover return self.name @@ -55,14 +55,22 @@ def __lt__(self, candidate2): for attribute in PRIORITIES: attr1 = getattr(self, attribute) attr2 = getattr(candidate2, attribute) + print(attribute) + if attr1 is None or attr2 is None: + # don't compare if something is missing + print("continue") + continue if attr1 < attr2: # lesser + print("lesser") return True if attr1 > attr2: # greater + print("greater") return False # if we are here, attributes are equal, continue in the priorities # if we are here, candidates are perfectly equals + print("final") return False def __eq__(self, candidate2): diff --git a/auxiclean/course.py b/auxiclean/course.py index 0293963..182443b 100644 --- a/auxiclean/course.py +++ b/auxiclean/course.py @@ -1,7 +1,12 @@ class Course: def __init__(self, name, code, positions, discipline): - self.name = name - self.code = code.zfill(2) + self.code = code + if self.code is None: + raise ValueError("Course has no code!") + self.name = name if name is not None else self.code self.positions = int(positions) - self.discipline = discipline + self.discipline = discipline if discipline is not None else "générale" self.candidates = [] + + def __repr__(self): # pragma: no cover + return self.name diff --git a/auxiclean/managers/excel_manager.py b/auxiclean/managers/excel_manager.py index 7868e03..226d1b4 100644 --- a/auxiclean/managers/excel_manager.py +++ b/auxiclean/managers/excel_manager.py @@ -7,20 +7,17 @@ class ExcelFileManager: def __init__(self, path): self.path = path self.wb = load_workbook(path) - self._courses = None - self._candidates = None + self._courses = CoursesSheetManager(self.wb) + self._candidates = CandidatesSheetManager(self.wb) + self._checkup() self._distribution = None @property def courses(self): - if self._courses is None: - self._courses = CoursesSheetManager(self.wb) return self._courses.courses @property def candidates(self): - if self._candidates is None: - self._candidates = CandidatesSheetManager(self.wb) return self._candidates.candidates def write_distribution(self, distribution): @@ -31,3 +28,16 @@ def write_distribution(self, distribution): def save(self): self.wb.save(self.path) + + def _checkup(self): + for candidate in self.candidates: + for choice in candidate.choices: + if not self._choice_in_courses(choice): + raise ValueError(" Choice %s of %s not in courses list." % + (choice, candidate)) + + def _choice_in_courses(self, choice): + for course in self.courses: + if course.code == choice: + return True + return False diff --git a/auxiclean/managers/sheet_managers.py b/auxiclean/managers/sheet_managers.py index fb97311..d6ce5ff 100644 --- a/auxiclean/managers/sheet_managers.py +++ b/auxiclean/managers/sheet_managers.py @@ -39,7 +39,7 @@ def load_courses_from_wb(self, wb): for label, cell in zip(titles, course)} courses.append(d) return [Course(x["titre du cours"], - x["sigle"].strip("PHY"), + x["sigle"], x["nombre de postes"], x["discipline"]) for x in courses]