Exemplo n.º 1
0
    def test_gpx_file_Loading_2(self):
        test_file = GPXTrackRepository()
        parsed_file = test_file.read("../../rutaTramuntana.gpx")

        for p in parsed_file:
            plt.scatter(p.get_longitude(), p.get_latitude(), c="blue")
        plt.show()
Exemplo n.º 2
0
 def test_viterbi_algorithm(self):
     bellver_graph = Graph(39.5713, 39.5573, 2.6257, 2.6023)
     gpx_resource = GPXResourceImpl()
     points = gpx_resource.read('./../../data/tracks_to_analysis/activity_3584116575.gpx')
     hidden_markov_model = HMM(graph=bellver_graph)
     get_map_matching = GetMapMatchingImpl(hidden_markov_model)
     result = get_map_matching.match(points)
     bellver_graph.plot_graph()
     for p in points:
         plt.scatter(p.get_longitude(), p.get_latitude(), c="red")
     for r in result:
         plt.scatter(r[0].get_longitude(), r[0].get_latitude(), c="green")
         print(r)
     plt.show()
     self.assertEqual(True, True)
Exemplo n.º 3
0
    def test_get_nearest_segment_points(self):
        test_file = LoaderSaver("../../../tracks/Ficheros/rutasMFlores/activity_3689734814.gpx")
        point = Point(39.5586107, 2.6227118)
        parsed_file = test_file.parseFile()
        bellver_graph = Graph(39.5713, 39.5573, 2.6257, 2.6023)
        hidden_markov_model = HMM(graph=bellver_graph)
        fig, ax = osmnx.plot_graph(bellver_graph.graph, node_color='black', node_zorder=3, show=False, close=False)
        for p in parsed_file:
            list_of_points = hidden_markov_model.get_closest_nodes(p[2])
            plt.scatter(p[2].get_longitude(), p[2].get_latitude(), c="blue")
            plt.scatter(list_of_points[0][0].get_longitude(), list_of_points[0][0].get_latitude(), c="green")
            for res in range(2, len(list_of_points)):
                plt.scatter(list_of_points[res][0].get_longitude(), list_of_points[res][0].get_latitude(), c="red")

        plt.show()
        self.assertEqual(True, False)
Exemplo n.º 4
0
    def test_path_creation(self):
        mongo_resource = MongoResourceImpl()
        graph_information = GraphInformationRepositoryImpl(mongo_resource)

        track_statistics_repository = TrackStatisticsRepositoryImpl(
            mongo_resource)
        bellver_graph = Graph(39.5713, 39.5573, 2.6257, 2.6023)
        gpx_resource = GPXResourceImpl()
        pyplot_resource = PyplotResourceImpl()
        id_track = "Graph_Analysis_05-03-2020"
        try:
            k.start()
            data = graph_information.read_graph_information_dataframe(
                os.environ.get('LAST_VERSION_GRAPH'))
            k.stop()
        except IndexError:
            logging.warning("NOT found in MongoDB")
            return

        simulate_track = SimulateTrackImpl(bellver_graph, 4, gpx_resource,
                                           pyplot_resource,
                                           track_statistics_repository)
        # Graph information load
        bellver_graph.load_graph_analysis_statistics(data)
        simulator = TrackSimulatorPipeline(simulate_track)

        path = simulator.run(1248507104, 10000)
        a = [x[0] for x in path]
        print(path)
Exemplo n.º 5
0
    def test_mocked_path_creation(self):
        mongo_resource = MongoResourceImpl()
        track_statistics_repository = TrackStatisticsRepositoryImpl(
            mongo_resource)
        graph_information = GraphInformationRepositoryImpl(mongo_resource)
        bellver_graph = Graph(39.5713, 39.5573, 2.6257, 2.6023)
        gpx_resource = GPXResourceImpl()
        pyplot_resource = PyplotResourceImpl()
        try:
            k.start()
            data = graph_information.read_graph_information_dataframe(
                os.environ.get('LAST_VERSION_GRAPH'))
            k.stop()
        except IndexError:
            logging.warning("NOT found in MongoDB")
            return
        simulate_track = SimulateTrackImpl(bellver_graph, 4, gpx_resource,
                                           pyplot_resource,
                                           track_statistics_repository)
        # Graph information load
        bellver_graph.load_graph_analysis_statistics(data)
        simulator = TrackSimulatorPipeline(simulate_track)

        path = simulator.run(1248507104, 10000)
        a = [x[0] for x in path]
        print(path)
        fig, ax = osmnx.plot_graph_route(bellver_graph.graph,
                                         a,
                                         bgcolor='k',
                                         node_color='black',
                                         edge_linewidth=1.5,
                                         edge_alpha=1,
                                         node_zorder=3)
        plt.show()
