Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

How do you parse a Fit file for the purpose of analyzing the metrics?

Rank

Total Posts: 5

Joined 2020-03-10

PM

Hello folks,

This is my first time posting here.

I'm writing an app in Java that analyzes data recorded by my Garmin Edge 810 bicycle computer. I was able to import metrics stored in TCX files. The metrics include time, latitude, longitude, distance, altitude, heart rate, power, speed and cadence. My goal now, is to import the same data from a Fit file, as this is the native format of Garmin devices. I've been searching all over the internet and I believe this is the right place to find a solution. I was able to download the latest FitSDK. I'm assuming I should be looking into decoding a fit file, but I've yet to find the code that allows me to decode the metrics I've mentioned.

Specifically, I will be populating an array list with the metrics, from start to finish. My code will use this array list of data to perform an analysis on it.

Which class should I be using in the SDK and what are some examples? Can someone please point me in the right direction?

TIA,

grecinos      
Rank

Total Posts: 15

Joined 2020-02-05

PM

Grecinos,

It sounds like you already downloaded the FIT SDK, if not you can find it here:
https://www.thisisant.com/developer/resources/downloads/#software_tab

You mentioned Java, so I will assume that you already have it installed. In the FIT SDK you can find an example of how to decode a FIT file using Java here:
/java/com/garmin/fit/examples/decode.java

You can compile and run the code from the terminal. In a terminal from the FIT SDK's Java folder execute these two commands to compile and then run the decode example, passing a file name to the second command.

javac com/garmin/fit/examples/DecodeExample.java
java com/garmin/fit/examples/DecodeExample ../examples/Activity.fit

You should see quite a bit of information displayed in the terminal. You can also use an IDE.

The files recorded on your EDGE810 are known as Activity files, which is why they are found in the /Garmin/Activities folder on the device. In the FIT SDK is a document called "D00001309 FIT File Types Description Rev 2.2.pdf". Section 9 "Activity File" talks about all of the data messages that you can expect in an activity file. The decode example already has a message listener for Record messages, which is where the data that you are looking for is. Checkout the javadocs that come with the FIT SDK for what other properties are found in the Record message. 

The docs can be found here: /java/doc/index.html

Good luck and let me know how it goes.

Ben      
Rank

Total Posts: 5

Joined 2020-03-10

PM

Hi Ben,

Thanks for the response. I was able to compile and run the examples you mentioned. Definitely what I was looking for. The examples show how to get the values of some of the metrics I'm interested in. I need to do the research to determine how to get the remaining. It looks promising. I'll post questions here if I get stuck.

Much appreciated,

George      
Rank

Total Posts: 5

Joined 2020-03-10

PM

Hi Ben,

I made some progress with the Java Fit file decoder as per your reply .

I spent the better half of the weekend studying the code responsible for decoding a fit file. I made progress, but I'm a bit confused how it works. I was expecting a conventional loop (For, While, etc) in order to iterate through the data within the Fit file. It seems to loop through the data by other means. I was able to locate the code that acquires the data. There are a bunch of "getters" . The getters work like a charm. The other thing that confuses me are the data types returned by some of the getters. In particular the Latitude and Longitude being of type integer. I'm not sure how to convert them to floats, yet. I'm assuming the distance is measured in meters. The altitude shows double digits, I live at about 3700 ft of elevation, so some inconsistency there. The data seems inconsistent with that of its TCX counterpart. Also, the latitude, longitude and altitude values should show almost the same for the first and last records, as I always start and finish at the same place, when I go for a bike ride. I'll integrate the decoder into my Java app as soon as I iron out the details I'm having issues with.

Please let me know if you have any suggestions?

Regards,

George      
Rank

Total Posts: 15

Joined 2020-02-05

PM

The FIT SDK handles reading the file and looping through the data. Message listeners are used in the client to receive data as it is decoded. In DecodeExample.java. a number of message listeners are added, each with its own callback method that receives the data. The data you are looking for is in the Record messages. You may also want to add listeners and callbacks for Lap and Session messages. Session is where the summary data for the entire activity is. Things like sport type, start time, distance, average HR, etc. Section 9 "Activity File" in the "D00001309 FIT File Types Description Rev 2.2.pdf" document lists the message types you can expect.

The units for each property are given in the javadocs that come with the SDK, look at FITSDK/java/doc/index.html and scroll down to RecordMesg. Latitude and Longitude are in semicircles and can be converted to/from degrees. Storing the data as an unsigned 32 bit integer provides a higher level of precision than could be obtained with a float and without having to use a 64 bit double. Altitude is in meters. The TCX file you are using for reference is not the original file that was recorded on the device, and something may have been changed or lost in translation. The method you are using to get the TCX file may be applying elevation correction, and then the two files may not match.

This is the semicircles to/from degrees calc.
degrees = semicircles * ( 180 / 2^31 )
semicircles = degrees * ( 2^31 / 180 )

Ben
     
Rank

Total Posts: 5

Joined 2020-03-10

PM

Hi Ben,

Thanks for the clarification. The latitude and longitude values make sense to me now. I was able to confirm the results with a fit file that has "good" data. I performed the conversion, entered the values on google maps, and it put the marker precisely at my doorstep. All of the other values seem to be accurate. My next objective is to be able to loop through the data with minimal code.

Cheers,

George      
Rank

Total Posts: 5

Joined 2020-03-10

PM

Update on my project:

Now that I am able to retrieve the metrics I need (from fit files), and after making a sandbox to confirm the accuracy of the data, I created a Fit file decoder class that I am now using with my analysis program. The results I'm getting is very promising. It corresponds with the results I was getting with my TCX files. If I have any other questions, I'll be sure to post them here. Thanks for your assistance.

Cheers,

George