Exemplo n.º 1
0
    def dijkstra(self, start, stop):
        logging.debug('dekstra start:' + str(start) + ' stop:' + str(stop))
        self.dijkstra_connectons = []
        for i in range(0, len(self.dijkstra_weight)):
            self.dijkstra_connectons.append([])
            for j in range(0, len(self.dijkstra_weight[i])):
                if (self.dijkstra_weight[i][j] < 10000):
                    self.dijkstra_connectons[i].append(j)

        print(self.dijkstra_connectons)
        logging.debug(self.dijkstra_connectons)
        size = self.max_id
        INF = 10**10

        dist = [INF] * size
        dist[start] = 0
        prev = [None] * size
        used = [False] * size
        min_dist = 0
        min_vertex = start
        while min_dist < INF:
            i = min_vertex
            used[i] = True
            for j in self.dijkstra_connectons[i]:
                if dist[i] + self.dijkstra_weight[i][j] < dist[j]:
                    dist[j] = dist[i] + self.dijkstra_weight[i][j]
                    prev[j] = i
            min_dist = INF
            for i in range(size):
                if not used[i] and dist[i] < min_dist:
                    min_dist = dist[i]
                    min_vertex = i

        self.paths = []
        while stop is not None:
            self.paths.append(stop)
            stop = prev[stop]
        self.paths = self.paths[::-1]

        sum = 0
        for i in range(0, len(self.paths) - 1):
            sum += self.dijkstra_weight[self.paths[i]][self.paths[i + 1]]

        return sum
Exemplo n.º 2
0
 def __init__(self, telebot, dialog_id, id):
     self.telebot = telebot
     self.dialog_id = dialog_id
     self.dialog_state = 0
     self.dialog_style = 1
     self.bot_id = id
     logging.debug('init bot ' + str(id))
     logging.debug('request building')
     self.building = get_building()
     logging.debug('init WB class')
     self.wb = WayBuilderClass(self.building)
     logging.debug('config wb')
     self.wb.init_pre_count()
Exemplo n.º 3
0
 def __init__(self, building):
     logging.debug('init WB class')
     logging.debug('request building')
     self.building = building
     logging.debug('pre count')
     self.init_pre_count()
     return
Exemplo n.º 4
0
    def get_answer(self, input_string):

        logging.debug('request amswer from bot ' + str(self.bot_id))
        logging.debug('request by string ' + input_string)
        logging.debug('bot in  state ' + str(self.dialog_state))

        if self.dialog_state == 0:
            self.send_message(sql.get_dialog_item(0, 1))
            self.dialog_state = 1
            return

        if self.dialog_state == 1:
            if int(input_string) in (1, 3):
                self.dialog_style = int(input_string)
                self.send_message(sql.get_dialog_item(1, self.dialog_style))
                self.send_message(sql.get_dialog_item(2, self.dialog_style))
                self.send_message(sql.get_dialog_item(3, self.dialog_style))
                self.send_photo('all.jpeg')
                self.send_message(sql.get_dialog_item(4, self.dialog_style))
                self.dialog_state = 2
            else:
                self.send_message(sql.get_dialog_item(5, self.dialog_style))
            return

        if self.dialog_state == 2:
            self.from_id = get_id(input_string)
            self.send_message(sql.get_dialog_item(6, self.dialog_style))
            self.send_message(sql.get_dialog_item(7, self.dialog_style))
            self.dialog_state = 3
            return

        if self.dialog_state == 3:
            self.to_id = get_id(input_string)
            self.send_message(sql.get_dialog_item(8, self.dialog_style))
            self.send_message(sql.get_dialog_item(9, self.dialog_style))
            self.dialog_state = 4
            return

        if self.dialog_state == 4:
            out_style = int(input_string)
            path = self.wb.request_path(self.from_id, self.to_id)  #
            for i in range(len(path.points)):
                self.send_message(path.points[i].name)
                if 1 < out_style:
                    if (i < len(path.connections)):
                        self.send_message(
                            str(path.connections[i].connection_comment))
            if out_style == 3:
                for id in path.floors_obj:

                    pic_path = path.floors_obj[id].picture_path
                    self.send_photo(pic_path)
            return
Exemplo n.º 5
0
    def request_path(self, start, stop):
        logging.debug('start request path start:' + str(start) + ' stop:' +
                      str(stop))
        weight = self.dijkstra(start, stop)
        print(self.paths)

        path = Path()
        path.clearr()
        print(Path.floors)
        logging.debug(Path.floors)

        path.weight = weight

        for point_id in self.paths:
            for point in self.building.graph.points:
                if point.id == point_id:
                    path.points.append(point)
                    break

        for i in range(0, len(path.points) - 1):
            for connection in self.building.graph.connections:
                if connection.point1 == path.points[
                        i].id and connection.point2 == path.points[i + 1].id:
                    path.connections.append(connection)

        floors_set = set()
        for point in path.points:
            floors_set.add(point.floor_index)

        for floor in floors_set:
            path.floors.append(floor)

        print(path.floors)
        logging.debug(path.floors)
        print(path.weight)
        logging.debug(path.weight)

        # нужен рерайтер картинок
        old_picture_path = {}
        new_picture_path = {}
        draw_points_dict_of_sequences = {}

        for id in path.floors:
            draw_points_dict_of_sequences[id] = []

        for point in path.points:
            draw_points_dict_of_sequences[point.floor_index].append(point)

        for floor_id in path.floors:
            old_picture_path[floor_id] = sql.get_instance_path_by_id(floor_id)
            #head, tail = ntpath.split(old_picture_path[floor_id])
            new_picture_path[
                floor_id] = config.pre_path + config.pre_key + str(
                    config.key) + '.jpg'
            config.key += 1
            copyfile(old_picture_path[floor_id], new_picture_path[floor_id])
            draw.redraw_picture(new_picture_path[floor_id],
                                draw_points_dict_of_sequences[floor_id])

        path.floors_obj = {}
        for id in floors_set:
            path.floors_obj[id] = sql.get_floor_by_id(id)
            path.floors_obj[id].picture_path = new_picture_path[id]
        #copyfile(src, dst)

        logging.debug('return path')
        return path
Exemplo n.º 6
0
 def send_photo(self, path):
     logging.debug('bot ' + str(self.bot_id) + ' sending photo:' + path)
     #self.telebot.send_message(self.dialog_id, '+')
     self.telebot.send_photo(self.dialog_id, open(path, 'rb'))
Exemplo n.º 7
0
 def send_message(self, text):
     logging.debug('bot ' + str(self.bot_id) + ' sending text:' + text)
     self.telebot.send_message(
         self.dialog_id, text
     )  # + '  answer of bot '+str(self.bot_id) +'  chat_id='+ str(self.dialog_id))