Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpx export #993

Merged
merged 3 commits into from
Dec 22, 2020
Merged

Gpx export #993

merged 3 commits into from
Dec 22, 2020

Conversation

ayonix
Copy link
Contributor

@ayonix ayonix commented Oct 10, 2020

The current prototype exposes an endpoint to download a drive as a gpx file.
The drive details dashboard would have a link to the endpoint, so you could directly download the file from the dashboard.

As a note: I don't exactly know the details and features of GPX but as a minimal solution a list of trackpoints should be sufficient.

This is an effort to implement #722

Todos:

  • Test the endpoint/view

@ayonix ayonix marked this pull request as draft October 10, 2020 11:49
@adriankumpf
Copy link
Collaborator

Cool! I really like the simplicity of the integration with the dashboard.

@adriankumpf adriankumpf added the WIP Work in progress label Oct 14, 2020
@ayonix ayonix marked this pull request as ready for review October 27, 2020 13:27
@ayonix
Copy link
Contributor Author

ayonix commented Oct 27, 2020

I think it might be tested enough now, but as always, if you have any concerns, let me know :)

In the future it might be better to have a real gpx library/implementation, since i'm really not sure what I'm breaking with this.
Also the newlines take some unneeded space, but this should be easy to fix

@adriankumpf adriankumpf removed the WIP Work in progress label Oct 30, 2020
@ayonix
Copy link
Contributor Author

ayonix commented Dec 13, 2020

Is there anything I should do or you want to have improved? :)

Copy link
Collaborator

@adriankumpf adriankumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. The changes looks very good! 🙌 I only noticed one small thing regarding the sorting, which can cause drives to look like this:

Screenshot 2020-12-22 at 16 45 54

alias TeslaMate.Repo

def gpx(conn, %{"id" => id}) do
drive = Repo.get(Drive, id) |> Repo.preload(:positions)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we cannot rely on the standard sorting:

  import Ecto.Query

  drive =
    Drive
    |> Repo.get(id)
    |> Repo.preload(positions: from(p in TeslaMate.Log.Position, order_by: p.date))

longitude: 10.0,
elevation: 200
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test the date-based sorting, a third Position with a date in the past could be inserted here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as suggested :)

Copy link
Collaborator

@adriankumpf adriankumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@LukeSkywalker993
Copy link

Hello, is it also possible to export all trips to a GPX file - i.e. my complete TeslaMate. Preferably a GPX file for every trip. The way I see it, this is currently only possible manual?

@ayonix
Copy link
Contributor Author

ayonix commented Jul 22, 2022

Yes, currently this would only be possible manually/programmatically. You could write a script that iterates over ids 1 to n, where n is the currently highest id and downloads the file under /drive/$n/gpx.
Then you'd also have one file per drive.

@LukeSkywalker993
Copy link

The the answer. Unfortunately I can't program, so I hope that an export function will come up.

@DrMichael
Copy link
Collaborator

DrMichael commented Jul 24, 2022

That caught me. Pls find attached a small python3 script. You need to install python3-psycopg2, either with sudo apt install python3-psycopg2 or with pip install psycopg2. And you must set the parameters for the database, either from environment or directly in the program.

Then you need to call it with the drive id... It writes the route to out.xml.

@DrMichael
Copy link
Collaborator

Ok, I tweeked it a bit. Now it asks for From, To and CarID. If you give an empty input, then it defaults to last 24 hours and car no 1. It now produces a track for every drive.

Output now is out.gpx. You still need to set the database parameters either by environment or manually in the code.
GetGpsTrack.zip

@LukeSkywalker993
Copy link

Unfortunately I don't understand the file. I can neither query database nor program. Wouldn't it be great to have a button to download all the tracks directly from the website with the push of a button?

For example, I downloaded all my training sessions from Apple Health as a ZIP file and then put them together and have everything directly in Google Earth. What would I like in TeslaMate.

It would also be an idea that this is installed under TRIP? You can already select the start date and end date and then the card is there. Only a new button "Export GPX" would have to be installed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants