def test_sportgems_fastest_interface__real_activity_data__gpx(gpx_parser): parser = gpx_parser() coordinates = list(zip(parser.latitude_list, parser.longitude_list)) result = find_fastest_section(1000, parser.timestamps_list, coordinates) assert result.start == 58 assert result.end == 118 assert math.isclose(result.velocity, 3.098, abs_tol=0.01)
def test_sportgems_fastest_interface__fit_file_which_cause_panic( fit_parser, test_file): parser = fit_parser(test_file) coordinates = list(zip(parser.latitude_list, parser.longitude_list)) for distance in configuration.fastest_distances: result = find_fastest_section(distance, parser.timestamps_list, coordinates) # sanity check that no section causes rust panic assert result.end != 0
def test_sportgems_fastest_interface__dummy_data(): # test sportgems interface with the example data given in the repo readme coordinates = [(48.123, 9.35), (48.123, 9.36), (48.123, 9.37), (48.123, 9.38)] times = [1608228953.8, 1608228954.8, 1608228955.8, 1608228956.8] result = find_fastest_section(1000, times, coordinates, tolerance=1000) assert result.start == 0 assert result.end == 1 assert math.isclose(result.velocity, 743.0908195788583, abs_tol=0.01)
def get_fastest_section(distance: int, parser) -> GenericBestSection: # safety check to catch activities with missing coordinate data if not parser.latitude_list or not parser.longitude_list: return None coordinates = list(zip(parser.latitude_list, parser.longitude_list)) # call to rust section = find_fastest_section(distance, parser.timestamps_list, coordinates) return GenericBestSection( start=section.start, end=section.end, distance=distance, max_value=round(section.velocity, 2), kind="fastest", )
import folium from pathlib import Path from sportgems import parse_fit_data, find_fastest_section # desired fastest sections to parse, note larges must come first in # order to be able to render the smaller sections on top of the larger ones sections = [5000, 3000, 2000, 1000] colors = ["yellow", "blue", "green", "red"] if __name__ == "__main__": fit_file = Path(".").parent / "tests" / "data" / "2019-09-14-17-22-05.fit" fit_data = parse_fit_data(str(fit_file)) coords = [] for coordinate in fit_data.coordinates: if coordinate[0] > 0 and coordinate[1] > 0: coords.append((coordinate[0], coordinate[1])) trace = folium.PolyLine(coords, color="black") map = folium.Map(location=fit_data.coordinates[300], zoom_start=15) trace.add_to(map) for i in range(len(sections)): fs = find_fastest_section(sections[i], fit_data.times, fit_data.coordinates) fs_coords = coords[fs.start:fs.end] fs_poly = folium.PolyLine(fs_coords, color=colors[i]) fs_poly.add_to(map) output_file = "map.html" map.save(output_file) print(f"saved map to {output_file}, can be viewed in browser")