Example #1
0
 /**
  * Recalculate VDOT shape
  * @return float new shape
  */
 public function recalculateVDOTshape()
 {
     $Shape = new JD\Shape(DB::getInstance(), SessionAccountHandler::getId(), Configuration::General()->runningSport(), Configuration::Vdot());
     $Shape->setCorrector(new JD\VDOTCorrector($this->vdotFactor()));
     $Shape->calculate();
     $this->updateVdotShape($Shape->value());
     return $Shape->value();
 }
Example #2
0
    $Trimps_raw = $EmptyArray;
    $VDOTs_raw = $EmptyArray;
    $Durations_raw = $EmptyArray;
    // Here VDOT will be implemented again
    // Normal functions are too slow, calling them for each day would trigger each time a query
    // - VDOT: AVG(`vdot`) for Configuration::Vdot()->days()
    //Can't cache until we can invalidate it
    //$Data = Cache::get('calculationsPlotData'.$Year.$All.$lastHalf.$lastYear);
    //if (is_null($Data)) {
    $withElevation = Configuration::Vdot()->useElevationCorrection();
    $Data = DB::getInstance()->query('
			SELECT
				DATEDIFF(FROM_UNIXTIME(`time`), "' . $StartDay . '") as `index`,
				SUM(`trimp`) as `trimp`,
				SUM(' . JD\Shape::mysqlVDOTsum($withElevation) . '*(`sportid`=' . Configuration::General()->runningSport() . ')) as `vdot`,
				SUM(' . JD\Shape::mysqlVDOTsumTime($withElevation) . '*(`sportid`=' . Configuration::General()->runningSport() . ')) as `s`
			FROM `' . PREFIX . 'training`
			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'];
        }
    }
    /**
     * Init complete data
     */
    private function initCompleteData()
    {
        $withElevation = Configuration::Vdot()->useElevationCorrection();
        $Query = '
			SELECT
				SUM(`s`) as `s`,
				SUM(IF(`distance`>0,`s`,0)) as `s_sum_with_distance`,
				SUM(`distance`) as `distance`,
				SUM(' . JD\Shape::mysqlVDOTsum($withElevation) . ')/SUM(' . JD\Shape::mysqlVDOTsumTime($withElevation) . ') as `vdot`,
				SUM(`trimp`) as `trimp`,
				SUM(`jd_intensity`) as `jd_intensity`,
				' . $this->getTimerIndexForQuery() . ' as `i`
			FROM
				`' . PREFIX . 'training`
			WHERE
				`accountid`=:sessid ' . $this->getSportAndYearDependenceForQuery();
        $Query .= ' GROUP BY ' . $this->getTimerForOrderingInQuery() . ' ASC';
        $Request = DB::getInstance()->prepare($Query);
        $Request->bindValue('sessid', SessionAccountHandler::getId(), PDO::PARAM_INT);
        $Request->execute();
        $this->CompleteData = $Request->fetchAll();
    }
Example #4
0
$DataFailed = false;
$Prognosis = array();
$Results = array();
$Strategy = new Prognosis\Daniels();
$Strategy->adjustVDOT(false);
$PrognosisObj = new Prognosis\Prognosis();
$PrognosisObj->setStrategy($Strategy);
if (START_TIME != time()) {
    $Data = Cache::get('prognosePlotData');
    if (is_null($Data)) {
        $withElevation = Configuration::Vdot()->useElevationCorrection();
        $Data = DB::getInstance()->query('
			SELECT
				YEAR(FROM_UNIXTIME(`time`)) as `y`,
				MONTH(FROM_UNIXTIME(`time`)) as `m`,
				SUM(' . JD\Shape::mysqlVDOTsum($withElevation) . ')/SUM(' . JD\Shape::mysqlVDOTsumTime($withElevation) . ') as `vdot`
			FROM `' . PREFIX . 'training`
			WHERE
				`vdot`>0 AND use_vdot<>0
			GROUP BY `y`, `m`
			ORDER BY `y` ASC, `m` ASC')->fetchAll();
        Cache::set('prognosePlotData', $Data, '300');
    }
    foreach ($Data as $dat) {
        // TODO: use correct GA
        $Strategy->setVDOT(Configuration::Data()->vdotFactor() * $dat['vdot']);
        $index = mktime(1, 0, 0, $dat['m'], 15, $dat['y']);
        $Prognosis[$index . '000'] = $PrognosisObj->inSeconds($distance) * 1000;
    }
    $ResultsData = Cache::get('prognosePlotDistanceData' . $distance);
    if (is_null($ResultsData)) {
Example #5
0
 /**
  * Load shape
  * @param int $time
  * @return float
  */
 private function loadShape($time)
 {
     $Shape = new Shape(DB::getInstance(), SessionAccountHandler::getId(), Configuration::General()->runningSport(), Configuration::Vdot());
     $Shape->calculateAt($time);
     return $Shape->value();
 }
Example #6
0
 /**
  * @expectedException \RuntimeException
  */
 public function testCallWithoutCalculation()
 {
     $Shape = new Shape($this->PDO, 1, 1, new CategoryFake());
     $Shape->value();
 }