Exemplo n.º 1
0
class Router(object):
    def __init__(self):
        self.mongodb_database_connection = MongodbDatabaseConnection(host=mongodb_host, port=mongodb_port)
        log(module_name='Router', log_type='DEBUG', log_message='mongodb_database_connection: established')

    def get_bus_stop(self, name=None, provided_point=None, longitude=None, latitude=None):
        """
        Get a bus_stop_document.

        :param name: string
        :param provided_point: Point
        :param longitude: float
        :param latitude: float
        :return: bus_stop: bus_stop_document
        """
        bus_stop = None

        if name is not None:
            bus_stop = self.mongodb_database_connection.find_bus_stop_document(name=name)
        elif provided_point is not None:
            bus_stop_documents = self.mongodb_database_connection.find_bus_stop_documents()
            bus_stop = self.get_bus_stop_closest_to_point(
                bus_stop_documents=bus_stop_documents,
                provided_point=provided_point
            )
        elif longitude is not None and latitude is not None:
            point = Point(longitude=longitude, latitude=latitude)
            bus_stop_documents = self.mongodb_database_connection.find_bus_stop_documents()
            bus_stop = self.get_bus_stop_closest_to_point(
                bus_stop_documents=bus_stop_documents,
                provided_point=point
            )
        else:
            pass

        return bus_stop

    @staticmethod
    def get_bus_stop_closest_to_point(bus_stop_documents, provided_point):
        """
        Get the bus stop which is closest to a geographic point.

        :param bus_stop_documents: [bus_stop_document]
        :param provided_point: Point
        :return closest_bus_stop: bus_stop_document
        """
        minimum_distance = float('Inf')
        closest_bus_stop = None

        for bus_stop_document in bus_stop_documents:
            bus_stop_document_point = bus_stop_document.get('point')

            current_distance = distance(
                point_one=provided_point,
                longitude_two=bus_stop_document_point.get('longitude'),
                latitude_two=bus_stop_document_point.get('latitude')
            )
            if current_distance == 0:
                closest_bus_stop = bus_stop_document
                break
            elif current_distance < minimum_distance:
                minimum_distance = current_distance
                closest_bus_stop = bus_stop_document
            else:
                pass

        return closest_bus_stop

    def get_bus_stops(self, names):
        """
        Get multiple bus_stop_documents.

        :param names: [string]
        :return: bus_stops: [bus_stop_document]
        """
        bus_stops = []

        # for name in names:
        #     bus_stop = self.get_bus_stop(name=name)
        #     bus_stops.append(bus_stop)

        bus_stop_documents = self.mongodb_database_connection.find_bus_stop_documents(names=names)
        bus_stop_documents_dictionary = {}

        for bus_stop_document in bus_stop_documents:
            bus_stop_document_name = bus_stop_document.get('name')
            bus_stop_documents_dictionary[bus_stop_document_name] = bus_stop_document

        for name in names:
            bus_stop_document = bus_stop_documents_dictionary.get(name)
            bus_stops.append(bus_stop_document)

        return bus_stops

    def get_bus_stops_dictionary(self):
        """
        Retrieve a dictionary containing all the documents of the BusStops collection.

        :return: bus_stops_dictionary: {name -> {'_id', 'osm_id', 'name', 'point': {'longitude', 'latitude'}}}
        """
        bus_stops_dictionary = self.mongodb_database_connection.find_bus_stop_documents(in_dictionary=True)
        return bus_stops_dictionary

    def get_bus_stops_list(self):
        """
        Retrieve a list containing all the documents of the BusStops collection.

        :return: bus_stops_list: [{'_id', 'osm_id', 'name', 'point': {'longitude', 'latitude'}}]
        """
        bus_stops_list = self.mongodb_database_connection.find_bus_stop_documents()
        return bus_stops_list

    def get_edges_dictionary(self):
        """
        Retrieve a dictionary containing all the documents of the Edges collection.

        :return: {starting_node_osm_id -> [{'_id', 'starting_node': {'osm_id', 'point': {'longitude', 'latitude'}},
                                            'ending_node': {'osm_id', 'point': {'longitude', 'latitude'}},
                                            'max_speed', 'road_type', 'way_id', 'traffic_density'}]}
        """
        edges_dictionary = self.mongodb_database_connection.find_edge_documents(in_dictionary=True)
        return edges_dictionary

    def get_edges_list(self):
        """
        Retrieve a list containing all the documents of the Edges collection.

        :return: edges_list: [{'_id', 'starting_node': {'osm_id', 'point': {'longitude', 'latitude'}},
                               'ending_node': {'osm_id', 'point': {'longitude', 'latitude'}},
                               'max_speed', 'road_type', 'way_id', 'traffic_density'}]
        """
        edges_list = self.mongodb_database_connection.find_edge_documents()
        return edges_list

    def get_points_dictionary(self):
        """
        Retrieve a dictionary containing all the documents of the Points collection.

        :return points_dictionary: {osm_id -> {'_id', 'osm_id', 'point': {'longitude', 'latitude'}}}
        """
        points_dictionary = self.mongodb_database_connection.find_point_documents(in_dictionary=True)
        return points_dictionary

    def get_route_between_two_bus_stops(self, starting_bus_stop=None, ending_bus_stop=None,
                                        starting_bus_stop_name=None, ending_bus_stop_name=None,
                                        edges_dictionary=None):
        """
        Identify the less time-consuming route between two bus_stops.

        :param starting_bus_stop: bus_stop_document
        :param ending_bus_stop: bus_stop_document
        :param starting_bus_stop_name: string
        :param ending_bus_stop_name: string
        :param edges_dictionary: {starting_node_osm_id -> [edge_document]}
        :return response: get_route_between_two_bus_stops
        """
        if starting_bus_stop is None and starting_bus_stop_name is not None:
            starting_bus_stop = self.get_bus_stop(name=starting_bus_stop_name)

        if ending_bus_stop is None and ending_bus_stop_name is not None:
            ending_bus_stop = self.get_bus_stop(name=ending_bus_stop_name)

        if edges_dictionary is None:
            edges_dictionary = self.get_edges_dictionary()

        route = identify_path_with_lowest_cost(
            start=starting_bus_stop,
            end=ending_bus_stop,
            edges_dictionary=edges_dictionary
        )
        response = {
            'starting_bus_stop': starting_bus_stop,
            'ending_bus_stop': ending_bus_stop,
            'route': route
        }
        return response

    def get_route_between_multiple_bus_stops(self, bus_stops=None, bus_stop_names=None):
        """
        Identify the less time-consuming route between multiple bus_stops.

        :param bus_stops: [bus_stop_document]
        :param bus_stop_names: string
        :return response: get_route_between_multiple_bus_stops
        """
        response = []
        edges_dictionary = self.get_edges_dictionary()

        if bus_stops is None and bus_stop_names is not None:
            bus_stops = self.get_bus_stops(names=bus_stop_names)

        for i in range(0, len(bus_stops) - 1):
            starting_bus_stop = bus_stops[i]
            ending_bus_stop = bus_stops[i + 1]

            intermediate_route = self.get_route_between_two_bus_stops(
                starting_bus_stop=starting_bus_stop,
                ending_bus_stop=ending_bus_stop,
                edges_dictionary=edges_dictionary
            )
            response.append(intermediate_route)

        return response

    def get_waypoints_between_two_bus_stops(self, starting_bus_stop=None, ending_bus_stop=None,
                                            starting_bus_stop_name=None, ending_bus_stop_name=None):
        """
        Identify all possible route connections between two bus_stops.

        :param starting_bus_stop: bus_stop_document
        :param ending_bus_stop: bus_stop_document
        :param starting_bus_stop_name: string
        :param ending_bus_stop_name: string
        :return response: get_waypoints_between_two_bus_stops
        """
        if starting_bus_stop is None and starting_bus_stop_name is not None:
            starting_bus_stop = self.get_bus_stop(name=starting_bus_stop_name)

        if ending_bus_stop is None and ending_bus_stop_name is not None:
            ending_bus_stop = self.get_bus_stop(name=ending_bus_stop_name)

        edges_dictionary = self.get_edges_dictionary()

        waypoints = identify_all_paths(
            starting_node_osm_id=starting_bus_stop.get('osm_id'),
            ending_node_osm_id=ending_bus_stop.get('osm_id'),
            edges_dictionary=edges_dictionary
        )
        response = {
            'starting_bus_stop': starting_bus_stop,
            'ending_bus_stop': ending_bus_stop,
            'waypoints': waypoints
        }
        return response

    def get_waypoints_between_multiple_bus_stops(self, bus_stops=None, bus_stop_names=None):
        """
        Identify all possible route connections between multiple bus_stops.

        :param bus_stops: [bus_stop_document]
        :param bus_stop_names: string
        :return response: get_waypoints_between_multiple_bus_stops
        """
        response = []

        if bus_stops is None and bus_stop_names is not None:
            bus_stops = self.get_bus_stops(names=bus_stop_names)

        edges_dictionary = self.get_edges_dictionary()

        for i in range(0, len(bus_stops) - 1):
            starting_bus_stop = bus_stops[i]
            ending_bus_stop = bus_stops[i + 1]

            waypoints = identify_all_paths(
                starting_node_osm_id=starting_bus_stop.get('osm_id'),
                ending_node_osm_id=ending_bus_stop.get('osm_id'),
                edges_dictionary=edges_dictionary
            )
            intermediate_response = {
                'starting_bus_stop': starting_bus_stop,
                'ending_bus_stop': ending_bus_stop,
                'waypoints': waypoints
            }
            response.append(intermediate_response)

        return response
