/** * Construct plot data * @param enum $algorithm * @param int $treshold * @return array */ protected function constructPlotDataFor($algorithm, $treshold = false) { $Method = new ElevationMethod(); $Method->set($algorithm); if ($treshold === false) { $treshold = Configuration::ActivityView()->elevationMinDiff(); } $Calculator = new Data\Elevation\Calculation\Calculator($this->Context->route()->elevations()); $Calculator->setMethod($Method); $Calculator->setThreshold($treshold); $Calculator->calculate(); $i = 0; $Data = array(); $Points = $Calculator->strategy()->smoothedData(); $Indices = $Calculator->strategy()->smoothingIndices(); $hasDistances = $this->Context->trackdata()->get(Trackdata\Object::DISTANCE); $Distances = $this->Context->trackdata()->get(Trackdata\Object::DISTANCE); $Times = $this->Context->trackdata()->get(Trackdata\Object::TIME); $num = $this->Context->trackdata()->num(); foreach ($Indices as $i => $index) { if ($index >= $num) { $index = $num - 1; } if ($hasDistances) { $Data[(string) $Distances[$index]] = $Points[$i]; } else { $Data[(string) $Times[$index] . '000'] = $Points[$i]; } } $this->manipulateData($Data); return $Data; }
public function testAlgorithmDouglasPeucker() { $Method = new ElevationMethod(); $Method->set(ElevationMethod::DOUGLAS_PEUCKER); $Calc = new Calculator(array(0, 2, 4, 6, 5, 7, 4, 8, 10, 0), $Method, 2); $Calc->calculate(); $this->assertEquals(13, $Calc->totalElevation()); $this->assertEquals(13, $Calc->elevationUp()); $this->assertEquals(13, $Calc->elevationDown()); }
/** * Choose strategy */ protected function chooseStrategy() { if ($this->Method->usesThreshold()) { $this->Strategy = new Threshold($this->ElevationPoints, $this->Threshold); } elseif ($this->Method->usesDouglasPeucker()) { $this->Strategy = new DouglasPeucker($this->ElevationPoints, $this->Threshold); } elseif ($this->Method->usesReumannWitkam()) { $this->Strategy = new ReumannWitkam($this->ElevationPoints); } else { $this->Strategy = new NoSmoothing($this->ElevationPoints); } }
/** * Get different algorithms for * @param array $array * @return string */ protected function getDifferentAlgorithmsFor($array) { $Method = new ElevationMethod(); $Calculator = new Elevation\Calculation\Calculator($array); $TresholdRange = range(1, 10); $Algorithms = array(array(ElevationMethod::NONE, false), array(ElevationMethod::THRESHOLD, true), array(ElevationMethod::DOUGLAS_PEUCKER, true)); $Code = '<table class="fullwidth zebra-style small">'; $Code .= '<thead>'; $Code .= '<tr><th class="r">' . __('Threshold') . ':</th>'; foreach ($TresholdRange as $t) { $Code .= '<th>' . $t . '</th>'; } $Code .= '</tr>'; $Code .= '</thead>'; $Code .= '<tbody>'; foreach ($Algorithms as $Algorithm) { $Method->set($Algorithm[0]); $Calculator->setMethod($Method); $Code .= '<tr><td class="b">' . $Method->valueAsLongString() . '</td>'; if ($Algorithm[1]) { foreach ($TresholdRange as $t) { $highlight = Configuration::ActivityView()->elevationMinDiff() == $t && Configuration::ActivityView()->elevationMethod()->value() == $Algorithm[0] ? ' highlight' : ''; $Calculator->setThreshold($t); $Calculator->calculate(); $Code .= '<td class="r' . $highlight . '">' . $Calculator->totalElevation() . ' m</td>'; } } else { $Calculator->calculate(); $Code .= '<td class="c' . (Configuration::ActivityView()->elevationMethod()->value() == $Algorithm[0] ? ' highlight' : '') . '" colspan="' . count($TresholdRange) . '">' . $Calculator->totalElevation() . ' m</td>'; } $Code .= '</tr>'; } $Code .= '</tbody>'; $Code .= '</table>'; return $Code; }
public function testMethods() { $this->object->set(ElevationMethod::NONE); $this->assertTrue($this->object->usesNone()); $this->assertFalse($this->object->usesThreshold()); $this->assertFalse($this->object->usesDouglasPeucker()); $this->object->set(ElevationMethod::THRESHOLD); $this->assertFalse($this->object->usesNone()); $this->assertTrue($this->object->usesThreshold()); $this->assertFalse($this->object->usesDouglasPeucker()); $this->object->set(ElevationMethod::DOUGLAS_PEUCKER); $this->assertFalse($this->object->usesNone()); $this->assertFalse($this->object->usesThreshold()); $this->assertTrue($this->object->usesDouglasPeucker()); }