Example #1
0
 /**
  * Remove single series from trackdata
  * @param enum $key
  */
 public function removeFromTrackdata($key)
 {
     if (isset($this->ActivityKeysForTrackdataKeys[$key])) {
         $this->removeFromActivityIfValueIsEqualToAverage($key, $this->ActivityKeysForTrackdataKeys[$key]);
     }
     $this->Trackdata->set($key, array());
 }
Example #2
0
 /**
  * Calculate power
  */
 protected function calculatePower()
 {
     if (\Runalyze\Context::Factory()->sport($this->Object->sportid())->hasPower() && Configuration::ActivityForm()->computePower() && NULL !== $this->Trackdata) {
         $Calculator = new \Runalyze\Calculation\Power\Calculator($this->Trackdata, $this->Route);
         $Calculator->calculate();
         $this->Trackdata->set(Model\Trackdata\Object::POWER, $Calculator->powerData());
         $this->Object->set(Object::POWER, $Calculator->average());
     }
 }
Example #3
0
 /**
  * Update power for trackdata
  * @param array $powerData
  */
 protected function updatePowerForTrackdata(array $powerData)
 {
     if (NULL !== $this->Trackdata && (empty($powerData) && $this->Trackdata->has(Model\Trackdata\Object::POWER) || !empty($powerData) && !$this->Trackdata->has(Model\Trackdata\Object::POWER))) {
         $this->Trackdata->set(Model\Trackdata\Object::POWER, $powerData);
         $TrackdataUpdater = new Model\Trackdata\Updater($this->PDO);
         $TrackdataUpdater->setAccountID($this->AccountID);
         $TrackdataUpdater->update($this->Trackdata, array(Model\Trackdata\Object::POWER));
     }
 }
Example #4
0
 /**
  * Init data
  * @param \Runalyze\Model\Trackdata $trackdata
  * @param string $key
  */
 protected function fillGaps(Trackdata $trackdata, $key)
 {
     $data = $trackdata->get($key);
     $last = $data[0];
     foreach ($data as &$val) {
         if ($val == 0) {
             $val = $last;
         }
         $last = $val;
     }
     $trackdata->set($key, $data);
 }
 /**
  * Construct time series for trackdata object
  * @param \Runalyze\Model\Trackdata\Object $trackdata
  * @param enum $indexKey
  * @param enum[] $sumDifferencesKeys
  * @param enum[] $avgValuesKeys
  * @throws \InvalidArgumentException
  */
 public function __construct(Trackdata\Object $trackdata, $indexKey, $sumDifferencesKeys = array(), $avgValuesKeys = array())
 {
     $this->Trackdata = $trackdata;
     $this->IndexKey = $indexKey;
     $this->SumDifferencesKeys = $sumDifferencesKeys;
     $this->AvgValuesKeys = $avgValuesKeys;
     foreach (array_merge($sumDifferencesKeys, $avgValuesKeys) as $key) {
         if (!$trackdata->has($key)) {
             $trackdata->set($key, array_fill(0, $trackdata->num(), 0));
         }
     }
     parent::__construct($trackdata->get($indexKey), $trackdata->get(Trackdata\Object::TIME));
     $this->collectData();
 }
Example #6
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());
 }
Example #7
0
 public function fillDistanceArray(Trackdata\Object &$trackdata)
 {
     if ($this->poollength() && !$trackdata->has(Trackdata\Object::DISTANCE)) {
         $distance = range($this->poollength() / 100000, $this->num() * $this->poollength() / 100000, $this->poollength() / 100000);
         $trackdata->set(Trackdata\Object::DISTANCE, $distance);
     }
 }
Example #8
0
 /**
  * Remove single series from trackdata
  * @param enum $key
  */
 public function removeFromTrackdata($key)
 {
     $this->Trackdata->set($key, array());
 }