コード例 #1
0
    def compute_traffic_scores(self):  # Computes traffic scores
        self.classes_time = {
        }  # contains class num as key and time of use as its value
        for r in self.rooms:
            time = {}
            for d in self.days:
                time[d] = []
            for course in self.parsed_info.values():
                if r in course.values():
                    for x in course:
                        if x in self.days and course[x] not in time[x]:
                            time[x].append(course[x])
            self.classes_time[r] = time
        # ==== Removes time after 19:00
        for day in self.classes_time.values():
            for time in day.values():
                time.sort()
                for hour in time:
                    if hour >= "19:00-24:00":
                        time.remove(hour)
        # ==== Block of code that computes the traffic scores
        classes_traffic_num = {
        }  # contains class num as key and its traffic num
        for cla in self.classes_time:
            day_hour = {}
            for d in self.days:
                day_hour[d] = 0
            for day in self.classes_time[cla]:
                for time in self.classes_time[cla][day]:
                    uncut_time = time.split('-')
                    start_hour = uncut_time[0].split(":")[0]
                    end_hour = uncut_time[1].split(":")[0]
                    difference_hours = int(end_hour) - int(start_hour)
                    sum_hours = day_hour[day] + difference_hours
                    day_hour[day] = sum_hours
            classes_traffic_num[cla] = day_hour
        for cla, day_time in classes_traffic_num.items():
            for day in day_time:
                if day_time[day] == 0:
                    day_time[day] = 0.1
                traffic_num = day_time[day] / (19.0 - 9.0)
                day_time[day] = traffic_num
            normalized_dict = mysearchengine.normalizescores(day_time)
            for x in normalized_dict:
                rounded_num = round(normalized_dict[x], 4)
                normalized_dict[x] = rounded_num
            classes_traffic_num[cla] = normalized_dict

        for buildings in self.buildings_objects.values():
            for cla_object in buildings.classroom_objects:
                for cla in classes_traffic_num:
                    if cla in cla_object.room_number:
                        for day in classes_traffic_num[cla]:
                            cla_object.traffic_score[
                                day] = classes_traffic_num[cla][
                                    day]  # (updates the classroom
コード例 #2
0
 def compute_closeness_scores(self, building, room_num):
     current_class = ''  # to keep selected class
     closeness = {}  # to keep closeness scores
     self.normalized_closenes = {}
     for classes in self.buildings[building].classrooms:
         if classes.room_num == room_num:  # if classes room number == selected room number
             current_class = classes  # set current objdect
     for name, build in self.buildings.items():
         for another_class in build.classrooms:  # find closeness score using another classes
             closeness[str(another_class.building_num) + str(
                 another_class.room_num)] = current_class.get_distance_from(
                     another_class)
     self.normalized_closenes = mysearchengine.normalizescores(
         closeness, smallIsBetter=True)
コード例 #3
0
 def compute_traffic_scores(self, day):
     dict_ = {}  # to keep class_num and result of traffic score calculation
     self.normalized_traffic = {}  # to keep normalized traffic score
     for name, build in self.buildings.items():
         for class_ in build.classrooms:
             if day not in class_.traffic_score:  # if day not exists in traffic score
                 class_.traffic_score[day] = 0  # set its traffic score as 0
             score = class_.traffic_score[
                 day]  # take class traffic score for corresponding day
             result = float(score) / 10  # traffic calculations
             if result == 0.0:  # if result 0 replace it with 0.1
                 result = 0.1
             class_.traffic_score[day] = result  # set class traffic score
             class_num = str(class_.building_num) + str(class_.room_num)
             dict_[
                 class_num] = result  # and add them in dict_ dictionary to normalize
     self.normalized_traffic = mysearchengine.normalizescores(
         dict_, smallIsBetter=True)
コード例 #4
0
 def compute_closeness_scores(self, location,
                              room):  # Computes closeness score
     # ====== Block of code that computes the closeness scores
     chosen_building_num = location.get().split()[2]
     chosen_room = chosen_building_num + room.get()
     closeness = {}
     for building in self.buildings_objects.values():
         for cla_obj in building.classroom_objects:
             if chosen_room == cla_obj.room_number:
                 current_room = cla_obj
     for building in self.buildings_objects.values():
         for cla_obj in building.classroom_objects:
             closeness[
                 cla_obj.room_number] = current_room.get_distance_from(
                     cla_obj)
     normalized_closeness = mysearchengine.normalizescores(closeness)
     for cla, score in normalized_closeness.items():
         self.search_results_items.append(
             SearchResultItem(cla, round(score, 4)))