Exemplo n.º 6
0
def analysis_main(file_directory, north_component, south_component, east_component, west_component):
    """
    Main function to deploy pipeline that analyzes GPX tracks in directory

    :param file_directory: directory path where files are stored.
    :param north_component: North component of limited area.
    :param south_component: South component of limited area.
    :param east_component: East component of limited area.
    :param west_component: West component of limited area.
    """
    # Resources
    gpx_resource = GPXResourceImpl()
    mongo_resource = MongoResourceImpl()

    # Repositories
    graph_information = GraphInformationRepositoryImpl(mongo_resource)
    track_information = TrackInformationRepositoryImpl(mongo_resource)
    track_statistics = TrackStatisticsRepositoryImpl(mongo_resource)

    # Entities
    useDefaultZone = any(elem is None for elem in [north_component, south_component, east_component, west_component])

    if useDefaultZone:
        zone_graph = Graph(NORTH_COMPONENT, SOUTH_COMPONENT, EAST_COMPONENT, WEST_COMPONENT)
    else:
        zone_graph = Graph(north_component, south_component, east_component, west_component)

    # Interactors
    get_map_matching = GetMapMatchingImpl(HMM(zone_graph))
    get_track_analysis = GetTrackAnalysisDataframeImpl()
    get_track_statistics = GetTrackAnalysisStatisticsImpl()
    get_analysis_figure = GetAnalysisFigureImpl()
    get_track_graph = GetTrackAnalysisGraphImpl()

    # Pipeline
    track_analyzer_pipeline = TrackAnalysisPipeline(gpx_resource=gpx_resource,
                                                    graph_information_repository=graph_information,
                                                    track_information_repository=track_information,
                                                    track_statistics_repository=track_statistics,
                                                    get_map_matching=get_map_matching,
                                                    get_track_analysis_dataframe=get_track_analysis,
                                                    get_track_statitstics=get_track_statistics,
                                                    get_analysis_figure=get_analysis_figure,
                                                    get_track_graph=get_track_graph,
                                                    graph=zone_graph)

    # Execution

    track_analyzer_pipeline.run(file_directory)
Exemplo n.º 7
0
def simulation_main(origin_node, distance, data, quantity):
    """
    Main function to deploy pipeline that simulates track based on previous analysis.

    :param origin_node: Node to start simulation.
    :param distance: Distance to start simulation.
    :param data: Data to import from database. (Graph_Analysis_mm-dd-YYYY)
    :param quantity: Number of tracks to generate.
    """
    origin_node = 1248507104  # Bellver Castle entrance
    distance = 20000  # In meters
    data = 'Graph_Analysis_05-24-2020'
    quantity = 1
    # Resource
    mongo_resource = MongoResourceImpl()
    pyplot_resource = PyplotResourceImpl()
    gpx_resource = GPXResourceImpl()

    # Repository
    graph_repository = GraphInformationRepositoryImpl(mongo_resource)
    track_statistics_repository = TrackStatisticsRepositoryImpl(mongo_resource)

    # Entity
    bellver_graph = Graph(39.5713, 39.5573, 2.6257, 2.6023)
    bellver_graph.load_graph_analysis_statistics(
        graph_repository.read_graph_information_dataframe(data))

    # Interactors
    simulate_track = SimulateTrackImpl(bellver_graph, 4, gpx_resource,
                                       pyplot_resource,
                                       track_statistics_repository)

    # Pipeline
    track_simulator_pipeline = TrackSimulatorPipeline(simulate_track)

    # Run
    track_simulator_pipeline.run(origin_node, distance, quantity)
Exemplo n.º 8
0
 def test_gpx_file_Loading(self):
     test_file = GPXTrackRepository()
     parsed_file = test_file.read(
         "tracks/Ficheros/RutasSegmentadas/RutaCastilloBellver1.gpx")
     self.assertEqual(len(parsed_file), 4)