public function testDiffInDays() { $this->assertEquals(0, Time::diffInDays(mktime(0, 0, 0, 12, 5, 2000), mktime(0, 0, 0, 12, 5, 2000))); $this->assertEquals(0, Time::diffInDays(mktime(0, 0, 0, 12, 5, 2000), mktime(23, 59, 0, 12, 5, 2000))); $this->assertEquals(1, Time::diffInDays(mktime(0, 0, 0, 12, 5, 2000), mktime(0, 0, 0, 12, 6, 2000))); $this->assertEquals(5, Time::diffInDays(mktime(0, 0, 0, 12, 5, 2000), mktime(0, 0, 0, 12, 10, 2000))); $this->assertEquals(4, Time::diffInDays(mktime(17, 0, 0, 12, 5, 2000), mktime(15, 0, 0, 12, 10, 2000))); $this->assertEquals(5, Time::diffInDays(mktime(18, 0, 0, 12, 5, 2000), mktime(13, 0, 0, 12, 11, 2000))); $this->assertEquals(365, Time::diffInDays(mktime(0, 0, 0, 12, 5, 2000), mktime(0, 0, 0, 12, 5, 2001))); }
/** * Init all days for beeing displayed */ protected function initDays() { $this->initShortModes(); $this->initEmptyDays(); $WhereNotPrivate = FrontendShared::$IS_SHOWN && !Configuration::Privacy()->showPrivateActivitiesInList() ? 'AND is_public=1' : ''; $AllTrainings = $this->DB->query(' SELECT id, time, `s` as `s_sum_with_distance`, DATE(FROM_UNIXTIME(time)) as `date` ' . $this->Dataset->getQuerySelectForAllDatasets() . ' FROM `' . PREFIX . 'training` WHERE `time` BETWEEN ' . ($this->timestamp_start - 10) . ' AND ' . ($this->timestamp_end - 10) . ' AND accountid = ' . SessionAccountHandler::getId() . ' ' . $WhereNotPrivate . ' ORDER BY `time` ASC ')->fetchAll(); foreach ($AllTrainings as $Training) { $w = Time::diffInDays($Training['time'], $this->timestamp_start); if (in_array($Training['sportid'], $this->sports_short) || in_array($Training['typeid'], $this->types_short)) { $this->days[$w]['shorts'][] = $Training; } else { $this->days[$w]['trainings'][] = $Training; } } }
/** * Init all days for beeing displayed */ protected function initDays() { $this->initShortModes(); $this->initEmptyDays(); $Statement = $this->DatasetQuery->statementToFetchActivities($this->TimestampStart, $this->TimestampEnd); while ($Training = $Statement->fetch()) { $w = Time::diffInDays($Training['time'], $this->TimestampStart); if (in_array($Training['sportid'], $this->SportsShort) || in_array($Training['typeid'], $this->TypesShort)) { $this->Days[$w]['shorts'][] = $Training; } else { $this->Days[$w]['trainings'][] = $Training; } } }
/** * Check: Is this training too old for weather forecast? * @return boolean */ private function trainingIsTooOldToFetchWeatherData() { return Time::diffInDays($this->getTimestamp()) > 30; }
/** * Display the content * @see PluginPanel::displayContent() */ protected function displayContent() { $this->showValues(); if ($this->Configuration()->value('show_trainingpaces')) { $this->showPaces(); } if (Time::diffInDays(START_TIME) < 70) { echo HTML::info(__('There are not enough activities for good calculations.')); } }
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()) {
/** * 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; }
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('