def test_all(self): # Returns no events, if DB is blank self.assertEqual([], list(event.name for event in Event.all())) # Returns all events from DB Event.create(name='archived', take_place_at=datetime.utcnow() - timedelta(days=1)) Event.create(name='upcoming', take_place_at=datetime.utcnow() + timedelta(days=10)) self.assertEqual(['archived', 'upcoming'], list(event.name for event in Event.all()))
def get(self): events = Event.all() path = os.path.join(os.path.dirname(__file__), 'templates/administration/event-list.html') template_values = { 'events': events } self.response.out.write(template.render(path, template_values))
def get(self): path = os.path.join(os.path.dirname(__file__), 'templates/requests.html') template_values = { 'event': Event.all().filter('event_name', 'paasrapport').fetch(1), 'guardians': Guardian.all().fetch(9999) } self.response.out.write(template.render(path, template_values))
def lis(self, user): all_events = Event.all() result = all_events.fetch(20) # self.response.write(result.list_index()) context = [] for r in all_events: context.append({'name':r.name, 'venue': r.venue,'id': r.key().id()}) self.render_api_response(context)
def get(self): events = Event.all().fetch(100) path = os.path.join(os.path.dirname(__file__), 'templates/listregistrations.html') template_values = { 'events': events } self.response.out.write(template.render(path, template_values))
def get(self, arg): event = Event.get_by_id(int(arg)) notifications = [] events = Event.all() path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-list.html') template_values = { 'notifications': notifications, 'events': events, 'logoutlink': users.create_logout_url("/") } if not event: notifications.append('Het event bestaat niet.') self.response.out.write(template.render(path, template_values)) return self.createGuardianPasses(event) notifications.append('De sleutels zijn aangemaakt') self.response.out.write(template.render(path, template_values)) return
def api_list(self, user): events = Event.all() context = [] for event in events: context.append({'name':event.name, 'id': event.key().id(), 'venue': event.venue }) self.render_api_response(context)
def myevents(self): my_events = Event.all().filter('profile =', self.get_current_profile()) context = {'events': my_events} self.render_template('event_list.html', context)
def list(self): all_events = Event.all() context = {'events': all_events} self.render_template('event_list.html', context)
def get(self): print "" print "<html><body style='font-family: Helvetica; font-size: 0.9em;'>" print time.strftime("%H:%M:%S", time.localtime()) + ": Start<br>" logging.info("Fetching all info") # if arg != None: # event = Event.get_by_id(int(arg)) # else: event = Event.all().filter("event_name", "paasrapport").get() days = Day.all().filter("event", event).fetch(999) days.sort(key=lambda day: day.date) max_requests = 0 max_timepref = 0 max_rank = 0 allguardians = Guardian.all().fetch(9999) guardians = [] requests = [] for guardian in allguardians: requests = Request.all().filter("guardian", guardian).filter("event", event).fetch(999) if len(requests) > 0: max_requests = max([max_requests, len(requests)]) guardian.requests = requests guardian.day_prefs = [] for day in days: guardian.day_prefs.append(DayPreference.all().filter("guardian", guardian).filter("day", day).get()) guardian.day_prefs.sort(key=lambda day: day.rank) max_rank = max([max_rank, max([day.rank for day in guardian.day_prefs])]) guardian.time_pref = TimePreference.all().filter("guardian", guardian).filter("event", event).get() max_timepref = max([max_timepref, guardian.time_pref.preference]) if len(requests) > 5: guardianCopy = copy.deepcopy(guardian) guardian.requests = guardian.requests[: int(len(requests) / 2)] guardianCopy.requests = guardianCopy.requests[int(len(requests) / 2) :] guardianCopy.day_prefs[0].rank = 999 guardians.append(guardianCopy) guardians.append(guardian) timepref_options = range(max_timepref + 1) timepref_options = [1, 2, 0] planning = Planning(event, days) logging.info("All guardians/requests collected") for length in range(max_requests, 0, -1): for timepref in timepref_options: for rank in range(0, max_rank + 1): for day_num, day in enumerate(days): for guardian in filter( lambda guardian: (len(guardian.requests) == length) and (guardian.time_pref.preference == timepref) and ( filter(lambda day_pref: day_pref.day.date == day.date, guardian.day_prefs)[0].rank == rank ), guardians, ): # try to place these requests placed = planning.place(guardian, day_num) # on succes, remove guardian from guardian # on fail, the guardian will return on a less preferable round if placed: guardians.remove(guardian) logging.info("Placed") for dayIndex, day in enumerate(planning.days): start = time.clock() lowestValue = 0 for i, slot in enumerate(day[0]): lowestValue += len(planning.conflictedTeachers(day, i)) logging.info("conflicts: " + str(lowestValue)) # <--- Build a list of all regions logging.info("Building regions") regions = [] for tableIndex, table in enumerate(day): region = [tableIndex, 0, -1] previousGuardian = "" for slotIndex, slot in enumerate(table): guardianId = planning.getGuardianIdFromRequest(slot) block = table[region[1] : region[2] + 1] if guardianId == "": if len(block) == 0: region = [tableIndex, slotIndex, slotIndex] elif block.count(None) == 0: if previousGuardian != "": region[2] = slotIndex regions.append(region) region = [tableIndex, 0, -1] elif block.count(None) > 0: if len(block) > block.count(None): regions.append(region) region = [tableIndex, slotIndex, slotIndex] previousGuardian = "" else: if guardianId != previousGuardian and previousGuardian != "": regions.append(region) region = [tableIndex, slotIndex, slotIndex] region[2] = slotIndex previousGuardian = guardianId block = table[region[1] : region[2] + 1] if len(block) > block.count(None) > 0: regions.append(region) logging.info("Regions built") permutationSets = {} preconflicts = 0 pre_max_conflicts = 0 for i, slot in enumerate(day[0]): slotConflicts = len(planning.conflictedTeachers(day, i)) pre_max_conflicts = max([pre_max_conflicts, slotConflicts]) preconflicts += slotConflicts logging.info("Starting conflicts: " + str(preconflicts)) logging.info("Starting max slotconflicts: " + str(pre_max_conflicts)) for set in regions: block = day[set[0]][set[1] : set[2] + 1] block.sort(key=lambda x: planning.getTeacherStringFromRequest(x)) day[set[0]][set[1] : (set[2] + 1)] = block sortedconflicts = 0 sorted_max_conflicts = 0 for i, slot in enumerate(day[0]): slotConflicts = len(planning.conflictedTeachers(day, i)) sorted_max_conflicts = max([sorted_max_conflicts, slotConflicts]) sortedconflicts += slotConflicts logging.info("Conflicts after sorting: " + str(sortedconflicts)) logging.info("Max slotconflicts after sorting: " + str(sorted_max_conflicts)) conflicts = 9999 max_conflicts = 9999 while ( conflicts >= preconflicts and conflicts >= sortedconflicts and max_conflicts >= pre_max_conflicts and max_conflicts >= sorted_max_conflicts ): for set in regions: block = day[set[0]][set[1] : set[2] + 1] random.shuffle(block) day[set[0]][set[1] : (set[2] + 1)] = block conflicts = 0 max_conflicts = 0 for i, slot in enumerate(day[0]): slotConflicts = len(planning.conflictedTeachers(day, i)) max_conflicts = max([max_conflicts, slotConflicts]) conflicts += slotConflicts logging.info("Conflicts after shuffling: " + str(conflicts)) logging.info("Max slotconflicts after shuffling: " + str(max_conflicts)) # <--- Cycle through conflicted regions loop = 0 while lowestValue > 0: logging.info("Dropping non-conflicted regions") conflictedRegions = [ region for region in regions if planning.numberOfConflictsPerRegion(day, region) > 0 and (region[2] - region[1]) < 7 ] logging.info("Sorting regions to start with smallest region with highest number of conflicts") conflictedRegions.sort( key=lambda set: (set[2] - set[1], -planning.numberOfConflictsPerRegion(day, set)) ) logging.info(str(conflictedRegions)) loop += 2 if loop > len(conflictedRegions): loop = len(conflictedRegions) for set in conflictedRegions[:loop]: logging.info("Working on set: " + str(set)) logging.info("Set size: " + str(set[2] - set[1] + 1)) # logging.info("Number of conflicts in region: "+str(planning.numberOfConflictsPerRegion(day, set))) if planning.numberOfConflictsPerRegion(day, set) <= 0: logging.info("Already fixed; moving on...") continue if not tuple(set) in permutationSets: # logging.info("This set is new to the dictionary") block = day[set[0]][set[1] : set[2] + 1] permutations = itertools.permutations(block) permutations = list(permutations) permutationSets[tuple(set)] = permutations else: # logging.info("This set was already in the dictionary") permutations = permutationSets[tuple(set)] conflictCounter = [] for permIndex, perm in enumerate(permutations): block = day[set[0]][set[1] : (set[2] + 1)] day[set[0]][set[1] : (set[2] + 1)] = perm conflicts = 0 for i, slot in enumerate(day[0]): conflicts += len(planning.conflictedTeachers(day, i)) conflictCounter.append(conflicts) lowestValue = min(conflictCounter) bestOptions = [enum for enum, x in enumerate(conflictCounter) if x == lowestValue] bestOption = random.choice(bestOptions) newList = permutations[bestOption] day[set[0]][set[1] : set[2] + 1] = newList logging.info("Total conflicts: " + str(lowestValue)) if lowestValue == 0: break if lowestValue == 0: break if time.clock() - start > 600: break planning.outputHTML() for dayIndex, day in enumerate(planning.days): for tableIndex, table in enumerate(day): for slotIndex, slot in enumerate(table): if slot != None: new_appointment = Appointment( request=slot, day=days[dayIndex], table=tableIndex, slot=slotIndex ) new_appointment.put()
def get(self, arg): event = Event.get_by_id(int(arg)) notifications = [] if not event: notifications.append("De bewerking kon niet worden voltooid omdat het event niet bestaat.") events = Event.all() path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-list.html') template_values = {'events': events, 'logoutlink': users.create_logout_url("/") , 'notifications': notifications } self.response.out.write(template.render(path, template_values)) return requests = event.requests.fetch(9999) guardians_keys = [] for request in requests: if request.guardian.key().name() not in guardians_keys: guardians_keys.append(request.guardian.key().name()) if not guardians_keys: notifications.append("Er zijn geen voogden met verzoeken") events = Event.all() path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-list.html') template_values = {'events': events, 'logoutlink': users.create_logout_url("/") , 'notifications': notifications } self.response.out.write(template.render(path, template_values)) return for guardian_num, guardian_key in enumerate(guardians_keys): guardian = Guardian.get_by_key_name(guardian_key) guardian_requests = Request.gql("WHERE guardian = :1 AND event = :2", guardian, event).fetch(999) guardian_appointments = [guardian_request.appointment.get() for guardian_request in guardian_requests if guardian_request.appointment.get()] day_ids = [appointment.day.key().id() for appointment in guardian_appointments if appointment] day_ids = list(set(day_ids)) if not guardian_appointments: continue mail = Email() message = 'Beste ' + guardian.title if not guardian.preposition == '': message += ' ' + guardian.preposition message += ' ' + guardian.lastname + ',\n\n' message += 'Er zijn afspraken ingepland voor de ouderavond(en) van het ' + event.event_name + ". " message += 'Hieronder vind u de afspraken die voor u zijn gemaakt:\n\n' for day_id in day_ids: day = Day.get_by_id(day_id) message += 'Op ' + str(day.date.day) + ' ' + AdministrationInviteGuardiansHandler.getMonthText(self, day.date.month) + ' ' + str(day.date.year) + ':\n' for appointment in guardian_appointments: if appointment.day.key().id() == day_id: student = appointment.request.student m = event.talk_time * appointment.slot d = timedelta(minutes=m) time = day.date + d message += 'Tijd: ' + str(time.hour) + ':' + str(time.minute) + '\n' message += 'Tafel: ' + str(appointment.table) + '\n' message += 'Leerling: ' + student.firstname + ' ' + student.preposition + ' ' + student.lastname + '\n' message += 'Vak: ' + appointment.request.combination.subject.name + '\n' message += 'Docent: ' + appointment.request.combination.teacher.name + '\n' message += 'Docentcode: ' + appointment.request.combination.teacher.key().name() + '\n\n' # mail.sendMail(guardian.email, 'Afspraken ouderavond(en) ' + event.event_name, message) if guardian_num == 0: print message return
def get(self): events = Event.all() path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-list.html') template_values = {'events': events, 'logoutlink': users.create_logout_url("/") } self.response.out.write(template.render(path, template_values))