class TrafficDataParser(object):
    def __init__(self):
        self.mongodb_database_connection = MongodbDatabaseConnection(host=mongodb_host, port=mongodb_port)
        self.edge_documents = []
        self.traffic_event_documents = []
        self.minimum_latitude = float('inf')
        self.maximum_latitude = float('-inf')
        self.minimum_longitude = float('inf')
        self.maximum_longitude = float('-inf')
        log(module_name='traffic_data_parser', log_type='DEBUG',
            log_message='mongodb_database_connection: established')

    def check_borders_of_traffic_event_document(self, traffic_event_document):
        """
        Check if a traffic_event_document corresponds to the operation area, by comparing their borders.
        If yes, then return True. Otherwise, False.

        :param traffic_event_document: traffic_event_document
        :return: included_in_borders: bool
        """
        included_in_borders = True
        traffic_event_point_document = traffic_event_document.get('point')
        traffic_event_longitude = traffic_event_point_document.get('longitude')
        traffic_event_latitude = traffic_event_point_document.get('latitude')

        if (traffic_event_longitude < self.minimum_longitude or traffic_event_longitude > self.maximum_longitude or
                    traffic_event_latitude < self.minimum_latitude or traffic_event_latitude > self.maximum_latitude):
            included_in_borders = False

        return included_in_borders

    @staticmethod
    def estimate_traffic_density_value(event_level):
        """
        Estimate the traffic_density_value based on the event_level.

        :param event_level: int
        :return: traffic_density_value: float
        """
        if event_level == 1:
            traffic_density_value = 0.2
        elif event_level == 2:
            traffic_density_value = 0.4
        elif event_level == 3:
            traffic_density_value = 0.6
        elif event_level == 4:
            traffic_density_value = 0.8
        else:
            traffic_density_value = 0.0

        return traffic_density_value

    def get_borders_of_operation_area(self):
        """
        Get the minimum and maximum values for longitude and latitude of the operation area.

        :return: borders: {'minimum_latitude', 'maximum_latitude', 'minimum_longitude', 'maximum_longitude'}
        """
        if len(self.edge_documents) == 0:
            self.retrieve_edge_documents()

        self.set_borders_of_operation_area()

        borders = {
            'minimum_latitude': self.minimum_latitude,
            'maximum_latitude': self.maximum_latitude,
            'minimum_longitude': self.minimum_longitude,
            'maximum_longitude': self.maximum_longitude
        }
        return borders

    @staticmethod
    def get_edge_document_with_minimum_distance(traffic_event_document, edge_documents):
        """
        Get the edge_document which corresponds to the nearest point of a traffic_event.

        :param traffic_event_document: traffic_event_document
        :param edge_documents: [edge_document]
        :return:
        """
        edge_document_with_minimum_distance = None
        minimum_distance = float('Inf')

        traffic_event_point_document = traffic_event_document.get('point')
        traffic_event_longitude = traffic_event_point_document.get('longitude')
        traffic_event_latitude = traffic_event_point_document.get('latitude')

        traffic_event_point = Point(
            longitude=traffic_event_longitude,
            latitude=traffic_event_latitude
        )
        for edge_document in edge_documents:
            starting_node = edge_document.get('starting_node')
            starting_node_point_document = starting_node.get('point')
            starting_node_point = Point(
                longitude=starting_node_point_document.get('longitude'),
                latitude=starting_node_point_document.get('latitude')
            )
            ending_node = edge_document.get('ending_node')
            ending_node_point_document = ending_node.get('point')
            ending_node_point = Point(
                longitude=ending_node_point_document.get('longitude'),
                latitude=ending_node_point_document.get('latitude')
            )
            distance_of_starting_node = distance(
                point_one=traffic_event_point,
                point_two=starting_node_point
            )
            distance_of_ending_node = distance(
                point_one=traffic_event_point,
                point_two=ending_node_point
            )
            distance_of_edge_document = distance_of_starting_node + distance_of_ending_node

            if distance_of_edge_document < minimum_distance:
                edge_document_with_minimum_distance = edge_document
                minimum_distance = distance_of_edge_document

        return edge_document_with_minimum_distance

    def retrieve_edge_documents(self):
        self.edge_documents = self.mongodb_database_connection.find_edge_documents()

    def retrieve_traffic_event_documents(self):
        self.traffic_event_documents = self.mongodb_database_connection.find_traffic_event_documents()

    def set_borders_of_operation_area(self):
        """
        Set the minimum and maximum values for longitude and latitude of the operation area.

        :return: None
        """
        for edge_document in self.edge_documents:
            starting_node = edge_document.get('starting_node')
            starting_node_point_document = starting_node.get('point')
            starting_node_longitude = starting_node_point_document.get('longitude')
            starting_node_latitude = starting_node_point_document.get('latitude')

            if starting_node_longitude < self.minimum_longitude:
                self.minimum_longitude = starting_node_longitude

            if starting_node_longitude > self.maximum_longitude:
                self.maximum_longitude = starting_node_longitude

            if starting_node_latitude < self.minimum_latitude:
                self.minimum_latitude = starting_node_latitude

            if starting_node_latitude > self.maximum_latitude:
                self.maximum_latitude = starting_node_latitude

            ending_node = edge_document.get('ending_node')
            ending_node_point_document = ending_node.get('point')
            ending_node_longitude = ending_node_point_document.get('longitude')
            ending_node_latitude = ending_node_point_document.get('latitude')

            if ending_node_longitude < self.minimum_longitude:
                self.minimum_longitude = ending_node_longitude

            if ending_node_longitude > self.maximum_longitude:
                self.maximum_longitude = ending_node_longitude

            if ending_node_latitude < self.minimum_latitude:
                self.minimum_latitude = ending_node_latitude

            if ending_node_latitude > self.maximum_latitude:
                self.maximum_latitude = ending_node_latitude

    def update_traffic_data(self):
        """

        :return: None
        """
        self.retrieve_edge_documents()
        self.retrieve_traffic_event_documents()
        self.set_borders_of_operation_area()

        for traffic_event_document in self.traffic_event_documents:

            if self.check_borders_of_traffic_event_document(traffic_event_document=traffic_event_document):
                edge_document_with_minimum_distance = self.get_edge_document_with_minimum_distance(
                    traffic_event_document=traffic_event_document,
                    edge_documents=self.edge_documents
                )
                traffic_density_value = self.estimate_traffic_density_value(
                    event_level=traffic_event_document.get('event_level')
                )
                self.mongodb_database_connection.update_traffic_density(
                    edge_object_id=edge_document_with_minimum_distance.get('_id'),
                    new_traffic_density_value=traffic_density_value
                )
            else:
                print 'traffic_event_document: out_of_borders -', traffic_event_document
