Source for file int_training.php
Documentation is available at int_training.php
* Interval training parse and display functions
* @author Jean-Philippe Brunon <jp75018@free.fr>
* @copyright 2007-2009 Jean-Philippe Brunon
* @license http://www.opensource.org/licenses/gpl-license.php GPL
* @version $Id: int_training.php 22 2009-03-05 23:58:02Z jp75018 $
* Parse interval training expression
* @param string $expr Interval training expression as in {F=<expr>}
* @return array Array of interval training elements (index from 0) :
* - repeat_nb : Nb of repetitions (integer >= 1)
* - work_distance : Distance of effort in meters
* - work_duration : Duration of effort in seconds
* - reco_distance : Distance of recovery in meters
* - reco_duration : Duration of recovery in seconds
* Work and recovery are defined either by distance
* (usual for work) or duration.
* If recovery is empty and repeat_nb > 1 => recovery
* If work is empty and repeat_nb = 1 => recovery only
* Return null if expression is not valid.
// 1. Split into components separated by '+'
for ($i =
0; $i <
count($expr_tab); $i++
)
$expr =
trim($expr_tab[$i]);
// 2. Extract nb of repetitions
if (preg_match('/^([0-9]+)\s*[x\*]\s*[\(\[]?([^\)\]]+)[\)\]]?$/i',
$expr =
trim($matches[2]);
if (preg_match('/^R\s*=(.*)$/i', $expr, $matches))
{ $expr_reco =
trim($matches[1]); }
// 4. Work / Optional recovery ?
if (preg_match('/^([^\/]+)(\/(\s*R\s*=)?(.*))?$/i', $expr, $matches))
$expr_work =
trim($matches[1]);
{ $expr_reco =
trim($matches[4]); }
$training['repeat_nb'] =
$nb_rep;
{ $training['work_distance'] =
$distance; }
{ $training['work_duration'] =
$duration; }
{ $training['reco_distance'] =
$distance; }
{ $training['reco_duration'] =
$duration; }
* Parse interval training work or recovery element (separated by '+' in
* interval training expression
* @param string $expr Interval training element
* @param integer &$distance Distance of work or recovery in meters if
* element is a distance, else null
* @param integer &$duration Duration of work or recovery in seconds if
* element is a duration, else null
* @return boolean true if element is valid, else false
if (preg_match('/^(([0-9]+)([\.,]([0-9]+))?\s*(m|k|km)?|([0-9]+)\s*[\'m]|([0-9]+)\s*[\"s]|([0-9]+)\s*[\'m:]\s*([0-9]+)\s*[\"s]?)$/i',
$distance = (float)
($matches[2] .
'.' .
$matches[4]);
$distance =
round($distance);
return $distance ?
true :
false;
{ $duration =
60 *
$matches[6]; } // Minutes only
{ $duration =
$matches[7]; } // Seconds only
if (($matches[8] !=
'') &&
($matches[9] !=
''))
{ $duration =
60 *
$matches[8] +
$matches[9]; } // Minutes and seconds
return $duration ?
true :
false;
* Format interval training expression for nice output
* @param array $train_tab Array of interval training components
* @return string Formatted interval training
for ($i =
0; $i <
count($train_tab); $i++
)
{ $train_str .=
' + '; }
if ($train_tab[$i]['repeat_nb'] >
1)
{ $train_str .=
$train_tab[$i]['repeat_nb'] .
' x ['; }
if ($train_tab[$i]['work_distance'] ||
$train_tab[$i]['work_duration'])
if ($train_tab[$i]['work_distance'])
{ $train_str .=
round($train_tab[$i]['work_distance']) .
'm'; }
if ($train_tab[$i]['work_duration'])
$sec =
$train_tab[$i]['work_duration'];
{ $str_elapsed =
sprintf("%d'%02d\"", floor($sec /
60), $sec %
60); }
{ $str_elapsed =
floor($sec/
60) .
'\''; }
{ $str_elapsed =
sprintf("%02d\"", $sec); }
$train_str .=
$str_elapsed;
if ($train_tab[$i]['reco_distance'] ||
$train_tab[$i]['reco_duration'])
if ($train_tab[$i]['reco_distance'] ||
$train_tab[$i]['reco_duration'])
$train_str .=
$GLOBALS['str_abbr_recovery'] .
'=';
if ($train_tab[$i]['reco_distance'])
{ $train_str .=
round($train_tab[$i]['reco_distance']) .
'm'; }
$sec =
$train_tab[$i]['reco_duration'];
{ $str_elapsed =
sprintf("%d'%02d\"", floor($sec /
60), $sec %
60); }
{ $str_elapsed =
floor($sec/
60) .
'\''; }
{ $str_elapsed =
sprintf("%02d\"", $sec); }
$train_str .=
$str_elapsed;
if ($train_tab[$i]['repeat_nb'] >
1)
{ $train_str .=
'/' .
$GLOBALS['str_abbr_recovery'] .
'=?'; }
if ($train_tab[$i]['repeat_nb'] >
1)
Documentation generated on Sat, 28 Mar 2009 23:15:30 +0000 by phpDocumentor 1.4.1