Source for file PolarFile.class.php
Documentation is available at PolarFile.class.php
* Common Class for all Polar files
* @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: PolarFile.class.php 22 2009-03-05 23:58:02Z jp75018 $
* General configuration file
require_once ('conf/config.php');
* Interval training parse
require_once ('include/int_training.php');
* Common Class for all Polar files (ppd, pdd, hrm)
* Contains common code for Polar files parsing
* @todo Include common code to open / close file
* File name of Polar file (full pathname)
* User ID (as in database)
* @param string $fileName Polar file name (full path name)
* @param integer $userId User ID (as in database)
* Parse a block from a Polar file (buffered)
* A Block starts with a line [block_name]
* @param string &$buffer Pointer to buffer
* @param integer &$line_no Pointer to line number where to start parsing.
* It contains the line number of the end of the block on return.
* @return string Block name or null on error
if (preg_match('/^\[([^\]]+)\][\s]*$/i', $buffer[$line_no], $match))
if ($block_name ==
'hrdata')
{ $line_no =
count($buffer); }
while (($line_no <
count($buffer)) &&
(! preg_match('/^\[([^\]]+)\][\s]*$/i', $buffer[$line_no])))
* Parse note to extract contest distance or interval training expression
* Contest distance / Internal expression is in { }
* - Contest distance is D=<distance>, where <distance> is number of meters or
* <distance>m or <distance>k[m] or number of km if float number
* (contains . or ,). <distance> can be also a keyword in
* ('marathon','half','semi').
* - Interval training expression start with 'F='
* - Shoe used : S=<shoe-name>[:<distance>[k[m]]] where <distance> is initial
* distance for shoe (in km if not specified)
* @param string $note Exercise note
* @param string &exercise_type exercise type : 'contest' for contest,
* 'int_training' for interval training, else 'training'.
* @param integer &$distance If 'contest' : official distance in meters
* @param array &$int_training If 'int_training' :
* 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
* @param array &$options :
* Associative array of options :
* - shoe : Shoe name (ID)
* - shoe_ini_dist : Shoe optional init distance (meters)
* - footpod_id : Foot pod ID (1 digit, default : 1)
* - footpod_batt : Battery initial use (sec x10)
* @return string Note with { } distance and options removed
function _parse_note($note, &$exercise_type, &$distance, &$int_training,
$exercise_type =
'training';
// 1. Extract exercise type in { }
if (preg_match('/^(.*){\s*([df])\s*=?([^}]+)}(.*)$/i', $note, $matches))
$note =
trim($matches[1]);
if ($matches[1] &&
$matches[4])
$note .=
trim($matches[4]);
case 'd' :
// Contest => Find out exact distance
$dist_str =
trim($matches[3]);
if (preg_match('/^((([0-9]+)([\.,]([0-9]+))?\s*(m|k|km)?)|marathon|half([\-\s]*marathon)?|semi([\-\s]*marathon)?)$/i',
$distance = (float)
($matches[3] .
'.' .
$matches[5]);
$distance =
round($distance);
{ $exercise_type =
'contest'; }
case 'f' :
// Interval training
{ $exercise_type =
'int_training'; }
// 2. Extract shoe + optional initial nb of km in last { }
if (preg_match('/^(.*){\s*s\s*=([^}:\s]+)(\s*:\s*(([0-9]+)([\.,]([0-9]+))?\s*(k|km)?))?}(.*)$/i', $note, $matches))
$note =
trim($matches[1]);
if ($matches[1] &&
$matches[9])
$note .=
trim($matches[9]);
// Shoe => Get shoe name + optional initial nb of km
$options['shoe'] =
$shoe_str;
$shoe_dist = (float)
($matches[5] .
'.' .
$matches[7]);
$shoe_dist =
round(1000 *
$shoe_dist);
$options['shoe_ini_dist'] =
$shoe_dist;
// 3. Extract foot pod + optional initial nb of hours in last { }
$options['footpod_id'] =
1; // Default foot pod
if (preg_match('/^(.*){\s*p\s*(=\s*([1-9]))?(\s*:\s*(([0-9]+)([\.,]([0-9]+))?\s*(h)?))?}(.*)$/i', $note, $matches))
$note =
trim($matches[1]);
if ($matches[1] &&
$matches[10])
$note .=
trim($matches[10]);
// Pod => Get optional pod ID + optional initial nb of hours
{ $pod_id =
$matches[3]; }
$options['footpod_id'] =
$pod_id;
// Numeric number of hours
$pod_battery = (float)
($matches[6] .
'.' .
$matches[8]);
$pod_battery =
round(36000 *
$pod_battery);
$options['footpod_batt'] =
$pod_battery;
Documentation generated on Sat, 28 Mar 2009 23:16:30 +0000 by phpDocumentor 1.4.1