/** * Prepare summary */ protected function prepare() { parent::prepare(); $this->Title = sprintf(__('All training weeks %s'), $this->Year); $this->TimeEnd = $this->Year == date("Y") ? Time::weekend(time()) : Time::weekend(mktime(1, 0, 0, 12, 31, $this->Year)); $this->TimeStart = Time::weekstart(mktime(1, 0, 0, 12, 31, $this->Year - 1)); }
/** * Head for row * @param int $index * @return string */ protected function rowHead($index) { $year = $this->Mode == self::MODE_YEAR ? $this->Year : date('Y'); $month = date('m', $this->TimeEnd - ($index + 0.5) * 31 * DAY_IN_S); $start = mktime(0, 0, 1, $month, 1, $year); $end = mktime(23, 59, 59, $month + 1, 0, $year); return DataBrowserLinker::link(Time::month($month), $start, $end, ''); }
/** * Head for row * @param int $index * @return string */ protected function rowHead($index) { $time = $this->TimeEnd - ($index + 0.5) * 7 * DAY_IN_S; $start = Time::weekstart($time); $end = Time::weekend($time); $week = Icon::$CALENDAR . ' ' . __('Week') . ' ' . date('W', $time); return DataBrowserLinker::link($week, $start, $end, '') . '</span> <span class="small">' . date('d.m', $start) . ' - ' . date('d.m', $end); }
public function testWeekstartAndWeekendForSundayBug() { Configuration::General()->weekStart()->set(WeekStart::SUNDAY); $today = mktime(0, 0, 0, 10, 25, 2015); $end = mktime(23, 59, 50, 10, 31, 2015); $this->assertEquals($today, Time::weekstart($today)); $this->assertEquals($today, Time::weekstart($end)); $this->assertEquals($end, Time::weekend($today)); $this->assertEquals($end, Time::weekend($end)); }
/** * Get X labels * @return array */ protected function getXLabels() { $months = array(); $add = $this->Year == parent::LAST_6_MONTHS || $this->Year == parent::LAST_12_MONTHS ? date('m') : 0; $i = 0; for ($m = $this->timerStart; $m <= $this->timerEnd; $m++) { $months[] = array($i, Time::month($m + $add, true)); $i++; } return $months; }
/** * Get X labels * @return array */ protected function getXLabels() { $weeks = array(); $add = $this->Year == parent::LAST_6_MONTHS || $this->Year == parent::LAST_12_MONTHS ? 0 : $this->WeekStart->phpWeek() - $this->timerEnd; for ($w = $this->timerStart; $w <= $this->timerEnd; $w++) { $time = strtotime($this->WeekStart->lastDayOfWeekForStrtotime() . " -" . ($this->timerEnd - $w + $add) . " weeks"); $string = date("d", $time) <= 7 ? Time::month(date("m", $time), true) : ''; if ($string != '' && date("m", $time) == 1) { $string .= ' \'' . date("y", $time); } $weeks[] = array($w - $this->timerStart, $string); } return $weeks; }
/** * Get date string for given timestamp * @param int $timestamp * @return string */ protected function dateString($timestamp) { $date = date('d.m.', $timestamp); $addLink = ''; $weekDay = Time::weekday(date('w', $timestamp), true); if (Configuration::DataBrowser()->showCreateLink() && !FrontendShared::$IS_SHOWN) { $addLink = ImporterWindow::linkForDate($timestamp); } if (Time::isToday($timestamp)) { $weekDay = '<strong>' . $weekDay . '</strong>'; } return $date . ' ' . $addLink . ' ' . $weekDay; }
<?php /** * Draw total time of training for each day of a week for the user * Include: inc/draw/Plot.Weekday.php * @package Runalyze\Plugins\Stats */ use Runalyze\Util\Time; $titleCenter = __('Activity [in h] by weekday'); $yAxis = array(); $xAxis = array(); for ($w = 1; $w <= 7; $w++) { $xAxis[] = array($w - 1, Time::weekday($w, true)); } if ($this->sportid > 0) { $Sports = array(SportFactory::DataFor((int) $this->sportid)); } else { $Sports = SportFactory::AllSports(); } $Query = DB::getInstance()->prepare('SELECT SUM(`s`) as `value`, (DAYOFWEEK(FROM_UNIXTIME(`time`))-1) as `day` FROM `' . PREFIX . 'training` WHERE `sportid`=:id ' . $this->getYearDependenceForQuery() . ' GROUP BY `day` ORDER BY ((`day`+6)%7) ASC'); // TODO: Should be possible with one query? foreach ($Sports as $sport) { $id = $sport['name'];
<?php /** * Draw weather-plot * Call: include 'Plot.Average.php' * @package Runalyze\Plugins\Stats */ use Runalyze\Util\Time; use Runalyze\Activity\Temperature; $Temperature = new Temperature(); $Months = array(); $Temperatures = array(); for ($m = 1; $m <= 12; $m++) { $Months[] = array($m - 1, Time::month($m, true)); for ($y = START_YEAR, $n = date('Y'); $y <= $n; $y++) { $Temperatures[$y] = array(null, null, null, null, null, null, null, null, null, null, null, null); } } $Query = ' SELECT YEAR(FROM_UNIXTIME(`time`)) as `y`, MONTH(FROM_UNIXTIME(`time`)) as `m`, AVG(`temperature`) as `temp` FROM `' . PREFIX . 'training` WHERE !ISNULL(`temperature`) GROUP BY `y`, `m` ORDER BY `y` ASC, `m` ASC'; $Data = DB::getInstance()->query($Query)->fetchAll(); foreach ($Data as $dat) { $Temperatures[$dat['y']][$dat['m'] - 1] = $Temperature->format((int) $dat['temp'], false);
/** * Display table head */ protected function displayHead() { echo '<table class="fullwidth zebra-style r">'; echo '<thead>'; echo '<th></th>'; for ($i = 1; $i <= 12; $i++) { echo '<th width="7.5%">' . Time::month(($i + $this->MonthOffsetForHeader) % 12 + 1, true) . '</th>'; } echo '</thead>'; echo '<tbody>'; }
/** * Weekday * @return string */ public function weekday() { return Time::weekday(date('w', $this->Activity->timestamp())); }
/** * Display days of streakrunning */ private function displayStreak() { $Query = ' SELECT `time`, DATE(FROM_UNIXTIME(`time`)) as `day` FROM `' . PREFIX . 'training` WHERE `sportid`=' . Configuration::General()->runningSport() . ' AND `accountid`=' . SessionAccountHandler::getId() . ' GROUP BY DATE(FROM_UNIXTIME(`time`)) ORDER BY `day` DESC'; $Request = DB::getInstance()->query($Query); $IsStreak = true; $FirstDay = true; $NumDays = 0; $LastTime = time(); $LastDay = date('Y-m-d'); $Text = ''; while ($IsStreak) { $Day = $Request->fetch(); if ($FirstDay) { if ($Day['day'] != $LastDay) { if (Time::diffOfDates($Day['day'], $LastDay) == 1) { $Text = __('If you run today: '); $NumDays++; } else { $IsStreak = false; } } $FirstDay = false; } if (!$Day || !$IsStreak) { $IsStreak = false; } else { if (Time::diffOfDates($Day['day'], $LastDay) <= 1) { $NumDays++; $LastDay = $Day['day']; $LastTime = $Day['time']; } else { $IsStreak = false; } } } if ($NumDays >= $this->Configuration()->value('show_streak_days')) { if ($NumDays == 0) { $Text .= __('You don\'t have a streak. Go out and start one!'); $LastTraining = DB::getInstance()->query('SELECT time FROM `' . PREFIX . 'training` WHERE `sportid`=' . Configuration::General()->runningSport() . ' AND accountid = ' . SessionAccountHandler::getId() . ' ORDER BY `time` DESC LIMIT 1')->fetch(); if (isset($LastTraining['time'])) { $Text .= ' ' . sprintf(__('Your last run was on %s'), date('d.m.Y', $LastTraining['time'])); } } else { $Text .= sprintf(_n('%d day of running since %s', '%d days of running since %s', $NumDays), $NumDays, date('d.m.Y', $LastTime)); } echo '<p class="text c"><em>' . $Text . '</em></p>'; } }
/** * Get a tr-tag for a bold header-line containing all month-names * @param int $fixedWidth Fixed width for every month-td in percent [set '0' for no fixed width] * @param int $emptyTDs Number of empty td before the month-td * @return string */ public static function monthTR($fixedWidth = 0, $emptyTDs = 1, $tag = 'td') { $width = $fixedWidth > 0 ? ' width="' . $fixedWidth . '%"' : ''; $html = '<tr class="b">'; for ($i = 1; $i <= $emptyTDs; $i++) { $html .= '<' . $tag . '></' . $tag . '>'; } for ($m = 1; $m <= 12; $m++) { $html .= '<' . $tag . $width . '>' . Time::month($m, true) . '</' . $tag . '>'; } $html .= '</tr>'; return $html; }
/** * Get days used for week km for basic endurance * @return double */ public function getDaysForWeekKm() { $diff = Time::diffInDays(START_TIME); if ($diff > $this->DAYS_FOR_WEEK_KM) { return $this->DAYS_FOR_WEEK_KM; } elseif ($diff < $this->DAYS_FOR_WEEK_KM_MIN) { return $this->DAYS_FOR_WEEK_KM_MIN; } return $diff; }
/** * Display the table with most kilometer for each year/month/week */ private function displayMostKilometer() { echo '<table class="fullwidth zebra-style">'; echo '<thead><tr><th colspan="11" class="l">' . __('Most kilometers') . '</th></tr></thead>'; echo '<tbody>'; if (empty($this->weeks)) { echo '<tr><td colspan="11"><em>' . __('No data available') . '</em></td></tr>'; echo HTML::spaceTR(11); echo '</tbody>'; echo '</table>'; return; } // Years if ($this->year == -1) { echo '<tr class="r"><td class="c b">' . __('per year') . '</td>'; foreach ($this->years as $i => $year) { $link = DataBrowserLinker::link(Distance::format($year['km']), mktime(0, 0, 0, 1, 1, $year['year']), mktime(23, 59, 50, 12, 31, $year['year'])); echo '<td class="small"><span title="' . $year['year'] . '">' . $link . '</span></td>'; } for (; $i < 9; $i++) { echo HTML::emptyTD(); } echo '</tr>'; } // Months echo '<tr class="r"><td class="c b">' . __('per month') . '</td>'; foreach ($this->months as $i => $month) { $link = DataBrowserLinker::link(Distance::format($month['km']), mktime(0, 0, 0, $month['month'], 1, $month['year']), mktime(23, 59, 50, $month['month'] + 1, 0, $month['year'])); echo '<td class="small"><span title="' . Time::month($month['month']) . ' ' . $month['year'] . '">' . $link . '</span></td>'; } for (; $i < 9; $i++) { echo HTML::emptyTD(); } echo '</tr>'; // Weeks echo '<tr class="r"><td class="c b">' . __('per week') . '</td>'; foreach ($this->weeks as $i => $week) { $link = DataBrowserLinker::link(Distance::format($week['km']), Time::weekstart($week['time']), Time::weekend($week['time'])); echo '<td class="small"><span title="' . __('Week') . ' ' . $week['week'] . ' ' . $week['year'] . '">' . $link . '</span></td>'; } for (; $i < 9; $i++) { echo HTML::emptyTD(); } echo '</tr>'; echo '</tbody>'; echo '</table>'; }
/** * Get a ajax-link to a specified DataBrowser * @param string $name Name to be displayed as link * @param int $time Timestamp of the week * @return string HTML-link */ public static function weekLink($name, $time) { return self::link($name, Time::weekstart($time), Time::weekend($time), '', 'week-link'); }
/** * Display an empty th and ths for chosen years/months * @param bool $prependEmptyTag * @param string $width */ protected function displayTableHeadForTimeRange($prependEmptyTag = true, $width = '8%') { if ($prependEmptyTag) { echo '<th></th>'; } if (!empty($width)) { $width = ' width="' . $width . '"'; } if ($this->showsAllYears()) { $year = date('Y'); for ($i = START_YEAR; $i <= $year; $i++) { echo '<th' . $width . '>' . $i . '</th>'; } echo '<th>' . __('In total') . '</th>'; } else { $num = $this->showsLast6Months() ? 6 : 12; $add = $this->showsTimeRange() ? date('m') - $num - 1 + 12 : -1; for ($i = 1; $i <= 12; $i++) { echo '<th' . $width . '>' . Time::month(($i + $add) % 12 + 1, true) . '</th>'; } } }
/** * Week link * @param string $name [optional] * @return string */ public function weekLink($name = '') { if ($name == '') { $name = date('d.m.Y', $this->Activity->timestamp()); } return DataBrowserLinker::link($name, Time::weekstart($this->Activity->timestamp()), Time::weekend($this->Activity->timestamp())); }
/** * Display title */ protected function displayTitle() { $timeForLinks = $this->timestamp_start < time() && time() < $this->timestamp_end ? time() : $this->timestamp_start; echo DataBrowserLinker::monthLink(Time::month(date("m", $timeForLinks)), $timeForLinks) . ', '; echo DataBrowserLinker::yearLink(date("Y", $timeForLinks), $timeForLinks) . ', '; echo DataBrowserLinker::weekLink(Configuration::General()->weekStart()->phpWeek($timeForLinks) . '. ' . __('week'), $timeForLinks); }
/** * Weekday * @return string */ public function weekday() { if (!is_numeric($this->Activity->timestamp())) { return ''; } return Time::weekday(date('w', $this->Activity->timestamp())); }
/** * Display an empty th and ths for chosen years/months * @param bool $prependEmptyTag * @param string $width */ protected function displayTableHeadForTimeRange($prependEmptyTag = true, $width = '8%') { echo '<th></th>'; $width = ' width="' . $width . '"'; $num = $this->showsLast6Months() ? 6 : 12; $add = $this->showsTimeRange() ? date('m') - $num - 1 + 12 : -1; for ($i = 1; $i <= 12; $i++) { echo '<th' . $width . '>' . Time::month(($i + $add) % 12 + 1, true) . '</th>'; } }
/** * Display title */ protected function displayTitle() { $timeForLinks = $this->timestamp_start < time() && time() < $this->timestamp_end ? time() : $this->timestamp_start; echo DataBrowserLinker::monthLink(Time::month(date("m", $timeForLinks)), $timeForLinks) . ', '; echo DataBrowserLinker::yearLink(date("Y", $timeForLinks), $timeForLinks) . ', '; echo DataBrowserLinker::weekLink(date("W", $timeForLinks) . '. ' . __('week'), $timeForLinks); }
/** * Show values */ protected function showValues() { $ModelQuery = new Performance\ModelQuery(); $ModelQuery->execute(DB::getInstance()); $TSBmodel = new Performance\TSB($ModelQuery->data(), Configuration::Trimp()->daysForCTL(), Configuration::Trimp()->daysForATL()); $TSBmodel->calculate(); $MonotonyQuery = new Performance\ModelQuery(); $MonotonyQuery->setRange(time() - (Monotony::DAYS - 1) * DAY_IN_S, time()); $MonotonyQuery->execute(DB::getInstance()); $Monotony = new Monotony($MonotonyQuery->data()); $Monotony->calculate(); $VDOT = Configuration::Data()->vdot(); $ATLmax = Configuration::Data()->maxATL(); $CTLmax = Configuration::Data()->maxCTL(); $ModelATLmax = $TSBmodel->maxFatigue(); $ModelCTLmax = $TSBmodel->maxFitness(); if ($ModelATLmax > $ATLmax) { Configuration::Data()->updateMaxATL($ModelATLmax); $ATLmax = $ModelATLmax; } if ($ModelCTLmax > $CTLmax) { Configuration::Data()->updateMaxCTL($ModelCTLmax); $CTLmax = $ModelCTLmax; } $ATLabsolute = $TSBmodel->fatigueAt(0); $CTLabsolute = $TSBmodel->fitnessAt(0); $TSBabsolute = $TSBmodel->performanceAt(0); $TrimpValues = array('ATL' => round(100 * $ATLabsolute / $ATLmax), 'ATLstring' => Configuration::Trimp()->showInPercent() ? round(100 * $ATLabsolute / $ATLmax) . ' %' : $ATLabsolute, 'CTL' => round(100 * $CTLabsolute / $CTLmax), 'CTLstring' => Configuration::Trimp()->showInPercent() ? round(100 * $CTLabsolute / $CTLmax) . ' %' : $CTLabsolute, 'TSB' => round(100 * $TSBabsolute / max($ATLabsolute, $CTLabsolute, 1)), 'TSBstring' => Configuration::Trimp()->showTSBinPercent() ? sprintf("%+d", round(100 * $TSBabsolute / max($ATLabsolute, $CTLabsolute))) . ' %' : sprintf("%+d", $TSBabsolute)); $TSBisPositive = $TrimpValues['TSB'] > 0; $maxTrimpToBalanced = ceil($TSBmodel->maxTrimpToBalanced($CTLabsolute, $ATLabsolute)); $restDays = ceil($TSBmodel->restDays($CTLabsolute, $ATLabsolute)); $JDQuery = Cache::get(self::CACHE_KEY_JD_POINTS); if (is_null($JDQuery)) { $JDQueryLastWeek = DB::getInstance()->query('SELECT SUM(`jd_intensity`) FROM `' . PREFIX . 'training` WHERE `time`>=' . Time::weekstart(time() - 7 * DAY_IN_S) . ' AND `time`<' . Time::weekend(time() - 7 * DAY_IN_S) . ' AND accountid = ' . SessionAccountHandler::getId()); $JDQueryThisWeek = DB::getInstance()->query('SELECT SUM(`jd_intensity`) FROM `' . PREFIX . 'training` WHERE `time`>=' . Time::weekstart(time()) . ' AND `time`<' . Time::weekend(time()) . ' AND accountid = ' . SessionAccountHandler::getId()); $JDQuery['LastWeek'] = Helper::Unknown($JDQueryLastWeek->fetchColumn(), 0); $JDQuery['ThisWeek'] = Helper::Unknown($JDQueryThisWeek->fetchColumn(), 0); Cache::set(self::CACHE_KEY_JD_POINTS, $JDQuery, '600'); } $JDPointsLastWeek = $JDQuery['LastWeek']; $JDPointsThisWeek = $JDQuery['ThisWeek']; $JDPointsPrognosis = round($JDPointsThisWeek / (7 - (Time::weekend(time()) - time()) / DAY_IN_S) * 7); $Values = array(array('show' => $this->Configuration()->value('show_vdot'), 'bars' => array(new ProgressBarSingle(2 * round($VDOT - 30), ProgressBarSingle::$COLOR_BLUE)), 'bar-tooltip' => '', 'value' => number_format($VDOT, 2), 'title' => __('VDOT'), 'small' => '', 'tooltip' => __('Current average VDOT')), array('show' => $this->Configuration()->value('show_basicendurance'), 'bars' => array(new ProgressBarSingle(BasicEndurance::getConst(), ProgressBarSingle::$COLOR_BLUE)), 'bar-tooltip' => '', 'value' => BasicEndurance::getConst() . ' %', 'title' => __('Basic endurance'), 'small' => '', 'tooltip' => __('<em>Experimental value!</em><br>100 % means: you had enough long runs and kilometers per week to run a good marathon, based on your current VDOT.')), array('show' => $this->Configuration()->value('show_trimpvalues'), 'bars' => array(new ProgressBarSingle($TrimpValues['ATL'], ProgressBarSingle::$COLOR_BLUE)), 'bar-tooltip' => sprintf(__('Current value: %s<br>Maximal value: %s<br>as percentage: %s %'), $ATLabsolute, $ATLmax, $TrimpValues['ATL']), 'value' => $TrimpValues['ATLstring'], 'title' => __('Fatigue'), 'small' => '(ATL)', 'tooltip' => __('Actual Training Load<br><small>Average training impulse of the last weeks in relation to your maximal value.</small>')), array('show' => $this->Configuration()->value('show_trimpvalues'), 'bars' => array(new ProgressBarSingle($TrimpValues['CTL'], ProgressBarSingle::$COLOR_BLUE)), 'bar-tooltip' => sprintf(__('Current value: %s<br>Maximal value: %s<br>as percentage: %s %'), $CTLabsolute, $CTLmax, $TrimpValues['CTL']), 'value' => $TrimpValues['CTLstring'], 'title' => __('Fitness level'), 'small' => '(CTL)', 'tooltip' => __('Chronical Training Load<br><small>Average training impulse of the last months in relation to your maximal value.</small>')), array('show' => $this->Configuration()->value('show_trimpvalues'), 'bars' => array(new ProgressBarSingle(abs($TrimpValues['TSB']) / 2, $TSBisPositive ? ProgressBarSingle::$COLOR_GREEN : ProgressBarSingle::$COLOR_RED, $TSBisPositive ? 'right' : 'left')), 'bar-tooltip' => 'TSB = CTL - ATL<br>' . sprintf(__('absolute: %s<br>as percentage: %s %'), $CTLabsolute . ' - ' . $ATLabsolute . ' = ' . sprintf("%+d", $TSBabsolute), $TrimpValues['TSB']), 'value' => $TrimpValues['TSBstring'], 'title' => __('Stress Balance'), 'small' => '(TSB)', 'tooltip' => __('Training Stress Balance (= CTL - ATL)<br>> 0: You are relaxing.<br>' . '< 0: You are training hard.')), array('show' => $this->Configuration()->value('show_trimpvalues') && !$TSBisPositive, 'bars' => array(new ProgressBarSingle(100 * $restDays / 7, ProgressBarSingle::$COLOR_BLUE)), 'bar-tooltip' => '', 'value' => $restDays, 'title' => __('Rest days'), 'small' => '', 'tooltip' => __('Rest days needed to reach TSB = 0')), array('show' => $this->Configuration()->value('show_trimpvalues') && $TSBisPositive, 'bars' => array(new ProgressBarSingle(100 * $maxTrimpToBalanced / 1000, ProgressBarSingle::$COLOR_BLUE)), 'bar-tooltip' => '', 'value' => $maxTrimpToBalanced, 'title' => __('Easy TRIMP'), 'small' => '', 'tooltip' => __('Max TRIMP that will still keep you at TSB = 0')), array('show' => $this->Configuration()->value('show_trimpvalues_extra'), 'bars' => array(new ProgressBarSingle($Monotony->valueAsPercentage(), $Monotony->value() > Monotony::CRITICAL ? ProgressBarSingle::$COLOR_RED : $Monotony->value() > Monotony::WARNING ? ProgressBarSingle::$COLOR_ORANGE : ProgressBarSingle::$COLOR_GREEN)), 'bar-tooltip' => 'Monotony = avg(Trimp)/stddev(Trimp)', 'value' => number_format($Monotony->value(), 2), 'title' => __('Monotony'), 'small' => '', 'tooltip' => __('Monotony<br><small>Monotony of your last seven days.<br>Values below 1.5 are preferable.</small>')), array('show' => $this->Configuration()->value('show_trimpvalues_extra'), 'bars' => array(new ProgressBarSingle($Monotony->trainingStrainAsPercentage(), $Monotony->trainingStrainAsPercentage() >= 75 ? ProgressBarSingle::$COLOR_RED : ($Monotony->trainingStrainAsPercentage() >= 50 ? ProgressBarSingle::$COLOR_ORANGE : ProgressBarSingle::$COLOR_GREEN))), 'bar-tooltip' => 'Training strain = sum(Trimp)*Monotony', 'value' => round($Monotony->trainingStrain()), 'title' => __('Training strain'), 'small' => '', 'tooltip' => __('Training strain<br><small>of your last seven days</small>')), array('show' => $this->Configuration()->value('show_jd_intensity'), 'bars' => array(new ProgressBarSingle($JDPointsPrognosis / 2, ProgressBarSingle::$COLOR_LIGHT), new ProgressBarSingle($JDPointsThisWeek / 2, ProgressBarSingle::$COLOR_RED)), 'bar-goal' => $JDPointsLastWeek / 2, 'bar-tooltip' => sprintf(__('This week: %s training points<br>Prognosis: ca. %s training points<br>Last week: %s training points'), $JDPointsThisWeek, $JDPointsPrognosis, $JDPointsLastWeek), 'value' => $JDPointsThisWeek, 'title' => __('Training points'), 'small' => '', 'tooltip' => __('Training intensity by Jack Daniels.<br>' . 'Jack Daniels considers the following levels:<br>' . '50 points: Beginner<br>' . '100 points: Advanced Runner<br>' . '200 points: Pro Runner'))); $this->showTableForValues($Values); }
FROM `' . PREFIX . 'training` WHERE `vdot`>0 AND use_vdot<>0 GROUP BY `y`, `m`, `d` ORDER BY `y` ASC, `m` ASC, `d` ASC')->fetchAll(); Cache::set('prognosePlotData', $Data, '300'); } if (!empty($Data)) { $StartTime = mktime(12, 0, 0, $Data[0]['m'], $Data[0]['d'], $Data[0]['y']); $windowWidth = Configuration::Vdot()->days(); $VDOTs = [$Data[0]['vdot']]; $Indices = [0]; // A 'prefix' of 15 days is needed to use uniform kernel only as 'rear mirror' foreach ($Data as $dat) { $VDOTs[] = $dat['vdot']; $Indices[] = 15 + Time::diffInDays($StartTime, mktime(12, 0, 0, $dat['m'], $dat['d'], $dat['y'])); } $MovingAverage = new WithKernel($VDOTs, $Indices); $MovingAverage->setKernel(new Kernel\Uniform($windowWidth)); $MovingAverage->calculate(); foreach ($MovingAverage->movingAverage() as $i => $value) { if ($i > 0) { // TODO: use correct GA $Strategy->setVDOT(Configuration::Data()->vdotFactor() * $value); $index = $StartTime + DAY_IN_S * ($Indices[$i] - 15); $Prognosis[$index . '000'] = $PrognosisObj->inSeconds($distance) * 1000; } } $ResultsData = Cache::get('prognosePlotDistanceData' . $distance); if (is_null($ResultsData)) { $ResultsData = DB::getInstance()->query('
/** * Check: Is this training too old for weather forecast? * @return boolean */ private function trainingIsTooOldToFetchWeatherData() { return Time::diffInDays($this->getTimestamp()) > 30; }
/** * Get the timeset as array for this panel */ private function getTimeset() { $timeset = array(); // km-Spiel Saisonen $kmstart = new DateTime(); $kmstart->setTime(0, 0, 0); $kmend = new DateTime(); $kmend->setTime(0, 0, 0); $now = new DateTime("now"); $kmstart->setISODate(date('Y'), 27, 1); if ($kmstart > $now) { $kmstart->setISODate(date('Y'), 1, 1); $kmend->setISODate(date('Y'), 26, 7); } else { $weeks = date('W', strtotime(date('Y') . '-12-31')); $kmend->setISODate(date('Y'), $weeks == 53 ? 53 : 52, 7); } echo new DateTime(date('o-\\WW')); // Zeitraeume fuer die Prognosen. $Time = new Time(); $timeset['woche'] = array('name' => __('Week'), 'start' => (new DateTime())->setTimestamp(Time::weekstart(time())), 'end' => (new DateTime())->setTimestamp(Time::weekend(time()) . " + 6 days")); $timeset['mon'] = array('name' => __('Month'), 'start' => new DateTime(date("Y-m-01")), 'end' => new Datetime(date('Y-m-t'))); $timeset['hj'] = array('name' => __('Half-Year'), 'start' => new DateTime(date('m') < 7 ? date("Y-01-01") : date("Y-07-01")), 'end' => new Datetime(date('m') < 7 ? date("Y-06-30") : date('Y-12-31'))); $timeset['saison'] = array('name' => __('Saison'), 'start' => $kmstart, 'end' => $kmend, 'note' => __('Note: Saison means the current season in the german "kmspiel"')); $timeset['jahr'] = array('name' => __('Year'), 'start' => new DateTime(date("Y-01-01")), 'end' => new Datetime(date('Y-12-31'))); return $timeset; }
WHERE `time` BETWEEN UNIX_TIMESTAMP("' . $StartDay . '" + INTERVAL -' . $AddDays . ' DAY) AND UNIX_TIMESTAMP("' . $StartDay . '" + INTERVAL ' . $NumberOfDays . ' DAY)-1 GROUP BY `index`')->fetchAll(); // Cache::set('calculationsPlotData'.$Year.$All.$lastHalf.$lastYear, $Data, '300'); //} foreach ($Data as $dat) { $index = $dat['index'] + $AddDays; $Trimps_raw[$index] = 1 * $dat['trimp']; if ($dat['vdot'] != 0) { $VDOTs_raw[$index] = $dat['vdot']; // Remember: These values are already multiplied with `s` $Durations_raw[$index] = (double) $dat['s']; } } $TodayIndex = Time::diffInDays($StartTime) + $AddDays; $StartDayInYear = $All || $lastHalf || $lastYear ? Time::diffInDays($StartTime, mktime(0, 0, 0, 1, 1, $StartYear)) + 1 + 1 * ($StartYear < $Year) : 1; $LowestIndex = $AddDays + 1; $HighestIndex = $AddDays + 1 + $NumberOfDays; $VDOTdays = Configuration::Vdot()->days(); $ATLdays = Configuration::Trimp()->daysForATL(); $CTLdays = Configuration::Trimp()->daysForCTL(); if ($perfmodel == 'banister') { $performanceModel = new Runalyze\Calculation\Performance\Banister($Trimps_raw, $CTLdays, $ATLdays, 1, 3); } else { $performanceModel = new Runalyze\Calculation\Performance\TSB($Trimps_raw, $CTLdays, $ATLdays); } $performanceModel->calculate(); if ($All) { $maxATL = $performanceModel->maxFatigue(); $maxCTL = $performanceModel->maxFitness(); if ($perfmodel == 'tsb' && $maxATL != Configuration::Data()->maxATL()) {