Exemple #1
0
 def getStudentsSubjects(self, students):
     students_subjects = []
     for student in students:
         class_id = student.class_id 
         combinations = Combination.gql("WHERE class_id = :1", class_id).fetch(10, 0)
         subjects = []
         for combination in combinations:
             subjects.append(combination.subject)
         students_subjects.append([student, subjects])
     return students_subjects
Exemple #2
0
def create_model(type,
                 first_layer_channels=10,
                 second_layer_channels=10,
                 third_layer_channels=configurations.num_of_filters,
                 num_of_heads=1,
                 cnnConfig="DBBNNN",
                 rnnType="lstm",
                 bi=False,
                 rnnConfig="N",
                 middleLayers=1,
                 dropout=.1,
                 sa_dropout=0.1,
                 usePosition=False,
                 order="rnn",
                 attention=False):
    pseudo_random(configurations.random_seed)
    if type == "rnn":
        mid_layer = myRNN(rnnType,
                          third_layer_channels,
                          bi,
                          rnnConfig,
                          layers=middleLayers)
    elif type == "sa":
        mid_layer = Self_attention(third_layer_channels,
                                   num_of_heads=num_of_heads,
                                   dropOut=sa_dropout,
                                   layers=middleLayers,
                                   usePosition=usePosition)
    elif type == "both":
        mid_layer = Combination(third_layer_channels,
                                num_of_heads=num_of_heads,
                                dropOut=dropout,
                                layers=middleLayers,
                                usePosition=usePosition,
                                bi=bi,
                                configuration=rnnConfig,
                                rnnType=rnnType,
                                order=order)
    model = KiNET(mid_layer,
                  first_layer_channels=first_layer_channels,
                  second_layer_channels=second_layer_channels,
                  third_layer_channels=third_layer_channels,
                  cnnConfig=cnnConfig,
                  attention=attention,
                  dropout=dropout)
    return model
