| Code Coverage | ||||||||||
| Classes and Traits | Functions and Methods | Lines | ||||||||
| Total |  | 100.00% | 1 / 1 |  | 100.00% | 5 / 5 | CRAP |  | 100.00% | 47 / 47 | 
| TrackMetaData |  | 100.00% | 1 / 1 |  | 100.00% | 5 / 5 | 17 |  | 100.00% | 47 / 47 | 
| __construct($track = null) |  | 100.00% | 1 / 1 | 1 |  | 100.00% | 2 / 2 | |||
| __get($varName) |  | 100.00% | 1 / 1 | 2 |  | 100.00% | 3 / 3 | |||
| __set($varName, $value) |  | 100.00% | 1 / 1 | 2 |  | 100.00% | 4 / 4 | |||
| addPlugin($plugin) |  | 100.00% | 1 / 1 | 3 |  | 100.00% | 9 / 9 | |||
| reCalculate($track) |  | 100.00% | 1 / 1 | 9 |  | 100.00% | 29 / 29 | |||
| <?php | |
| /** | |
| * | |
| */ | |
| namespace aae\geo { | |
| /** | |
| * @author Axel Ancona Esselmann | |
| * @package aae\geo | |
| */ | |
| class TrackMetaData { | |
| public $segmentTimes = array(); | |
| public $segmentDistances = array(); | |
| public $segmentElevationChanges = array(); | |
| public $segmentSpeeds = array(); | |
| protected $virtualVariables = array(); | |
| private $plugins = array(); | |
| private $calculator = null; | |
| public function __construct($track = null) { | |
| $this->calculator = new Calculator(); | |
| } | |
| public function __get($varName) { | |
| if (array_key_exists($varName, $this->virtualVariables)) { | |
| return $this->virtualVariables[$varName]; | |
| } | |
| } | |
| public function __set($varName, $value) { | |
| if (array_key_exists($varName, $this->virtualVariables)) { | |
| $this->virtualVariables[$varName] = $value; | |
| } | |
| return $this; | |
| } | |
| public function addPlugin($plugin) { | |
| $plugin->metaDataObject = $this; | |
| $this->plugins[get_class($plugin)] = $plugin; | |
| if (is_array($plugin->varName)) { | |
| foreach ($plugin->varName as $varName) { | |
| $this->virtualVariables[$varName] = null; | |
| } | |
| } else { | |
| $this->virtualVariables[$plugin->varName] = null; | |
| } | |
| } | |
| /** | |
| * __functionDescription__ | |
| * @param __type__ __parameterDescription__ | |
| */ | |
| public function reCalculate($track) { | |
| if (get_class($track) == "aae\adt\Tree") { | |
| $track = $track->getNode(0); | |
| // TODO: make sure that all subtracts are calculated! | |
| } | |
| $segment = 1; | |
| foreach ($this->plugins as $plugin) { | |
| $plugin->initialize(); | |
| } | |
| for ($i=1; $i < count($track); $i++) { | |
| if (count($track->segmentStarts) - 1 >= $segment) { | |
| if ($track->segmentStarts[$segment] == $i) { | |
| $segment++; | |
| continue; | |
| } | |
| } | |
| $time = $this->calculator->timePassedBetweenCoordinates($track[$i - 1], $track[$i]); | |
| $this->segmentTimes[] = $time; | |
| $distance = $this->calculator->distanceBetweenCoordinates($track[$i - 1], $track[$i]); | |
| $this->segmentDistances[] = $distance; | |
| $speed = ($time > 0) ? $distance / ($time / (60 * 60)) : 0; | |
| $this->segmentSpeeds[] = $speed; | |
| $elevationChange = $this->calculator->elevationChangeBetweenCoordinates($track[$i - 1], $track[$i]); | |
| $this->segmentElevationChanges[] = $elevationChange; | |
| foreach ($this->plugins as $plugin) { | |
| $plugin->execute(); | |
| } | |
| } | |
| foreach ($this->plugins as $plugin) { | |
| $plugin->finalize(); | |
| } | |
| } | |
| } | |
| } |