def _add_event(self, event, row): self._event_sheet.write(row, 0, date_string(event.date)) self._event_sheet.write(row, 1, time_string(event.time)) self._event_sheet.write(row, 2, event.title) self._event_sheet.write(row, 3, event.notes) self._event_sheet.write(row, 4, event.description) for r in GlobalRoleList.roles: self._vacancies_sheets[r.description].write(row, 0, event.title + '(' + date_string(event.date) + ')') event_jobs = map(_job, event.appointments) for d in self._jobs: for i, j in enumerate(self._jobs[d]): try: index = event_jobs.index(j) appointment = event.appointments[index] if appointment.disabled: self._vacancies_sheets[j[0]].write(row, i + 1, "Disabled", styleDisabled) elif appointment.is_filled(): self._vacancies_sheets[j[0]].write(row, i + 1, appointment.person.name) else: self._vacancies_sheets[j[0]].write(row, i + 1, "") event_jobs[index] = None except ValueError: self._vacancies_sheets[j[0]].write(row, i + 1, "", styleInvalid)
def _refresh_events_children(self): self._events_Item.takeChildren() date = None date_item = None for event in sorted(self._events, key=lambda w: w.datetime): if not event.date == date: date = event.date date_item = self._add_child(self._events_Item, 0, date_string(date)) date_item.appointment = None event_item = self._add_child(date_item, 0, event.name) event_item.appointment = None appointment_list = event.appointments if self.vacanciesOnly: appointment_list = filter(is_vacant, appointment_list) for appointment in appointment_list: appointment.changed.connect(self._collectingObject.vacancy_changed) appointment_item = self._add_child(event_item, 0, str(appointment.role) + '(' + appointment.note + ')') appointment_item.appointment = appointment this_item = self._add_child(self._rolesItemsDict[appointment.role], 0, event.title + '(' + date_string( event.date) + ')' + '(' + appointment.note + ')') this_item.appointment = appointment
def MultitaskingPersonCheck(events, appointmentsWarningLimit): l = [] for e in events: c = Counter(map(person, e.appointments)) for p in c: if p and c[p] > appointmentsWarningLimit: error = CheckWarning('The person, ' + p.name + ' is scheduled for ' + str( c[p]) + ' appointments during the same event (' + e.name + date_string(e.date) + time_string( e.time) + ')') l.append(error) elif p and c[p] > 1: error = CheckInformation('The person, ' + p.name + ' is scheduled for ' + str( c[p]) + ' appointments during the same event (' + e.name + date_string(e.date) + time_string( e.time) + ')') l.append(error) return l
def event_title(event): title = "" title += date_string(event.date) title += " " title += time_string(event.time) title += " " title += event.title return title
def _html_header(self): title = 'Event ' title += date_string(self._event.date) title += ' ' title += time_string(self._event.time) title += ' ' title += self._event.title return HTMLObjects.HTMLHeading(title)
def _html_table_row_for_appointment(self, appointment): html = HTMLObjects.HTMLTableRow() html.add(HTMLObjects.HTMLTableCell(date_string(appointment.date))) time = time_string(appointment.time) event = str(appointment.event.title) html.add(HTMLObjects.HTMLTableCell(time)) html.add(HTMLObjects.HTMLTableCell(self._role_description(appointment))) html.add(HTMLObjects.HTMLTableCell(event)) return html
def _html_table_row_for_appointment(self, appointment): html = HTMLObjects.HTMLTableRow() html.add(HTMLObjects.HTMLTableCell(date_string(appointment.date))) time = time_string(appointment.time) event_link = HTMLObjects.HTMLLink(appointment.event.title, "../events/" + event_title(appointment.event) + ".html") html.add(HTMLObjects.HTMLTableCell(time)) html.add(HTMLObjects.HTMLTableCell(self._role_description(appointment))) html.add(HTMLObjects.HTMLTableCell(event_link)) return html
def headerData(self, section, orientation, role): if role == QtCore.Qt.DisplayRole: if orientation == QtCore.Qt.Horizontal: if len(self.people()) > 0: return self.people()[section].name elif orientation == QtCore.Qt.Vertical: if len(self.dates()) > 0: return date_string(self.dates()[section])
def _get_events_order(self): if self._event_sheet.nrows - 2 != len(self._duration.events): raise ExcellImportExportError('There are the wrong number of event entries on the events sheet') table_events = [] for i in range(2, self._event_sheet.nrows): if self._event_sheet.cell_type(i, 0) is 0: break else: e = {} e['date'] = self._event_sheet.cell_value(i, 0) e['time'] = self._event_sheet.cell_value(i, 1) e['title'] = self._event_sheet.cell_value(i, 2) e['notes'] = self._event_sheet.cell_value(i, 3) e['description'] = self._event_sheet.cell_value(i, 4) table_events.append(e) ordered_events = [None for _ in range(len(self._duration.events))] for event in self._duration.events: for i, e in enumerate(table_events): if e is not None: if e['title'] == event.title and e['notes'] == event.notes and e[ 'description'] == event.description: if e['date'] == date_string(event.date) and e['time'] == time_string(event.time): ordered_events[i] = event table_events[i] = None if None in ordered_events: raise ExcellImportExportError('Not all the events of the duration were incoprorated in the sheet') for e in table_events: if e is not None: raise ExcellImportExportError('Not all the events of the sheet were present in the duration') for s in self._vacancies_sheets: for i, e in enumerate(ordered_events): if self._vacancies_sheets[s].cell_value(i + 2, 0) != e.title + '(' + date_string(e.date) + ')': raise ExcellImportExportError('The sheet about ' + s + ' did not have the matching events') return ordered_events
def _html_table(self): table = HTMLObjects.HTMLTable() row = HTMLObjects.HTMLTableRow(HTMLObjects.HTMLTableHeaderCell()) for t in self._times(): row.add(HTMLObjects.HTMLTableHeaderCell(time_string(t))) table.add(row) for d in self._dates(): row = HTMLObjects.HTMLTableRow(HTMLObjects.HTMLTableHeaderCell(date_string(d))) for t in self._times(): correct_appointments = filter(lambda x: x.date == d and x.time == t, self._all_appointments) names = map(person_name, correct_appointments) if len(names) > 0: string = '<br>'.join(names) else: string = '' row.add(HTMLObjects.HTMLTableCell(string)) table.add(row) return table
def _add_individual(self, person, row): self._population_sheet.write(row, 0, person.name) self._population_sheet.write(row, 1, person.phone_number) self._population_sheet.write(row, 2, person.email) self._population_sheet.write(row, 3, person.address) self._qualifications_sheet.write(row, 0, person.name) self._dates_sheet.write(row, 0, person.name) j = 1 for r in GlobalRoleList.roles: if person.suitable_for_role(r): self._qualifications_sheet.write(row, j, "Y") j += 1 j = 1 for d in person.blacklisted_dates(): self._dates_sheet.write(row, j, date_string(d)) j += 1
def _html_table(self): table = HTMLObjects.HTMLTable() row = HTMLObjects.HTMLTableRow() row.add(HTMLObjects.HTMLTableHeaderCell("Date")) row.add(HTMLObjects.HTMLTableHeaderCell("Time")) row.add(HTMLObjects.HTMLTableHeaderCell("Event")) row.add(HTMLObjects.HTMLTableHeaderCell("People")) table.add(row) for e in sorted(self._events, key=lambda e: e.datetime()): correct_appointments = [a for a in self._all_appointments if e is a.event] if len(correct_appointments) > 0: link = HTMLObjects.HTMLLink(e.title, "../events/" + event_title(e) + ".html") row = HTMLObjects.HTMLTableRow(HTMLObjects.HTMLTableHeaderCell(date_string(e.date))) row.add(HTMLObjects.HTMLTableHeaderCell(time_string(e.time))) row.add(HTMLObjects.HTMLTableHeaderCell(link)) names = map(person_name, correct_appointments) if len(names) > 0: string = '<br>'.join(names) else: string = '' row.add(HTMLObjects.HTMLTableCell(string)) table.add(row) return table
def _refresh_events_children(self): li = [] self._collect_checked_items(self._events_Item, li) enabled = map(lambda i: i.reportable[0], li) self._events_Item.takeChildren() date = None date_item = None for event in sorted(self._events, key=lambda w: w.datetime): if not event.date == date: date = event.date date_item = self._add_child(self._events_Item, 0, date_string(date)) date_item.reportTupple = None item = self._add_child(date_item, 0, event.name) if event in enabled: checked = QtCore.Qt.Checked else: checked = QtCore.Qt.Unchecked item.setCheckState(0, checked) item.reportTupple = event, self._eventReporter
def IncompatibleMultitaskingPersonCheck(events): l = [] for e in events: a = list(e.appointments) b = list(e.appointments) for appointment in a: b.remove(appointment) for otherAppointment in b: if appointment.is_filled() and appointment.person == otherAppointment.person and not appointment.role.compatible_with( otherAppointment.role): error = CheckError( 'The person, ' + appointment.person.name + ' is scheduled for conflicting appointments during the same event (' + e.name + date_string( e.date) + time_string(e.time) + ')') l.append(error) return l
def _update(self): if self._appointment is None: self.descriptionBox.setText('No Appointment Selected') self.notesBox.setText('') self.checkBox.setChecked(True) else: self.descriptionBox.setText( str(self._appointment.role) + '(' + self._appointment.event.title + ')' + '(' + date_string( self._appointment.date) + ')') self.notesBox.setText(self._appointment.note) self.checkBox.setChecked(self._appointment.disabled) if self._appointment is None: self.personLine.setText('') self.vacateButton.setEnabled(False) elif self._appointment.disabled: self.personLine.setText('***Disabled***') self.vacateButton.setEnabled(False) elif self._appointment.is_filled(): self.personLine.setText(str(self._appointment.person)) self.vacateButton.setEnabled(True) else: self.personLine.setText('***Vacant***') self.vacateButton.setEnabled(False)
def BlacklistedDatePersonCheck(appointments): l = [] for a in appointments: if a.is_filled(): if not a.person.is_available_on_date(a.date): error = CheckError( 'The person, ' + a.person.name + ' is scheduled for ' + a.role.description + ' on ' + date_string( a.date) + ' but is not available on that date') l.append(error) return l
def UnqualifiedPersonCheck(appointments): l = [] for a in appointments: if a.is_filled(): if not a.person.suitable_for_role(a.role): error = CheckError( 'The person, ' + a.person.name + ' is scheduled for ' + a.role.description + ' on ' + date_string( a.date) + ' but is not qualified as a ' + a.role.description) l.append(error) return l
def UnfilledAppointmentCheck(events): l = [] for e in events: a = list(e.appointments) for appointment in a: if not appointment.is_filled() and not appointment.disabled: error = CheckError( 'The appointment, ' + appointment.role.description + ' is unfilled during the event (' + e.name + date_string( e.date) + time_string(e.time) + ')') l.append(error) return l
def MultipleProximalAppointmentsPersonCheck(appointments, population, permittedTimedelta): l = [] for p in population: pAppointments = filter(lambda a: a.person == person, appointments) remainingPAppointments = set(pAppointments) for appointment in pAppointments: remainingPAppointments.remove(appointment) proximalAppointments = filter(lambda a: abs(a.datetime - appointment.datetime) <= permittedTimedelta, remainingPAppointments) for app in proximalAppointments: warning = CheckWarning( 'The person, ' + p.name + ' has 2 oppointments within a short timescale (one of them is' + appointment.role + date_string( appointment.date) + time_string(appointment.time) + ') the other is (' + app.role + date_string( app.date) + time_string(app.time) + +') within ' + str(permittedTimedelta)) l.append(warning) return l