PHP code example of adriangibbons / php-fit-file-analysis
1. Go to this page and download the library: Download adriangibbons/php-fit-file-analysis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adriangibbons / php-fit-file-analysis example snippets
FITFileAnalysis
= new adriangibbons\phpFITFileAnalysis('fit_files/my_fit_file.fit');
= new adriangibbons\phpFITFileAnalysis('fit_files/my_fit_file.fit');
$pFFA->data_mesgs
// Contains an array of all heart_rate data read from the file, indexed by timestamp
$pFFA->data_mesgs['record']['heart_rate']
// Contains an integer identifying the number of laps
$pFFA->data_mesgs['session']['num_laps']
// Option 1. Iterate through the $pFFA->data_mesgs array
foreach ($pFFA->data_mesgs as $mesg_key => $mesg) { // Iterate the array and output the messages
echo "<strong>Found Message: $mesg_key</strong><br>";
foreach ($mesg as $field_key => $field) { // Iterate each message and output the fields
echo " - Found Field: $mesg_key -> $field_key<br>";
}
echo "<br>";
}
// Option 2. Show the debug information
$pFFA->showDebugInfo(); // Quite a lot of info...
// Get Max and Avg Speed
echo "Maximum Speed: ".max($pFFA->data_mesgs['record']['speed'])."<br>";
echo "Average Speed: ".( array_sum($pFFA->data_mesgs['record']['speed']) / count($pFFA->data_mesgs['record']['speed']) )."<br>";
// Put HR data into a JavaScript array for use in a Chart
echo "var chartData = [";
foreach ($pFFA->data_mesgs['record']['heart_rate'] as $timestamp => $hr_value) {
echo "[$timestamp,$hr_value],";
}
echo "];";
// Access data stored within the private class variable $enum_data
// $pFFA->enumData($type, $value)
// e.g.
echo $pFFA->enumData('sport', 2)); // returns 'cycling'
echo $pFFA->enumData('manufacturer', $this->data_mesgs['device_info']['manufacturer']); // returns 'Garmin';
echo $pFFA->manufacturer(); // Short-hand for above
$options = ['fix_data' => ['all']]; // fix cadence, distance, heart_rate, lat_lon, power, and speed data
$options = ['fix_data' => ['cadence', 'distance']]; // fix cadence and distance data only
$options = ['fix_data' => ['lat_lon']]; // fix position data only
// Do not use code, just for demonstration purposes
var_dump($pFFA->data_mesgs['record']['temperature']); // ['100'=>22, '101'=>22, '102'=>23, '103'=>23, '104'=>23];
var_dump($pFFA->data_mesgs['record']['distance']); // ['100'=>3.62, '101'=>4.01, '104'=>10.88];
$date_FIT = new DateTime('1989-12-31 00:00:00', new DateTimeZone('UTC'));
$date_UNIX = new DateTime('1970-01-01 00:00:00', new DateTimeZone('UTC'));
$diff = $date_FIT->getTimestamp() - $date_UNIX->getTimestamp();
echo 'The difference (in seconds) between FIT and Unix timestamps is '. number_format($diff);