* Demonstration of the phpFITFileAnalysis class using Twitter Bootstrap framework
 * https://github.com/adriangibbons/phpFITFileAnalysis
 *
 * Not intended to be demonstration of how to best use Google APIs, but works for me!
 *
 * If you find this useful, feel free to drop me a line at Adrian.GitHub@gmail.com
 */
require __DIR__ . '/../src/phpFITFileAnalysis.php';
require __DIR__ . '/libraries/PolylineEncoder.php';
// https://github.com/dyaaj/polyline-encoder
require __DIR__ . '/libraries/Line_DouglasPeucker.php';
// https://github.com/gregallensworth/PHP-Geometry
try {
    $file = '/fit_files/mountain-biking.fit';
    $options = [];
    $pFFA = new adriangibbons\phpFITFileAnalysis(__DIR__ . $file, $options);
} catch (Exception $e) {
    echo 'caught exception: ' . $e->getMessage();
    die;
}
// Google Static Maps API
$position_lat = $pFFA->data_mesgs['record']['position_lat'];
$position_long = $pFFA->data_mesgs['record']['position_long'];
$lat_long_combined = [];
foreach ($position_lat as $key => $value) {
    // Assumes every lat has a corresponding long
    $lat_long_combined[] = [$position_lat[$key], $position_long[$key]];
}
$delta = 0.0001;
do {
    $RDP_LatLng_coord = simplify_RDP($lat_long_combined, $delta);
<?php

/**
 * Demonstration of the phpFITFileAnalysis class using Twitter Bootstrap framework
 * https://github.com/adriangibbons/phpFITFileAnalysis
 *
 * If you find this useful, feel free to drop me a line at Adrian.GitHub@gmail.com
 */
require __DIR__ . '/../src/phpFITFileAnalysis.php';
try {
    $file = '/fit_files/power-analysis.fit';
    $options = [];
    $pFFA = new adriangibbons\phpFITFileAnalysis(__DIR__ . $file, $options);
    // Google Time Zone API
    $date = new DateTime('now', new DateTimeZone('UTC'));
    $date_s = $pFFA->data_mesgs['session']['start_time'];
    $url_tz = "https://maps.googleapis.com/maps/api/timezone/json?location=" . reset($pFFA->data_mesgs['record']['position_lat']) . ',' . reset($pFFA->data_mesgs['record']['position_long']) . "&timestamp=" . $date_s . "&key=AIzaSyDlPWKTvmHsZ-X6PGsBPAvo0nm1-WdwuYE";
    $result = file_get_contents("{$url_tz}");
    $json_tz = json_decode($result);
    if ($json_tz->status == "OK") {
        $date_s = $date_s + $json_tz->rawOffset + $json_tz->dstOffset;
    }
    $date->setTimestamp($date_s);
    $ftp = 329;
    $hr_metrics = $pFFA->hrMetrics(52, 185, 172, 'male');
    $power_metrics = $pFFA->powerMetrics($ftp);
    $criticalPower = $pFFA->criticalPower([2, 3, 5, 10, 30, 60, 120, 300, 600, 1200, 3600, 7200, 10800, 18000]);
    $power_histogram = $pFFA->powerHistogram();
    $power_table = $pFFA->powerPartioned($ftp);
    $power_pie_chart = $pFFA->partitionData('power', $pFFA->powerZones($ftp), true, false);
    $quad_plot = $pFFA->quadrantAnalysis(0.175, $ftp);
<?php

/**
 * Demonstration of the phpFITFileAnalysis class using Twitter Bootstrap framework
 * https://github.com/adriangibbons/phpFITFileAnalysis
 *
 * If you find this useful, feel free to drop me a line at Adrian.GitHub@gmail.com
 */
require __DIR__ . '/../src/phpFITFileAnalysis.php';
try {
    $file = '/fit_files/swim.fit';
    $options = ['units' => 'raw'];
    $pFFA = new adriangibbons\phpFITFileAnalysis(__DIR__ . $file, $options);
} catch (Exception $e) {
    echo 'caught exception: ' . $e->getMessage();
    die;
}
$units = 'm';
$pool_length = $pFFA->data_mesgs['session']['pool_length'];
$total_distance = number_format($pFFA->data_mesgs['record']['distance']);
if ($pFFA->enumData('display_measure', $pFFA->data_mesgs['session']['pool_length_unit']) == 'statute') {
    $pool_length = round($pFFA->data_mesgs['session']['pool_length'] * 1.0936133);
    $total_distance = number_format($pFFA->data_mesgs['record']['distance'] * 1.0936133);
    $units = 'yd';
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>phpFITFileAnalysis demo</title>
<?php

/**
 * Demonstration of the phpFITFileAnalysis class using Twitter Bootstrap framework
 * https://github.com/adriangibbons/phpFITFileAnalysis
 *
 * If you find this useful, feel free to drop me a line at Adrian.GitHub@gmail.com
 */
require __DIR__ . '/../src/phpFITFileAnalysis.php';
try {
    $file = '/fit_files/power-analysis.fit';
    $options = [];
    $pFFA = new adriangibbons\phpFITFileAnalysis(__DIR__ . $file, $options);
    // Google Time Zone API
    $date = new DateTime('now', new DateTimeZone('UTC'));
    $date_s = $pFFA->data_mesgs['session']['start_time'];
    $url_tz = "https://maps.googleapis.com/maps/api/timezone/json?location=" . reset($pFFA->data_mesgs['record']['position_lat']) . ',' . reset($pFFA->data_mesgs['record']['position_long']) . "&timestamp=" . $date_s . "&key=AIzaSyDlPWKTvmHsZ-X6PGsBPAvo0nm1-WdwuYE";
    $result = file_get_contents("{$url_tz}");
    $json_tz = json_decode($result);
    if ($json_tz->status == "OK") {
        $date_s = $date_s + $json_tz->rawOffset + $json_tz->dstOffset;
    }
    $date->setTimestamp($date_s);
    $crank_length = 0.175;
    $ftp = 329;
    $selected_cadence = 90;
    $json = $pFFA->getJSON($crank_length, $ftp, ['all'], $selected_cadence);
} catch (Exception $e) {
    echo 'caught exception: ' . $e->getMessage();
    die;
}
 /**
  * @expectedException Exception
  */
 public function testPower_power_partitioned_no_power()
 {
     $pFFA = new adriangibbons\phpFITFileAnalysis($this->base_dir . 'road-cycling.fit');
     $power_partioned = $pFFA->powerPartioned(350);
 }