Ejemplo n.º 1
0
 /**
  * Calculate average stride length
  * @return int [cm]
  */
 public function average()
 {
     if (empty($this->Strides)) {
         return 0;
     }
     $Series = new TimeSeries($this->Strides, $this->Trackdata->time());
     $Series->calculateStatistic();
     return round($Series->mean());
 }
Ejemplo n.º 2
0
 /**
  * Run fast smoothing for step size
  * 
  * Although this does not look nice and is not the cleanest code,
  * direct access to the arrays is approx. 5-times faster.
  * (0.02s vs 0.11s for an array of 10.000 elements)
  */
 protected function runFastSmoothingForSteps()
 {
     $distance = $this->Trackdata->distance();
     $time = $this->Trackdata->time();
     $lastDist = 0;
     $lastTime = 0;
     foreach ($distance as $i => $dist) {
         if ($i != 0 && $i % $this->StepSize == 0) {
             $pace = $dist - $lastDist > 0 ? round(($time[$i] - $lastTime) / ($dist - $lastDist)) : 0;
             if ($this->KeepArraySize) {
                 for ($j = 0; $j < $this->StepSize; ++$j) {
                     $this->Smoothed[] = $pace;
                 }
             } else {
                 $this->Smoothed[] = $pace;
             }
             $lastDist = $dist;
             $lastTime = $time[$i];
         }
     }
     if ($this->KeepArraySize && isset($i)) {
         $pace = $dist - $lastDist > 0 ? round(($time[$i] - $lastTime) / ($dist - $lastDist)) : 0;
         for ($j = count($this->Smoothed), $num = $this->Trackdata->num(); $j < $num; ++$j) {
             $this->Smoothed[] = $pace;
         }
     }
 }
Ejemplo n.º 3
0
 public function testSimpleInsert()
 {
     $T = new Object(array(Object::ACTIVITYID => 1, Object::TIME => array(20, 40, 60), Object::DISTANCE => array(0.1, 0.2, 0.3), Object::HEARTRATE => array(100, 120, 130)));
     $T->pauses()->add(new Pause(40, 10));
     $I = new Inserter($this->PDO, $T);
     $I->setAccountID(1);
     $I->insert();
     $data = $this->PDO->query('SELECT * FROM `' . PREFIX . 'trackdata` WHERE `accountid`=1')->fetch(PDO::FETCH_ASSOC);
     $N = new Object($data);
     $this->assertEquals(1, $N->activityID());
     $this->assertEquals(array(20, 40, 60), $N->time());
     $this->assertEquals(array(0.1, 0.2, 0.3), $N->distance());
     $this->assertEquals(array(100, 120, 130), $N->heartRate());
     $this->assertFalse($N->pauses()->isEmpty());
 }
Ejemplo n.º 4
0
 public function testSimpleUpdate()
 {
     $Inserter = new Inserter($this->PDO, new Object(array(Object::ACTIVITYID => 1, Object::TIME => array(20, 40, 60), Object::DISTANCE => array(0.1, 0.2, 0.3), Object::HEARTRATE => array(100, 120, 130))));
     $Inserter->setAccountID(1);
     $Inserter->insert();
     $Track = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'trackdata` WHERE `activityid`=1')->fetch(PDO::FETCH_ASSOC));
     $Track->set(Object::HEARTRATE, array(120, 140, 150));
     $Changed = clone $Track;
     $Changed->set(Object::DISTANCE, array(0.15, 0.3, 0.45));
     $Updater = new Updater($this->PDO, $Changed, $Track);
     $Updater->setAccountID(1);
     $Updater->update();
     $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'trackdata` WHERE `activityid`=1')->fetch(PDO::FETCH_ASSOC));
     $this->assertEquals(1, $Result->activityID());
     $this->assertEquals(array(20, 40, 60), $Result->time());
     $this->assertEquals(array(0.15, 0.3, 0.45), $Result->distance());
     $this->assertEquals(array(100, 120, 130), $Result->heartRate());
 }
Ejemplo n.º 5
0
 /**
  * Calculate trimp
  * @return int
  */
 public function calculateTrimp()
 {
     if ($this->knowsTrackdata() && $this->Trackdata->has(Model\Trackdata\Object::HEARTRATE)) {
         $Collector = new Trimp\DataCollector($this->Trackdata->heartRate(), $this->Trackdata->time());
         $data = $Collector->result();
     } elseif ($this->Activity->hrAvg() > 0) {
         $data = array($this->Activity->hrAvg() => $this->Activity->duration());
     } else {
         $Factory = Context::Factory();
         if ($this->Activity->typeid() > 0) {
             $data = array($Factory->type($this->Activity->typeid())->hrAvg() => $this->Activity->duration());
         } else {
             $data = array($Factory->sport($this->Activity->sportid())->avgHR() => $this->Activity->duration());
         }
     }
     $Athlete = Context::Athlete();
     $Calculator = new Trimp\Calculator($Athlete, $data);
     return round($Calculator->value());
 }