コード例 #5
0
    def compute_availability_scores(self, start_time, end_time, day):
        self.search_items = {
        }  # to keep class number as a key and SearchResultItem objects as value
        self.normalized_availability = {
        }  # to keep normalized availability score
        for time, list_ in self.days[day].time_slots.items():
            for class_obj in list_:
                class_num = str(class_obj.building_num) + str(
                    class_obj.room_num)  # class num like 4302
                self.search_items.setdefault(
                    class_num, SearchResultItem(
                        class_obj))  # class num and SearchRes. obj
                self.search_items[class_num].available_slots.add(
                    time)  # add in available_slots

        for class_ in self.search_items:
            self.search_items[class_].compute_availability_score(
                start_time, end_time, day)  # to compute availability
            self.normalized_availability[class_] = self.search_items[
                class_].availability_score

        self.normalized_availability = mysearchengine.normalizescores(
            self.normalized_availability,
            smallIsBetter=False)  # to keep normalized values
コード例 #6
0
 def compute_availability(
         self, start_time, end_time,
         day):  # Computes available time in each class and availability
     selected_start_time = start_time.get()  # scores
     selected_end_time = end_time.get()
     selected_day = day.get()
     no_class_hours = {}
     # ========= Block of code that determines when the class is empty and adds it to the avaialability_slots
     for cla in self.classes_time:
         no_class_hours[cla] = []
         for day in self.classes_time[cla]:
             if day == selected_day and len(
                     self.classes_time[cla][day]) > 1:
                 for hour_class in range(
                         len(self.classes_time[cla][day]) - 1):
                     first_hour_split = self.classes_time[cla][day][
                         hour_class].split("-")[1]
                     second_hour_split = self.classes_time[cla][day][
                         hour_class + 1].split("-")[0]
                     if first_hour_split != second_hour_split:
                         no_class_hour = first_hour_split + "-" + second_hour_split
                         no_class_hours[cla].append(no_class_hour)
             elif day == selected_day and len(
                     self.classes_time[cla][day]) == 0:
                 no_class_hours[cla].append("09:00-19:00")
             elif day == selected_day and len(
                     self.classes_time[cla][day]) == 1:
                 first_hour = self.classes_time[cla][day][0].split("-")[0]
                 second_hour = self.classes_time[cla][day][0].split("-")[1]
                 no_class_hours[cla].append('09:00-' + first_hour)
                 no_class_hours[cla].append(second_hour + "-19:00")
             if day == selected_day and len(no_class_hours[cla]) == 0:
                 first_hour = self.classes_time[cla][day][0].split("-")[0]
                 second_hour = self.classes_time[cla][day][
                     len(self.classes_time[cla][day]) - 1].split("-")[1]
                 if first_hour != "9:00":
                     no_class_hours[cla].append("09:00-" + first_hour)
                 no_class_hours[cla].append(second_hour + "-19:00")
     # ==== Block of code that gets the available scores
     for cla, hour_list in no_class_hours.items():
         if len(hour_list) > 0 and "09:00" not in hour_list[0]:
             morning_no_class = "09:00-" + hour_list[0].split('-')[0]
             hour_list.insert(0, morning_no_class)
         if len(hour_list) > 0 and "19:00" not in hour_list[len(hour_list) -
                                                            1]:
             afternoon_no_class = hour_list[len(hour_list) -
                                            1].split('-')[1] + "-19:00"
             hour_list.insert(len(hour_list), afternoon_no_class)
     for cla in no_class_hours:
         if "09:00-09:00" in no_class_hours[cla]:
             no_class_hours[cla].pop(0)
         for result in self.search_results_items:
             if result.classroom == cla:
                 for time_interval in no_class_hours[cla]:
                     result.available_slots.append(time_interval)
     for result in self.search_results_items:  # removes 21:00 from list
         if result.classroom == "3001" or "7029":
             for time_interval in result.available_slots:
                 if "21:00" in time_interval:
                     result.available_slots.pop(
                         len(result.available_slots) - 1)
     normalizer = {}  # Contains normalized scores
     for result in self.search_results_items:
         result.compute_availability_scores(selected_start_time,
                                            selected_end_time)
         normalizer[result.classroom] = result.availability
     normalized = mysearchengine.normalizescores(
         normalizer)  # Normalizes the scores
     for cla, score in normalized.items():
         for result in self.search_results_items:
             if cla == result.classroom:
                 result.availability = abs(round(score, 4))