LEADS icon indicating copy to clipboard operation
LEADS copied to clipboard

Add Historical Traces to the Map

Open ATATC opened this issue 1 year ago • 12 comments

To better analyze and improve driving strategies, we want the historical traces to be displayed as a floating layer on the map. A detailed introduction will be later added in a periodic report.

ATATC avatar Mar 07 '24 06:03 ATATC

See https://github.com/ProjectNeura/LEADS/blob/master/docs/reports/2024-03-07.md.

ATATC avatar Mar 07 '24 06:03 ATATC

Here's the .gpx data for the 2023 Waterloo EV Challenge downloaded from Strava. You will need to scrub the data to get the course route with and without the pit. There's some extraneous data as well but I am sure you will be able to pick that out. Here's the Strava link if you want to view the data on their app but it's easy enough to upload to google earth/maps.

ATATC avatar Mar 07 '24 16:03 ATATC

See https://github.com/ProjectNeura/LEADS/blob/master/docs/reports/2024-03-07.md.

@HaydenHour Please see one of us if you have any questions about this task.

qmascarenhas avatar Mar 07 '24 17:03 qmascarenhas

Accidentally mentioned this issue. It should be #73.

ATATC avatar Mar 15 '24 22:03 ATATC

@HaydenHour Any update on this? Can you give us some more information on where you're stuck?

qmascarenhas avatar Apr 01 '24 20:04 qmascarenhas

@ATATC @qmascarenhas Sorry I did not post sooner, I did not have access to my laptop over the weekend. It appears that the code is hitting an issue when trying to read the GPX file (specifically regarding the parse function on line 10). This is my code below:

import gpxpy

def gpx_to_custom_csv(gpx_file_path, output_csv_file_path):

    # Open GPX file
    with open(gpx_file_path, 'r') as gpx_file:

        #Issue appears to be here with the parse
        gpx = gpxpy.parse(gpx_file)

        # write data in CSV format
    with open(output_csv_file_path, 'w') as csv_file:
        for track in gpx.tracks:
            for segment in track.segments:
                for point in segment.points:
                    # Write latitude and longitude separated by semicolon
                    csv_file.write(f"{point.latitude};{point.longitude},")

# file paths:
gpx_file_path = "C:/Users/hayde/OneDrive/VeC/Waterloo_Electric_Vehicle_Challenge_2023.gpx"
output_csv_file_path = "C:/Users/hayde/OneDrive/VeC/VEC2023_CSV.csv"
gpx_to_custom_csv(gpx_file_path, output_csv_file_path)

HaydenHour avatar Apr 04 '24 12:04 HaydenHour

Please provide the error message.

ATATC avatar Apr 04 '24 14:04 ATATC

This works for me.

ATATC avatar Apr 04 '24 15:04 ATATC

Oh, that's weird. So did it create a new file with the right formatting?

HaydenHour avatar Apr 05 '24 00:04 HaydenHour

I haven't tested the file part. I replaced it with print(). But I believe write overwrites the file. There should be an appending function.

ATATC avatar Apr 05 '24 02:04 ATATC

Btw please fork the repository to be ready to merge your contributions.

ATATC avatar Apr 05 '24 02:04 ATATC

I'm gonna finish this feature (including auto corner speed marking) for the website this week.

ATATC avatar May 13 '24 20:05 ATATC

@qmascarenhas Now you can directly import the previously recorded data onto the website and move your mouse close to the corners to check the data at that point. image image

ATATC avatar May 14 '24 02:05 ATATC

This is excellent @ATATC !

qmascarenhas avatar May 14 '24 12:05 qmascarenhas

@HaydenHour Sorry for the wrong instructions previously. I had some misunderstanding about CSV files. I'll provide a new handout later.

ATATC avatar May 14 '24 15:05 ATATC

Result

@HaydenHour Take a look if you want.

2023.csv

from gpxpy import parse
from leads.data_persistence import CSVCollection


def gpx_to_custom_csv(gpx_file_path: str, output_csv_file_path: str) -> None:
    with open(gpx_file_path, 'r') as gpx_file:
        gpx = parse(gpx_file)
    csv = CSVCollection(output_csv_file_path, ("t", "voltage", "speed", "front_wheel_speed", "rear_wheel_speed",
                                               "forward_acceleration", "lateral_acceleration", "mileage", "gps_valid",
                                               "gps_ground_speed", "latitude", "longitude"))
    for track in gpx.tracks:
        for segment in track.segments:
            for point in segment.points:
                csv.write_frame(int(point.time.timestamp() * 1000), *((None,) * 9), point.latitude, point.longitude)


gpx_to_custom_csv("Waterloo_Electric_Vehicle_Challenge_2023.gpx", "data/2023.csv")

ATATC avatar May 15 '24 02:05 ATATC

Result

An enhanced version with inferred speeds.

2023.csv

from gpxpy import parse
from leads.data_persistence import CSVCollection, DEFAULT_HEADER
from leads.data import dlat2meters, dlon2meters


def gpx_to_custom_csv(gpx_file_path: str, output_csv_file_path: str) -> None:
    with open(gpx_file_path, 'r') as gpx_file:
        gpx = parse(gpx_file)
    csv = CSVCollection(output_csv_file_path, DEFAULT_HEADER)
    # prev time
    t_0 = None
    # prev latitude
    lat_0 = None
    # prev longitude
    lon_0 = None
    for track in gpx.tracks:
        for segment in track.segments:
            for point in segment.points:
                t = point.time.timestamp()
                lat = point.latitude
                lon = point.longitude
                if t_0 is None or lat_0 is None or lon_0 is None:
                    t_0, lat_0, lon_0 = t, lat, lon
                    csv.write_frame(int(t * 1000), *((None,) * 7), True, None, lat, lon)
                    continue
                # dt
                dt = t - t_0
                dlat = lat - lat_0
                dlon = lon - lon_0
                # dy
                dy = dlat2meters(dlat)
                # dx
                dx = dlon2meters(dlon, .5 * (lat_0 + lat))
                # c
                hyp = (dy ** 2 + dx ** 2) ** 0.5
                # v
                v = hyp / dt
                # m/s to km/h
                v *= 3.6

                t_0 = t
                lat_0 = lat
                lon_0 = lon

                csv.write_frame(int(t * 1000), None, v, v, v, *((None,) * 3), True, v, lat, lon)


gpx_to_custom_csv("Waterloo_Electric_Vehicle_Challenge_2023.gpx", "data/2023.csv")

ATATC avatar May 15 '24 03:05 ATATC