Ejemplo n.º 1
0
 /**
  * Tasks after insertion
  */
 protected function after()
 {
     parent::after();
     if (Cache::is('swimdata' . $this->NewObject->activityID())) {
         Cache::delete('swimdata' . $this->NewObject->activityID());
     }
 }
 /**
  * Construct collector
  * @param \Runalyze\Model\Trackdata\Object $trackdata
  * @param enum $key
  * @param \Runalyze\Model\Swimdata\Object $swimdata
  * @throws \InvalidArgumentException
  */
 public function __construct(Trackdata $trackdata, $key, Swimdata $swimdata)
 {
     if (!$swimdata->has($key)) {
         throw new \InvalidArgumentException('Swimdata has no data for "' . $key . '".');
     }
     $this->Key = $key;
     $this->Precision = Configuration::ActivityView()->plotPrecision();
     $this->KnowsDistance = $trackdata->has(Trackdata::DISTANCE);
     $this->init($trackdata);
     $this->LoopSwimdata = new Loop($swimdata);
     $this->collect();
 }
Ejemplo n.º 3
0
 /**
  * Construct context
  * @var int $activityID
  * @var in $accountID
  */
 public function __construct($activityID, $accountID)
 {
     $Factory = new Factory((int) $accountID);
     $this->Activity = $Factory->activity((int) $activityID);
     $this->Trackdata = $Factory->trackdata((int) $activityID);
     $this->Swimdata = $Factory->swimdata((int) $activityID);
     $this->Route = $this->Activity->get(Activity\Object::ROUTEID) ? $Factory->route($this->Activity->get(Activity\Object::ROUTEID)) : null;
     $this->HRV = $Factory->hrv((int) $activityID);
     $this->Sport = $Factory->sport($this->Activity->sportid());
     $this->Swimdata->fillDistanceArray($this->Trackdata);
     $this->Swimdata->fillSwolfArray($this->Trackdata);
     $this->Dataview = new Dataview($this->Activity);
 }
Ejemplo n.º 4
0
 public function testSimpleInsert()
 {
     $R = new Object(array(Object::ACTIVITYID => 1, Object::POOL_LENGTH => 2500, Object::STROKE => array(25, 20, 15, 20), Object::STROKETYPE => array(2, 2, 2, 2)));
     $I = new Inserter($this->PDO, $R);
     $I->setAccountID(1);
     $I->insert();
     $data = $this->PDO->query('SELECT * FROM `' . PREFIX . 'swimdata` WHERE `activityid`=1')->fetch(PDO::FETCH_ASSOC);
     $N = new Object($data);
     $this->assertEquals(1, $data[Inserter::ACCOUNTID]);
     $this->assertEquals(2500, $N->poollength());
     $this->assertEquals(array(25, 20, 15, 20), $N->stroke());
     $this->assertEquals(array(2, 2, 2, 2), $N->stroketype());
 }
Ejemplo n.º 5
0
 public function testSimpleUpdate()
 {
     $Inserter = new Inserter($this->PDO);
     $Inserter->setAccountID(1);
     $Inserter->insert(new Object(array(Object::ACTIVITYID => 1, Object::STROKE => array(25, 20, 15, 20))));
     $Swimdata = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'swimdata` WHERE `activityid`=1')->fetch(PDO::FETCH_ASSOC));
     $Swimdata->set(Object::STROKE, array());
     $Changed = clone $Swimdata;
     $Changed->set(Object::STROKETYPE, array(2, 2, 2, 2));
     $Updater = new Updater($this->PDO, $Changed, $Swimdata);
     $Updater->setAccountID(1);
     $Updater->update();
     $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'swimdata` WHERE `activityid`=1')->fetch(PDO::FETCH_ASSOC));
     $this->assertEquals(array(25, 20, 15, 20), $Result->stroke());
     $this->assertEquals(array(2, 2, 2, 2), $Result->stroketype());
 }
Ejemplo n.º 6
0
 /**
  * Calculate swim values
  */
 protected function calculateSwimValues()
 {
     if (null !== $this->Trackdata && null !== $this->Swimdata) {
         if ($this->Swimdata->stroke()) {
             $this->Object->set(Object::TOTAL_STROKES, array_sum($this->Swimdata->stroke()));
         }
         if ($this->Object->totalStrokes() && $this->Trackdata->totalTime()) {
             $num = $this->Trackdata->num();
             $totaltime = $this->Trackdata->totalTime();
             $totalstrokes = $this->Object->totalStrokes();
             if (!empty($totalstrokes) && !empty($totaltime) & !empty($num) && $totalstrokes != 0) {
                 $this->Object->set(Object::SWOLF, round(($totalstrokes + $totaltime) / $num));
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Keys to insert
  * @return array
  */
 protected function keys()
 {
     return array_merge(array(self::ACCOUNTID), array_diff(Object::allProperties(), array(Object::SWOLF, Object::SWOLFCYCLES)));
 }