PHP code example of duckfusion / waddle

1. Go to this page and download the library: Download duckfusion/waddle 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/ */

    

duckfusion / waddle example snippets



$parser = new \Waddle\Parsers\TCXParser();
$activity = $parser->parse('/path/to/activity.tcx');


$parser = new \Waddle\Parsers\TCXParser();
$activity = $parser->parse('/path/to/activity.tcx');

// Get some key metrics
$totalDistance = $activity->getTotalDistance(); # In metres, e.g. 1000
$totalDuration = $activity->getTotalDuration(); # In seconds, e.g. 255
$totalCalories = $activity->getTotalCalories(); # e.g. 100

// Convert those metrics into more human-readable values
$totalDistanceInMiles = \Waddle\Converter::convertMetresToMiles($totalDistance); # e.g. 0.62
$totalDurationInHoursMinutesSeconds = \Waddle\Converter::convertSecondsToHumanReadable($totalDuration); # e.g. 00:04:15

$parser = new \Waddle\Parsers\TCXParser();
$parser = new \Waddle\Parsers\GPXParser();
$parser = new \Waddle\Parsers\PWXParser();
$parser = new \Waddle\Parsers\CSVParser();

// Get the average speed in MPH
$averageSpeedInMPH = $activity->getAverageSpeedInMPH();

// Calculate the MET score
$metScore = \Waddle\Calculators\CalorieCalculator::calculateMETFromMPH($averageSpeedInMPH);

// Get the weight of the person in KG
$weightInKG = 75;

// Get the duration and convert to hours decimal
$durationInHumanReadable = \Waddle\Converter::convertSecondsToHumanReadable($activity->getTotalDuration());
$durationSplit = explode(":", $durationInHumanReadable);
$durationInDecimalHours = \Waddle\Converter::convertHoursMinutesSecondsToDecimal($durationSplit[0], $durationSplit[1], $durationSplit[2]);

// Calculate the calories burned
$caloriesBurned = \Waddle\Calculators\CalorieCalculator::calculateCaloriesBurned($metScore , $weightInKG, $durationInDecimalHours );