public function testForVDOT20() { $this->object->setVDOT(20); $this->object->setDaysToRecognizeForLongjogs(7); $this->object->setDaysToRecognizeForWeekKilometer(7); $this->object->setMinimalDaysToRecognizeForWeekKilometer(7); $this->object->setMinimalDistanceForLongjogs(10); $this->object->setPercentageForLongjogs(0.33); $this->object->setPercentageForWeekKilometer(0.67); DB::getInstance()->insert('training', array('sportid', 'time', 'distance'), array(Configuration::General()->runningSport(), time() - 1 * DAY_IN_S, 15)); DB::getInstance()->insert('training', array('sportid', 'time', 'distance'), array(Configuration::General()->runningSport(), time() - 3 * DAY_IN_S, 15)); DB::getInstance()->insert('training', array('sportid', 'time', 'distance'), array(Configuration::General()->runningSport(), time() - 8 * DAY_IN_S, 42)); $Results = $this->object->asArray(); $this->assertEquals(30, $Results['weekkm-result']); $this->assertEquals(0.82, $Results['longjog-result'], '', 0.01); $this->assertEquals(1.0, $Results['weekkm-percentage'], '', 0.01); $this->assertEquals(0.82, $Results['longjog-percentage'], '', 0.01); $this->assertEquals(94, $Results['percentage'], '', 0.01); $this->assertEquals(94, $this->object->value()); $this->assertEquals('94 %', $this->object->valueInPercent()); $this->object->setPercentageForLongjogs(1); $this->assertEquals(82, $this->object->value()); $this->object->setDaysToRecognizeForLongjogs(14); $this->assertEquals(555, $this->object->value()); // Attention: depens on START_TIME $this->object->setMinimalDaysToRecognizeForWeekKilometer(70); $this->object->setDaysToRecognizeForWeekKilometer(70); $this->object->setPercentageForLongjogs(0.01); $this->assertEquals(29, $this->object->value()); }
/** * Update basic endurance */ protected function updateBasicEndurance() { $timestampLimit = time() - 182 * DAY_IN_S; if (($this->hasChanged(Entity::DISTANCE) || $this->hasChanged(Entity::TIMESTAMP) || $this->hasChanged(Entity::SPORTID)) && ($this->NewObject->sportid() == Configuration::General()->runningSport() && $this->NewObject->timestamp() > $timestampLimit || $this->knowsOldObject() && $this->OldObject->sportid() == Configuration::General()->runningSport() && $this->OldObject->timestamp() > $timestampLimit)) { BasicEndurance::recalculateValue(); } }
/** * Update basic endurance */ protected function updateBasicEndurance() { $timestampLimit = time() - 182 * DAY_IN_S; if ($this->Object->sportid() == Configuration::General()->runningSport() && $this->Object->timestamp() > $timestampLimit) { BasicEndurance::recalculateValue(); } }
/** * Trigger recalculation */ public static function triggerRecalculation() { if (!self::$TRIGGERED) { self::$TRIGGERED = true; $oldValue = CalculationBasicEndurance::getConst(); CalculationBasicEndurance::recalculateValue(); $newValue = CalculationBasicEndurance::getConst(); Messages::addValueRecalculated(__('Basic endurance'), $newValue . ' %', $oldValue . ' %'); } }
/** * Display additional info */ protected function displayInfos() { if ($this->showsAverage()) { $BasicEndurance = new BasicEndurance(); $BasicEndurance->readSettingsFromConfiguration(); echo HTML::info(__('Goal and average are based on current basic endurance calculations.')); } }
/** * Get fieldset for basic endurance * @return \FormularFieldset */ public function getFieldsetBasicEndurance() { $BasicEndurance = new BasicEndurance(); $BasicEndurance->readSettingsFromConfiguration(); $BEresults = $BasicEndurance->asArray(); $Strategy = new Prognosis\Daniels(); $Strategy->setupFromDatabase(); $Strategy->adjustVDOT(false); $Prognosis = new Prognosis\Prognosis(); $Prognosis->setStrategy($Strategy); $GeneralTable = ' <table class="fullwidth zebra-style"> <tbody class="top-and-bottom-border"> <tr> <td>' . __('<strong>Current VDOT</strong> <small>(based on heart rate)</small>') . '</td> <td class="r">' . round(Configuration::Data()->vdot(), 2) . '</td> <td> </td> <td>' . sprintf(__('<strong>Target kilometer per week</strong> <small>(%s weeks)</small>'), round($BasicEndurance->getDaysForWeekKm() / 7)) . '</td> <td class="r">' . Distance::format($BasicEndurance->getTargetWeekKm(), false, 0) . '</td> <td class="small">' . sprintf(__('done by %s%'), round(100 * $BEresults['weekkm-percentage'])) . '</td> <td class="small">(ø ' . Distance::format($BEresults['weekkm-result'] / $BasicEndurance->getDaysForWeekKm() * 7, false, 0) . ')</td> <td class="small">x' . $BasicEndurance->getPercentageForWeekKilometer() . '</td> <td rowspan="2" class="bottom-spacer b" style="vertical-align:middle;">= ' . round($BEresults['percentage']) . '%</td> </tr> <tr> <td>' . __('<strong>Marathon time</strong> <small>(optimal)</small>') . '</td> <td class="r">' . Duration::format($Prognosis->inSeconds(42.195)) . '</td> <td> </td> <td>' . sprintf(__('<strong>Target long run</strong> <small>(%s weeks)</small>'), round($BasicEndurance->getDaysToRecognizeForLongjogs() / 7)) . '</td> <td class="r">' . Distance::format($BasicEndurance->getRealTargetLongjogKmPerWeek(), false, 0) . '</td> <td class="small">' . sprintf(__('done by %s%'), round(100 * $BEresults['longjog-percentage'])) . '</td> <td class="small">(' . round($BEresults['longjog-result'], 1) . ' points)</td> <td class="small">x' . $BasicEndurance->getPercentageForLongjogs() . '</td> </tr> </tbody> </table>'; $LongjogTable = '<table class="fullwidth zebra-style c"> <thead> <tr> <th>' . __('Date') . '*</th> <th>' . __('Distance') . '</th> <th>' . __('Points') . '</th> </tr> </thead> <tbody>'; $IgnoredLongjogs = 0; $Longjogs = DB::getInstance()->query($BasicEndurance->getQuery(0, true))->fetchAll(); foreach ($Longjogs as $Longjog) { if ($Longjog['points'] >= 0.2) { $LongjogTable .= '<tr> <td>' . Ajax::trainingLink($Longjog['id'], date('d.m.Y', $Longjog['time'])) . '</td> <td>' . Distance::format($Longjog['distance']) . '</td> <td>' . round($Longjog['points'], 1) . ' points</td> </tr>'; } else { $IgnoredLongjogs++; } } $LongjogTable .= '<tr class="top-spacer no-zebra"> <td></td> <td></td> <td class="b">= ' . round($BEresults['longjog-result'], 1) . ' points</td> </tr> </tbody> </table>'; $LongjogTable .= '<p class="small">' . sprintf(__('* %s "long" jogs do not show up, ' . 'because they have less than 0.2 points.'), $IgnoredLongjogs) . '</p>'; $LongjogTable .= '<p class="small">' . sprintf(__('* In general, all runs with more than %s are being considered.'), Distance::format($BasicEndurance->getMinimalDistanceForLongjogs())) . '</p>'; $Fieldset = new FormularFieldset(__('Basic endurance')); $Fieldset->addBlock(__('Your basic endurance is based on your weekly kilometers and your long jogs.<br>' . 'The target is derived from the possible marathon time based on your current shape.') . '<br> '); $Fieldset->addBlock($GeneralTable); $Fieldset->addBlock(__('The points for your long runs are weighted by time and quadratic in distance. ' . 'That means, a long jog yesterday gives more points than a long jog two weeks ago ' . 'and a 30k-jog gives more points than two 20k-jogs.') . '<br> '); $Fieldset->addBlock($LongjogTable); $Fieldset->addBlock(__('The basic endurance is <strong>not</strong> from Jack Daniels.<br>' . 'It\'s our own attempt to adjust the prognosis for long distances based on your current endurance.')); return $Fieldset; }
/** * Running setup from database */ public function setupFromDatabase() { $this->setVDOT(Configuration::Data()->vdot()); $this->adjustVDOT(true); $this->setBasicEnduranceForAdjustment(BasicEndurance::getConst()); }
/** * Set default values */ protected function setDefaultValues() { $Strategy = new Prognosis\Bock(); $TopResults = $Strategy->getTopResults(2); $CurrentShape = Configuration::Data()->vdotShape(); if (empty($_POST)) { $Factory = new PluginFactory(); $Plugin = $Factory->newInstance('RunalyzePluginPanel_Prognose'); $_POST['model'] = 'jack-daniels'; $_POST['distances'] = implode(', ', $Plugin->getDistances()); $_POST['vdot'] = $CurrentShape; $_POST['endurance'] = true; $_POST['endurance-value'] = BasicEndurance::getConst(); $_POST['best-result-km'] = !empty($TopResults) ? $TopResults[0]['distance'] : '5.0'; $_POST['best-result-time'] = !empty($TopResults) ? Duration::format($TopResults[0]['s']) : '0:26:00'; $_POST['second-best-result-km'] = !empty($TopResults) ? $TopResults[1]['distance'] : '10.0'; $_POST['second-best-result-time'] = !empty($TopResults) ? Duration::format($TopResults[1]['s']) : '1:00:00'; } $this->InfoLines['jack-daniels'] = __('Your current VDOT:') . ' ' . $CurrentShape . '. '; $this->InfoLines['jack-daniels'] .= __('Your current basic endurance:') . ' ' . BasicEndurance::getConst() . '.'; $ResultLine = empty($TopResults) ? __('none') : sprintf(__('%s in %s <small>(%s)</small> and %s in %s <small>(%s)</small>'), Distance::format($TopResults[0]['distance']), Duration::format($TopResults[0]['s']), date('d.m.Y', $TopResults[0]['time']), Distance::format($TopResults[1]['distance']), Duration::format($TopResults[1]['s']), date('d.m.Y', $TopResults[1]['time'])); $this->InfoLines['robert-bock'] = __('Your two best results:') . ' ' . $ResultLine; $this->setupJackDanielsStrategy(); $this->setupBockStrategy(); $this->setupSteffnyStrategy(); $this->setupCameronStrategy(); }
/** * Recalculate basic endurance */ protected function recalculateBasicEndurance() { $oldValue = Configuration::Data()->basicEndurance(); BasicEndurance::recalculateValue(); $newValue = Configuration::Data()->basicEndurance(); $this->addSuccessMessage(__('Basic endurance'), $oldValue, $newValue); }