class TrafficDataParser(object):
    def __init__(self):
        self.mongodb_database_connection = MongodbDatabaseConnection(host=mongodb_host, port=mongodb_port)
        self.edge_documents = []
        self.traffic_event_documents = []
        self.minimum_longitude = float("inf")
        self.maximum_longitude = float("-inf")
        self.minimum_latitude = float("inf")
        self.maximum_latitude = float("-inf")
        log(module_name="traffic_data_parser", log_type="DEBUG", log_message="mongodb_database_connection: established")

    def check_borders_of_traffic_event_document(self, traffic_event_document):
        """
        Check if a traffic_event_document corresponds to the operation area, by comparing their borders.
        If yes, then return True. Otherwise, False.

        traffic_event_document: {
            '_id', 'event_id', 'event_type', 'event_level', 'point': {'longitude', 'latitude'}, 'datetime'
        }
        :param traffic_event_document: traffic_event_document
        :return: included_in_borders: bool
        """
        included_in_borders = True
        traffic_event_point_document = traffic_event_document.get("point")
        traffic_event_longitude = traffic_event_point_document.get("longitude")
        traffic_event_latitude = traffic_event_point_document.get("latitude")

        if (
            traffic_event_longitude < self.minimum_longitude
            or traffic_event_longitude > self.maximum_longitude
            or traffic_event_latitude < self.minimum_latitude
            or traffic_event_latitude > self.maximum_latitude
        ):
            included_in_borders = False

        return included_in_borders

    @staticmethod
    def estimate_traffic_density_value(event_level):
        """
        Estimate the traffic_density_value based on the event_level.

        :param event_level: int
        :return: traffic_density_value: float
        """
        if event_level == 1:
            traffic_density_value = 0.2
        elif event_level == 2:
            traffic_density_value = 0.4
        elif event_level == 3:
            traffic_density_value = 0.6
        elif event_level == 4:
            traffic_density_value = 0.8
        else:
            traffic_density_value = 0.0

        return traffic_density_value

    @staticmethod
    def get_edge_document_with_minimum_distance(traffic_event_document, edge_documents):
        """
        Get the edge_document which corresponds to the nearest point of a traffic_event.

        edge_document: {
            '_id', 'starting_node': {'osm_id', 'point': {'longitude', 'latitude'}},
            'ending_node': {'osm_id', 'point': {'longitude', 'latitude'}},
            'max_speed', 'road_type', 'way_id', 'traffic_density'
        }
        traffic_event_document: {
            '_id', 'event_id', 'event_type', 'event_level', 'point': {'longitude', 'latitude'}, 'datetime'
        }
        :param traffic_event_document: traffic_event_document
        :param edge_documents: [edge_document]
        :return:
        """
        edge_document_with_minimum_distance = None
        minimum_distance = float("Inf")

        traffic_event_point_document = traffic_event_document.get("point")
        traffic_event_longitude = traffic_event_point_document.get("longitude")
        traffic_event_latitude = traffic_event_point_document.get("latitude")

        traffic_event_point = Point(longitude=traffic_event_longitude, latitude=traffic_event_latitude)
        for edge_document in edge_documents:
            starting_node = edge_document.get("starting_node")
            starting_node_point_document = starting_node.get("point")
            starting_node_point = Point(
                longitude=starting_node_point_document.get("longitude"),
                latitude=starting_node_point_document.get("latitude"),
            )
            ending_node = edge_document.get("ending_node")
            ending_node_point_document = ending_node.get("point")
            ending_node_point = Point(
                longitude=ending_node_point_document.get("longitude"),
                latitude=ending_node_point_document.get("latitude"),
            )
            distance_of_starting_node = distance(point_one=traffic_event_point, point_two=starting_node_point)
            distance_of_ending_node = distance(point_one=traffic_event_point, point_two=ending_node_point)
            distance_of_edge_document = distance_of_starting_node + distance_of_ending_node

            if distance_of_edge_document < minimum_distance:
                edge_document_with_minimum_distance = edge_document
                minimum_distance = distance_of_edge_document

        return edge_document_with_minimum_distance

    def set_borders_of_operation_area(self, edge_documents):
        """
        Set the minimum and maximum values for longitude and latitude of the operation area.

        edge_document: {
            '_id', 'starting_node': {'osm_id', 'point': {'longitude', 'latitude'}},
            'ending_node': {'osm_id', 'point': {'longitude', 'latitude'}},
            'max_speed', 'road_type', 'way_id', 'traffic_density'
        }
        :param edge_documents: [edge_document]
        :return: None
        """
        for edge_document in edge_documents:
            starting_node = edge_document.get("starting_node")
            starting_node_point_document = starting_node.get("point")
            starting_node_longitude = starting_node_point_document.get("longitude")
            starting_node_latitude = starting_node_point_document.get("latitude")

            if starting_node_longitude < self.minimum_longitude:
                self.minimum_longitude = starting_node_longitude

            if starting_node_longitude > self.maximum_longitude:
                self.maximum_longitude = starting_node_longitude

            if starting_node_latitude < self.minimum_latitude:
                self.minimum_latitude = starting_node_latitude

            if starting_node_latitude > self.maximum_latitude:
                self.maximum_latitude = starting_node_latitude

            ending_node = edge_document.get("ending_node")
            ending_node_point_document = ending_node.get("point")
            ending_node_longitude = ending_node_point_document.get("longitude")
            ending_node_latitude = ending_node_point_document.get("latitude")

            if ending_node_longitude < self.minimum_longitude:
                self.minimum_longitude = ending_node_longitude

            if ending_node_longitude > self.maximum_longitude:
                self.maximum_longitude = ending_node_longitude

            if ending_node_latitude < self.minimum_latitude:
                self.minimum_latitude = ending_node_latitude

            if ending_node_latitude > self.maximum_latitude:
                self.maximum_latitude = ending_node_latitude

    def update_traffic_data(self):
        """
        edge_document: {
            '_id', 'starting_node': {'osm_id', 'point': {'longitude', 'latitude'}},
            'ending_node': {'osm_id', 'point': {'longitude', 'latitude'}},
            'max_speed', 'road_type', 'way_id', 'traffic_density'
        }
        traffic_event_document: {
            '_id', 'event_id', 'event_type', 'event_level', 'point': {'longitude', 'latitude'}, 'datetime'
        }
        :return: None
        """
        self.edge_documents = self.mongodb_database_connection.find_edge_documents()
        self.traffic_event_documents = self.mongodb_database_connection.find_traffic_event_documents()
        self.set_borders_of_operation_area(edge_documents=self.edge_documents)

        for traffic_event_document in self.traffic_event_documents:

            if self.check_borders_of_traffic_event_document(traffic_event_document=traffic_event_document):
                edge_document_with_minimum_distance = self.get_edge_document_with_minimum_distance(
                    traffic_event_document=traffic_event_document, edge_documents=self.edge_documents
                )
                traffic_density_value = self.estimate_traffic_density_value(
                    event_level=traffic_event_document.get("event_level")
                )
                self.mongodb_database_connection.update_traffic_density(
                    edge_object_id=edge_document_with_minimum_distance.get("_id"),
                    new_traffic_density_value=traffic_density_value,
                )
            else:
                print "traffic_event_document: out_of_borders -", traffic_event_document