Exemple #3
0
    def get(self):
        
        # Load all Guardians
        path = os.path.join(os.path.dirname(__file__), 'data/voogdouder.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_guardian = Guardian(key_name=row[0].strip())
            new_guardian.title=row[1].strip()
            new_guardian.initials=row[2].strip()
            new_guardian.preposition=row[3].strip()
            new_guardian.lastname=row[4].strip()
            new_guardian.streetname=row[6].strip()
            new_guardian.housenumber=row[7].strip()
            new_guardian.city=row[8].strip()
            new_guardian.postalcode=row[9].strip()
            new_guardian.email=row[12].strip()
            new_guardian.save()
            print "Guardian " + new_guardian.key().id_or_name() + " stored"

        # Load all Students
        path = os.path.join(os.path.dirname(__file__), 'data/leerlingen.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_student = Student(key_name=row[0].strip())
            new_student.firstname=row[1].strip()
            new_student.preposition=row[2].strip()
            new_student.lastname=row[3].strip()
            new_student.gender=row[4].strip()
            new_student.class_id=row[5].strip()
            new_student.guardian=Guardian.all().filter("__key__ >=", Key.from_path('Guardian', row[6].strip())).get()
            new_student.save()
            print "Student " + new_student.key().id_or_name() + " stored"
            
        # Load all Teachers
        path = os.path.join(os.path.dirname(__file__), 'data/docenten.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader:
            new_teacher = Teacher(key_name=row[0].strip())
            new_teacher.name=row[1].strip()
            new_teacher.boxnumber=int(row[2].strip())
            new_teacher.email=row[3].strip()
            new_teacher.save()
            print "Teacher " + new_teacher.key().id_or_name() + " stored"
            
        # Load all Subjects
        path = os.path.join(os.path.dirname(__file__), 'data/vakken.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader:
            new_subject = Subject(key_name=row[0].strip())
            new_subject.name=row[1].strip()
            new_subject.save()
            print "Subject " + new_subject.key().id_or_name() + " stored"

        # Load all Students
        path = os.path.join(os.path.dirname(__file__), 'data/docent_vak.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_combination = Combination()
            new_combination.class_id=row[0].strip()
            new_combination.subject=Subject.all().filter("__key__ >=", Key.from_path('Subject', row[1].strip())).get()
            new_combination.teacher=Teacher.all().filter("__key__ >=", Key.from_path('Teacher', row[2].strip())).get()
            new_combination.save()
            print "Combination " + str(new_combination.key().id_or_name()) + " stored"
        self.redirect("/fix")
Exemple #4
0
        for guardian in guardians:
            time = TimePreference()
            time.event = event
            time.guardian = guardian
            time.preference = random.randint(0, 2)
            time.save()
            days = event.days.fetch(999)
            random.shuffle(days)
            for i, day in enumerate(days):
                day_pref = DayPreference()
                day_pref.guardian = guardian
                day_pref.day = day
                day_pref.rank = i
                day_pref.save()
            for child in guardian.children:
                subjects = Combination.all().filter('class_id', child.class_id).fetch(999)
                selection = random.sample(subjects, int(random.triangular(0, 4, 0)))
                for choice in selection:
                    request = Request()
                    request.event = event
                    request.guardian = guardian
                    request.student = child
                    request.combination = choice
                    request.save()
                    

                    
class DisplayRequestsHandler(webapp.RequestHandler):
    def get(self):
        path = os.path.join(os.path.dirname(__file__), 'templates/requests.html')
        template_values = {
Exemple #5
0
    def post(self, eventId, guardianId):
        '''The visitor is not an authenticated guardian'''
        if not SubscriptionLoginHandler.isAuthenticatedGuardian():
            self.redirect('/inschrijven/')
            return
        
        '''The guardian is not authorized to the given'''
        if not self.isAuthorized(eventId, guardianId):
            SubscriptionLoginHandler.redirectToSubscriptionPage(self)
            return
        
        event = Event.get_by_id(int(eventId))
        days = Day.gql("WHERE event = :1", event).fetch(999)
        guardian = Guardian.get_by_key_name(guardianId)
        students = Student.gql("WHERE guardian = :1", guardian).fetch(999, 0)
        students_subjects = self.getStudentsSubjects(students)
        notifications = []
        templVal = {
            'event': event,
            'days': days,
            'guardian': guardian,
            'students': students_subjects,
            'notifications': notifications
        }
           
        if not (event and days and guardian and students):
            notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
            self.showError(templVal)
            return
        
        subscriptionDetailsList = SubscriptionDetails.gql("WHERE event = :1 AND guardian = :2", event, guardian).fetch(1, 0)
        if not subscriptionDetailsList:
            notifications.append('Pagina niet gevonden.')
            self.showError(templVal)
            return           
        subscriptionDetails = subscriptionDetailsList[0]
        if subscriptionDetails and subscriptionDetails.requested:
            notifications.append('U kunt geen verzoeken meer indienen.')
            self.showError(templVal)
            return
        
        studentKeys = [str(k.replace('subject_', '')) for k in self.request.arguments() if re.match("subject_.+", k)]
        requests = []
        dayPrefs = []
        
        for s in students[:]:
            if str(s.key().name()) not in studentKeys:
                students.remove(s)
                
        if not students:
            notifications.append('U kunt geen verzoek indienen als u geen enkel vak geselecteerd heeft. ')
        
        for student in students[:]:
            subjectCodes = [c for c in self.request.get_all("subject_" + str(student.key().name()))]
            subjects = Subject.get_by_key_name(subjectCodes)
            if len(subjectCodes) > 3:
                notifications.append('U kunt maximaal 3 vakken per leerling bespreken.')
            if len(subjectCodes) != len(subjects):
                notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
                
            for subject in subjects:
                combination = Combination.gql("WHERE class_id = :1 AND subject = :2", student.class_id, subject).fetch(1,0)[0]
                if not combination:
                    notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
                    self.showError(templVal)
                    return
                request = Request()
                request.event = event
                request.guardian = guardian
                request.student = student
                request.combination = combination
                requests.append(request)

        '''Process timepreference'''
        timePref = TimePreference()
        timePref.event = event
        timePref.guardian = guardian
        timePref.preference = 0
        if not (self.request.get('time_pref') and (int(self.request.get('time_pref')) in [0,1,2])):
            notifications.append('U moet een voorkeur voor tijd aangeven.')
        else:            
            timePref.preference = int(self.request.get('time_pref'))
        
        '''Check if dates from the form match the dates from the event '''
        dayKeys = [long(k.replace('date_', '')) for k in self.request.arguments() if re.match("date_.+", k)]
        dayKeysFromStore= [day.key().id() for day in days]
        daysOk = True
        for dayKey in dayKeys:
            if dayKey not in dayKeysFromStore:
                daysOk = False
                notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
                self.showError(templVal)
                return

        '''Check if the daypreference are correct filled in'''    
        dayPrefsList = [int(self.request.get(k)) for k in self.request.arguments() if re.match("date_.+", k)]
        dayPrefsList.sort()
        dayPrefsOk = True
        if dayPrefsList != [1,2,3]:
            dayPrefsOk = False
            notifications.append('U moet een eerste, een tweede en een derde voorkeur aangeven')

        '''Process daypreferences'''
        if daysOk and dayPrefsOk:
            for day in days:
                dayPref = DayPreference()
                dayPref.day = day
                dayPref.guardian = guardian
                dayPref.rank = int(self.request.get("date_" + str(day.key().id())))
                dayPrefs.append(dayPref)
        
        if notifications:
            path = os.path.join(os.path.dirname(__file__), '../templates/subscription/subscription.html')
            self.response.out.write(template.render(path, templVal))
            return
        
        '''Store the requests'''
        for request in requests:
            request.put()
        for dayPref in dayPrefs:
            dayPref.put()
        timePref.put()
        subscriptionDetails.requested = True
        subscriptionDetails.put()
        
        SubscriptionLogoutHandler.logoutGuardian()
        path = os.path.join(os.path.dirname(__file__), '../templates/subscription/subscription-success.html')
        self.response.out.write(template.render(path, templVal))
        return