Skip to content

Commit

Permalink
Added checkups for excel files completion and candidate/course initia…
Browse files Browse the repository at this point in the history
…lization
  • Loading branch information
fgoudreault committed Jun 22, 2017
1 parent 97a76fe commit f438f48
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
14 changes: 11 additions & 3 deletions auxiclean/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 8 additions & 3 deletions auxiclean/course.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 16 additions & 6 deletions auxiclean/managers/excel_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
2 changes: 1 addition & 1 deletion auxiclean/managers/sheet_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit f438f48

Please sign in to comment.