/** * Read request */ protected function readPropertiesFromRequest() { if ((double) Request::param('distance') > 0) { $this->LapDistance = min($this->Context->trackdata()->totalDistance(), (double) Request::param('distance')); } if (strlen(Request::param('time')) > 0) { $Time = new Duration(Request::param('time')); $this->LapTime = min($this->Context->trackdata()->totalTime(), $Time->seconds()); } if (strlen(Request::param('demanded-time')) > 0) { $this->DemandedTime->fromString(Request::param('demanded-time')); if ($this->LapDistance > 0) { $this->DemandedPace->setTime($this->DemandedTime->seconds() / $this->LapDistance); } } elseif ($this->LapDistance > 0) { $this->DemandedTime->fromSeconds($this->Context->trackdata()->totalTime() / $this->Context->trackdata()->totalDistance() * $this->LapDistance); $this->DemandedPace->setTime($this->DemandedTime->seconds() / $this->LapDistance); } if (strlen(Request::param('demanded-pace')) > 0) { $this->DemandedPace->fromMinPerKm(Request::param('demanded-pace')); $this->DemandedTime->fromSeconds($this->LapDistance * $this->DemandedPace->secondsPerKm()); } elseif ($this->DemandedPace->secondsPerKm() == 0) { $this->DemandedPace = $this->Context->dataview()->pace(); } if (strlen(Request::param('manual-distances')) > 0) { $this->ManualDistances = Calculator::getDistancesFromString(Request::param('manual-distances')); } if (strlen(Request::param('manual-times')) > 0) { $this->ManualTimes = Calculator::getTimesFromString(Request::param('manual-times')); } }
/** * Init data */ protected function initData() { $Zones = $this->computeZones(); $Pace = new Pace(0, 0, $this->Context->sport()->paceUnit()); foreach ($Zones as $hf => $Info) { if ($Info['time'] > parent::MINIMUM_TIME_IN_ZONE) { $Pace->setTime($Info['time']); $Pace->setDistance($Info['distance']); $this->Data[] = array('zone' => '< ' . $hf . ' %', 'time' => $Info['time'], 'distance' => $Info['distance'], 'average' => $Pace->value() > 0 ? $Pace->valueWithAppendix() : '-'); } } }
/** * Init data */ protected function initData() { $this->paceUnit = $this->Context->sport()->paceUnit(); $Zones = $this->computeZones(); $hrMax = Runalyze\Configuration::Data()->HRmax(); $Pace = new Pace(0, 1, $this->paceUnit); $HR = new HeartRate(0, Runalyze\Context::Athlete()); foreach ($Zones as $paceInSeconds => $Info) { if ($Info['time'] > parent::MINIMUM_TIME_IN_ZONE) { $Pace->setTime($paceInSeconds); $HR->setBPM($Info['time'] > 0 ? $Info['hr'] / $Info['time'] : 0); $this->Data[] = array('zone' => $paceInSeconds == 0 ? __('faster') : '> ' . $Pace->valueWithAppendix(), 'time' => $Info['time'], 'distance' => $Info['distance'], 'average' => $HR->asBPM() > 0 ? $HR->string() : '-'); } } }
/** * @param int $num */ protected function manipulateData($num) { $distanceUnit = \Runalyze\Configuration::General()->distanceUnitSystem()->distanceUnit(); $Pace = new PaceObject(0, 1); $Pace->setUnit($this->PaceUnit); foreach ($this->Data as $key => $val) { if ($num > 35) { $this->Labels[$key] = array($key, round($this->Labels[$key], 1)); } elseif ($num >= 15) { $this->Labels[$key] = array($key, number_format($this->Labels[$key], 1, '.', '')); } elseif ($num > 10) { $this->Labels[$key] = array($key, $this->Labels[$key] . $distanceUnit); } else { $this->Labels[$key] = array($key, $this->Labels[$key] . ' ' . $distanceUnit); } $Pace->setTime($val); if ($this->PaceUnit->isTimeFormat()) { $this->Data[$key] = 1000 * round($Pace->secondsPerKm() * $this->PaceUnit->factorForUnit()); } else { $this->Data[$key] = (double) str_replace(',', '.', $Pace->value()); } } $this->Plot->Data[] = array('label' => $this->title, 'data' => $this->Data); }
/** * @param int $num * @param enum $paceUnit */ protected function manipulateData($num, $paceUnit) { $paceInTime = $paceUnit == APace::MIN_PER_KM || $paceUnit == APace::MIN_PER_100M || $paceUnit == APace::MIN_PER_500M; $pace = new APace(0, 1, $paceUnit); foreach ($this->Data as $key => $val) { if ($num > 35) { $this->Labels[$key] = array($key, round($this->Labels[$key], 1)); } elseif ($num >= 20) { $this->Labels[$key] = array($key, number_format($this->Labels[$key], 1, '.', '')); } elseif ($num > 10) { $this->Labels[$key] = array($key, $this->Labels[$key] . 'k'); } else { $this->Labels[$key] = array($key, $this->Labels[$key] . ' km'); } $pace->setTime($val); if ($paceInTime) { $this->Data[$key] = 1000 * $pace->secondsPerKm(); if ($paceUnit == APace::MIN_PER_100M) { $this->Data[$key] /= 10; } elseif ($paceUnit == APace::MIN_PER_500M) { $this->Data[$key] /= 2; } } else { $this->Data[$key] = (double) str_replace(',', '.', $pace->value()); } } $this->Plot->Data[] = array('label' => $this->title, 'data' => $this->Data); }
public function testMethodChaining() { $Pace = new Pace(0, 1, PaceUnit::MIN_PER_KM); $this->assertEquals('3:00', $Pace->setTime(180)->value()); $this->assertEquals('6:00', $Pace->setDistance(0.5)->value()); }
/** * Get array for "Tempobereiche" */ private function getPaceArray() { $speed_min = $this->Configuration()->value('lowest_pacegroup'); $speed_max = $this->Configuration()->value('highest_pacegroup'); $speed_step = $this->Configuration()->value('pacegroup_step'); $ceil_corr = $speed_min % $speed_step; if ($this->sportid != Configuration::General()->runningSport()) { $MinMax = DB::getInstance()->query(' SELECT MIN(`s`/`distance`) as `min`, MAX(`s`/`distance`) as `max` FROM `' . PREFIX . 'training` WHERE `sportid`=' . $this->sportid . ' AND ' . PREFIX . 'training.accountid="' . SessionAccountHandler::getId() . '" ' . $this->where_time . ' AND `distance`>0 ')->fetch(); if (!empty($MinMax)) { $speed_min = round((double) $MinMax['max']); $speed_max = round((double) $MinMax['min']); $speed_step = $speed_min == $speed_max ? 1 : round(($speed_min - $speed_max) / 10); $ceil_corr = $speed_min == $speed_max ? 1 : $speed_min % $speed_step; } } $result = DB::getInstance()->query(' SELECT ' . $this->getTimerIndexForQuery() . ' AS `timer`, COUNT(*) AS `num`, SUM(`distance`) AS `distance`, SUM(`s`) AS `s`, FLOOR( (`s`/`distance` - ' . $ceil_corr . ')/' . $speed_step . ')*' . $speed_step . ' + ' . $ceil_corr . ' AS `group` FROM `' . PREFIX . 'training` WHERE `sportid`=' . $this->sportid . ' AND ' . PREFIX . 'training.accountid="' . SessionAccountHandler::getId() . '" ' . $this->where_time . ' AND `distance`>0 GROUP BY `group`, ' . $this->group_time . ' ORDER BY `group` DESC, ' . $this->getTimerForOrderingInQuery() . ' ASC ')->fetchAll(); $speed_data = $this->emptyData; foreach ($result as $dat) { if ($this->sportid == Configuration::General()->runningSport()) { if ($dat['group'] > $speed_min) { $dat['group'] = $speed_min; } else { if ($dat['group'] < $speed_max) { $dat['group'] = $speed_max; } } } $this->setGroupData($speed_data, $dat); $this->setSumData($speed_data, $dat); } $speed_foreach = array(); if (!empty($result)) { $Pace = new Pace(0, 1, SportFactory::getSpeedUnitFor($this->sportid)); for ($speed = $speed_min; $speed > $speed_max - $speed_step; $speed -= $speed_step) { if ($speed <= $speed_max) { $name = '<small>' . __('faster than') . '</small> ' . $Pace->setTime($speed + $speed_step)->valueWithAppendix(); } else { if ($speed == $speed_min) { $name = '<small>' . __('up to') . '</small> ' . $Pace->setTime($speed)->valueWithAppendix(); } else { $name = $Pace->setTime($speed + $speed_step)->value() . ' <small>' . __('to') . '</small> ' . $Pace->setTime($speed)->valueWithAppendix(); } } $speed_foreach[] = array('name' => $name, 'id' => max($speed, $speed_max)); } } return array('name' => __('Pace Zones') . '*', 'array' => $speed_data, 'foreach' => $speed_foreach); }