+11
Completed

Refactor Elevation Logging

rfmurphy81 8 years ago updated by James 5 years ago 20

DescriptionRather than displaying the elevation difference between the starting and ending location of a drive, it would be beneficial to determine the cumulative gain and loss throughout the drive. This would require tracking the elevation at each data point and having a summary field to determine Elevation Gain and a separate summary field to determine Elevation Loss.

This could be summarized in each drive record, plus the daily summary and possibly other places. This would be helpful to display in the leader boards, too.
Additional InformationIf you plan to use the Google Maps Elevation API, it appears that you're limited to 2,500 calls per day without having to pay. It may be smart to create a separate table for Long/Lat data and the associated elevation for that location, then create a separate service to ping the Google API to fill in any missing data within the limits. Perhaps this new TeslaFi elevation service can work every day to fill in all GPS locations captured thus far until you feel comfortable with the number of new GPS locations being less than the 2,500 limit per day, then you can start displaying the data on the site. Then the service, which is running every day, can fill in all incoming GPS locations that don't already have an elevation associated to it until it reaches the 2,500 limit for the day, then it starts over the next day.

https://developers.google.com/maps/documentation/elevation/intro

Some other possible tools:
* http://vdatum.noaa.gov/
* http://viewer.nationalmap.gov/tnmaccess/api/services? (there appears to be an Elevation API to hook into)
* https://open.mapquestapi.com/elevation/
* https://msdn.microsoft.com/en-us/library/jj158959.aspx
* http://www.programmableweb.com/api/usgs-elevation-query-service

int[] elevationData;


int cumulativeGain = 0;

int cumulativeLoss = 0;

int priorElevation = elevationData[0];

for (int elevation : elevationData) {

int difference = elevation - priorElevation;

    if (difference > 0) {

        cumulativeGain += difference;

    } else {

        cumulativeLoss += difference;

    }

    priorElevation = elevation;

}

+1
Completed

I'm going to mark this complete.  If anyone has any insight on calculating cumulative elevation gain/loss from a set of elevation data points please let me know.

Thanks for getting around to implementing this.

Thanks for the formula.  :-)

Does anyone know of a calculation to determine cumulative elevation gain/loss from a set of elevation data points?  I can't seem to find anything from searching.

I've been seeing a strange screen painting bug in the elevation graphs while the main Drives page is being built.


When the Drives page is first displayed, it looks pretty normal:


But then, as elevation graphs keep being generated for later drives, the individual drive blocks keep getting longer and longer (each block is repeatedly painted), so that soon they paint both under and over the summary blocks.  Here is the same screen 30 seconds later:




Interesting.  What browser and OS are you using?

Seems to work fine now for the pages with the individual drive.


But the day view is missing the graph for old drives.

Works fine for me for current drives, but not for older ones. I tried #2019 and 2020, after changing the setting.


Both are totally flat the whole time, with one big spike at the end.

+1

It looks like I'm requesting too many elevation requests from Google.  I should have a new API Key from them with unlimited requests today.

+1

I should say elevation is included.  Cumulative Gain/Loss hasn't been included yet.

+1

I've rolled this out to car id's under 2000.  If anyone notices any issues please let me know.


Thanks,


James

+1

I should have elevation data stored into every new data point starting on Monday.  


In the meantime for older drives you can enable "Show Elevation For Older Drives" in settings->account->preferences.  The load time will be slower depending on the length of the drive for the first load.  Newer drives that contain the elevation data will be instant.



I don't think the API can return elevation, so it would have to be cross checked via Google maps or some such.

Sample output from the streaming interface:


curl "https://streaming.vn.teslamotors.com/stream/157xxxxxxx/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,est_range"
1526028495799,,21246.7,67,403,171,47.371671,16.116316,1,P,166
1526028498549,0,21246.7,67,403,171,47.371671,16.116316,1,P,166

first field is a timestamp (miliseconds since 1.1.1970 GMT), 403 is my current elevation

Please have another look at the first reply; In addition to the (fairly well documented) Standard API there's also the streaming API. To use it you need a token that you get from the standard API. The app uses the streaming API if you watch the map view to show changing position/speed of your car; one call to the streaming API returns a stream of multiple records. This streaming API can actually return elevation data.

As it's a seperate interface, implementing this would not come "free", it requies additional calls to the streaming API - obviously only if the standard API indicates the car is in motion.

I too would like to see the elevation on the drive details graph

If the Tesla API returns the elevation with the other data, then this seems like a no brainer to me! TeslaLog did a good job of handling this so it'd be great to see it implemented here. 

+1

Another option for tracking elevation: the Tesla streaming  API can return elevation data in addition to latitude and longitude .information.

https://streaming.vn.teslamotors.com/stream/{VEHICLE_ID}/?values={VALUES} 


where {VALUES} is a coma delimited list of these fields: 

speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,est_range


See https://teslamotorsclub.com/tmc/posts/2255036/ for a good summary; beware that the description of the Authentication header is wrong in this post, the correct value is <teslaaccount>:<streamingtoken> (base64 encoded).