Exemplo n.º 4
0
class TrafficDataParser(object):
    def __init__(self):
        self.mongodb_database_connection = MongodbDatabaseConnection(
            host=mongodb_host, port=mongodb_port)
        self.edge_documents = []
        self.traffic_event_documents = []
        self.minimum_latitude = float('inf')
        self.maximum_latitude = float('-inf')
        self.minimum_longitude = float('inf')
        self.maximum_longitude = float('-inf')
        log(module_name='traffic_data_parser',
            log_type='DEBUG',
            log_message='mongodb_database_connection: established')

    def check_borders_of_traffic_event_document(self, traffic_event_document):
        """
        Check if a traffic_event_document corresponds to the operation area, by comparing their borders.
        If yes, then return True. Otherwise, False.

        :param traffic_event_document: traffic_event_document
        :return: included_in_borders: bool
        """
        included_in_borders = True
        traffic_event_point_document = traffic_event_document.get('point')
        traffic_event_longitude = traffic_event_point_document.get('longitude')
        traffic_event_latitude = traffic_event_point_document.get('latitude')

        if (traffic_event_longitude < self.minimum_longitude
                or traffic_event_longitude > self.maximum_longitude
                or traffic_event_latitude < self.minimum_latitude
                or traffic_event_latitude > self.maximum_latitude):
            included_in_borders = False

        return included_in_borders

    @staticmethod
    def estimate_traffic_density_value(event_level):
        """
        Estimate the traffic_density_value based on the event_level.

        :param event_level: int
        :return: traffic_density_value: float
        """
        if event_level == 1:
            traffic_density_value = 0.2
        elif event_level == 2:
            traffic_density_value = 0.4
        elif event_level == 3:
            traffic_density_value = 0.6
        elif event_level == 4:
            traffic_density_value = 0.8
        else:
            traffic_density_value = 0.0

        return traffic_density_value

    def get_borders_of_operation_area(self):
        """
        Get the minimum and maximum values for longitude and latitude of the operation area.

        :return: borders: {'minimum_latitude', 'maximum_latitude', 'minimum_longitude', 'maximum_longitude'}
        """
        if len(self.edge_documents) == 0:
            self.retrieve_edge_documents()

        self.set_borders_of_operation_area()

        borders = {
            'minimum_latitude': self.minimum_latitude,
            'maximum_latitude': self.maximum_latitude,
            'minimum_longitude': self.minimum_longitude,
            'maximum_longitude': self.maximum_longitude
        }
        return borders

    @staticmethod
    def get_edge_document_with_minimum_distance(traffic_event_document,
                                                edge_documents):
        """
        Get the edge_document which corresponds to the nearest point of a traffic_event.

        :param traffic_event_document: traffic_event_document
        :param edge_documents: [edge_document]
        :return:
        """
        edge_document_with_minimum_distance = None
        minimum_distance = float('Inf')

        traffic_event_point_document = traffic_event_document.get('point')
        traffic_event_longitude = traffic_event_point_document.get('longitude')
        traffic_event_latitude = traffic_event_point_document.get('latitude')

        traffic_event_point = Point(longitude=traffic_event_longitude,
                                    latitude=traffic_event_latitude)
        for edge_document in edge_documents:
            starting_node = edge_document.get('starting_node')
            starting_node_point_document = starting_node.get('point')
            starting_node_point = Point(
                longitude=starting_node_point_document.get('longitude'),
                latitude=starting_node_point_document.get('latitude'))
            ending_node = edge_document.get('ending_node')
            ending_node_point_document = ending_node.get('point')
            ending_node_point = Point(
                longitude=ending_node_point_document.get('longitude'),
                latitude=ending_node_point_document.get('latitude'))
            distance_of_starting_node = distance(point_one=traffic_event_point,
                                                 point_two=starting_node_point)
            distance_of_ending_node = distance(point_one=traffic_event_point,
                                               point_two=ending_node_point)
            distance_of_edge_document = distance_of_starting_node + distance_of_ending_node

            if distance_of_edge_document < minimum_distance:
                edge_document_with_minimum_distance = edge_document
                minimum_distance = distance_of_edge_document

        return edge_document_with_minimum_distance

    def retrieve_edge_documents(self):
        self.edge_documents = self.mongodb_database_connection.find_edge_documents(
        )

    def retrieve_traffic_event_documents(self):
        self.traffic_event_documents = self.mongodb_database_connection.find_traffic_event_documents(
        )

    def set_borders_of_operation_area(self):
        """
        Set the minimum and maximum values for longitude and latitude of the operation area.

        :return: None
        """
        for edge_document in self.edge_documents:
            starting_node = edge_document.get('starting_node')
            starting_node_point_document = starting_node.get('point')
            starting_node_longitude = starting_node_point_document.get(
                'longitude')
            starting_node_latitude = starting_node_point_document.get(
                'latitude')

            if starting_node_longitude < self.minimum_longitude:
                self.minimum_longitude = starting_node_longitude

            if starting_node_longitude > self.maximum_longitude:
                self.maximum_longitude = starting_node_longitude

            if starting_node_latitude < self.minimum_latitude:
                self.minimum_latitude = starting_node_latitude

            if starting_node_latitude > self.maximum_latitude:
                self.maximum_latitude = starting_node_latitude

            ending_node = edge_document.get('ending_node')
            ending_node_point_document = ending_node.get('point')
            ending_node_longitude = ending_node_point_document.get('longitude')
            ending_node_latitude = ending_node_point_document.get('latitude')

            if ending_node_longitude < self.minimum_longitude:
                self.minimum_longitude = ending_node_longitude

            if ending_node_longitude > self.maximum_longitude:
                self.maximum_longitude = ending_node_longitude

            if ending_node_latitude < self.minimum_latitude:
                self.minimum_latitude = ending_node_latitude

            if ending_node_latitude > self.maximum_latitude:
                self.maximum_latitude = ending_node_latitude

    def update_traffic_data(self):
        """

        :return: None
        """
        self.retrieve_edge_documents()
        self.retrieve_traffic_event_documents()
        self.set_borders_of_operation_area()

        for traffic_event_document in self.traffic_event_documents:

            if self.check_borders_of_traffic_event_document(
                    traffic_event_document=traffic_event_document):
                edge_document_with_minimum_distance = self.get_edge_document_with_minimum_distance(
                    traffic_event_document=traffic_event_document,
                    edge_documents=self.edge_documents)
                traffic_density_value = self.estimate_traffic_density_value(
                    event_level=traffic_event_document.get('event_level'))
                self.mongodb_database_connection.update_traffic_density(
                    edge_object_id=edge_document_with_minimum_distance.get(
                        '_id'),
                    new_traffic_density_value=traffic_density_value)
            else:
                print 'traffic_event_document: out_of_borders -', traffic_event_document