Jonathan Eropkin KOM list





$criterion) {
$criteria[$index] = is_array($criterion)
? array_pad($criterion, 3, null)
: array($criterion, SORT_ASC, null);
}

return function($first, $second) use (&$criteria) {
foreach ($criteria as $criterion) {
// How will we compare this round?
list($column, $sortOrder, $projection) = $criterion;
$sortOrder = $sortOrder === SORT_DESC ? -1 : 1;

// If a projection was defined project the values now
if ($projection) {
$lhs = call_user_func($projection, $first[$column]);
$rhs = call_user_func($projection, $second[$column]);
}
else {
$lhs = $first[$column];
$rhs = $second[$column];
}

// Do the actual comparison; do not return if equal
if ($lhs < $rhs) { return -1 * $sortOrder; } else if ($lhs > $rhs) {
return 1 * $sortOrder;
}
}

return 0; // tiebreakers exhausted, so $first == $second
};
}

///////////////////////////////////////////////
// Function to convert seconds to hh:mi:ss
///////////////////////////////////////////////
function time_cvt($seconds) {
$t = round($seconds);
return sprintf(‘%02d:%02d:%02d’, ($t/3600),($t/60%60), $t%60);
}

///////////////////////////////////////////////
// Table headings
//////////////////////////////////////////////
echo “

\n”;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

\n”;

$pageCount = 1;

// loop though KOM pages
while (
$myKOMs = file_get_contents(“https://www.strava.com/api/v3/athletes/45340/koms?access_token=$accessToken&page=$pageCount”))
{

// Count KOMs in the latest page from the raw json
$KOMcount = substr_count($myKOMs, ‘elapsed_time’);

if ($KOMcount == 0){
break;
}

$KOMCount=0; // reset count of KOMs returned with this page

// Convert the Strava json to a PHP array
$myKOMlist_part= json_decode($myKOMs, true);
if ($pageCount == 1) {
$myKOMlist_full = $myKOMlist_part; // create the full list array. First time through only.
}
else
{
// Merge the latest page in with previous pages
$myKOMlist_full = array_merge($myKOMlist_full, $myKOMlist_part);
}

$pageCount++; // increment page counter

} // end while loop

//usort($myKOMlist_full, make_comparer(‘start_date’));

$count = 0;
foreach ($myKOMlist_full as $KOM) {
// $KOMCount++ ;
$count++;
if ($count == $KOMcount){
echo “BREAKER, BREAKER\n”;
break;
}

echo “

\n”;
$url = ‘‘ .$KOM[“name”] . ‘‘;
echo “

\n”;
echo “

\n”;
echo “

\n”;
echo “

\n”;
echo “

\n”;

echo “

\n”;
$pageCount++; // increment page counter
}
echo “

“.”Segment”.” “.”Ave. Power”.” “.”Elapsed Time”.” “.”Distance (km)”.” “.”Date”.”
“.$url.” “.number_format($KOM[“average_watts”]).” “.time_cvt($KOM[“elapsed_time”]).” “.number_format($KOM[“distance”]/1000,1).” “.substr($KOM[“start_date”],0,10).”

\n”;

?>