コード例 #1
0
ファイル: TCX.php プロジェクト: dragosprotung/stc-core
 /**
  * {@inheritdoc}
  */
 public function fromString($string) : Workout
 {
     $simpleXML = new \SimpleXMLElement($string);
     $workout = new Workout();
     foreach ($simpleXML->Activities[0] as $simpleXMLActivity) {
         // Sport.
         $attributes = $simpleXMLActivity->attributes();
         $sport = SportMapperInterface::class;
         if (isset($attributes['Sport'])) {
             $sport = SportGuesser::sportFromCode((string) $attributes['Sport']);
         }
         $workoutTrack = new Track(array(), $sport);
         // Track points.
         foreach ($simpleXMLActivity->Lap as $lap) {
             foreach ($lap->Track as $track) {
                 foreach ($track->Trackpoint as $trackPoint) {
                     $dateTime = new \DateTime((string) $trackPoint->Time);
                     $latitude = (double) $trackPoint->Position->LatitudeDegrees;
                     $longitude = (double) $trackPoint->Position->LongitudeDegrees;
                     $workoutTrackPoint = new TrackPoint($latitude, $longitude, $dateTime);
                     $workoutTrackPoint->setElevation(round((double) $trackPoint->AltitudeMeters, 2));
                     if ($trackPoint->DistanceMeters) {
                         $workoutTrackPoint->setDistance($trackPoint->DistanceMeters);
                     }
                     $extensions = $this->parseExtensions($trackPoint);
                     $workoutTrackPoint->setExtensions($extensions);
                     $workoutTrack->addTrackPoint($workoutTrackPoint);
                 }
             }
         }
         $workout->addTrack($workoutTrack);
     }
     return $workout;
 }
コード例 #2
0
ファイル: GPXTest.php プロジェクト: dragosprotung/stc-core
 /**
  * Get a track point.
  *
  * @param float $lat The latitude.
  * @param float $lon The longitude.
  * @param string $time The time.
  * @param float $elevation The elevation.
  * @param integer $hr The heart rate.
  * @return TrackPoint
  */
 private function getTrackPoint(float $lat, float $lon, $time, float $elevation, $hr)
 {
     $trackPoint = new TrackPoint($lat, $lon, new \DateTime($time));
     $trackPoint->setElevation($elevation);
     $trackPoint->addExtension(new HR($hr));
     return $trackPoint;
 }
コード例 #3
0
ファイル: GPX.php プロジェクト: dragosprotung/stc-core
 /**
  * {@inheritdoc}
  */
 public function fromString($string) : Workout
 {
     $simpleXML = new \SimpleXMLElement($string);
     $workout = new Workout();
     if (isset($simpleXML->metadata->author->name)) {
         $workout->setAuthor(new Author($simpleXML->metadata->author->name));
     }
     foreach ($simpleXML->trk as $simpleXMLTrack) {
         // Sport.
         $sport = SportMapperInterface::class;
         if (isset($simpleXMLTrack->type)) {
             $sport = SportGuesser::sportFromCode((string) $simpleXMLTrack->type);
         }
         $track = new Track(array(), $sport);
         // Track points.
         foreach ($simpleXMLTrack->trkseg->trkpt as $point) {
             $attributes = $point->attributes();
             $dateTime = new \DateTime((string) $point->time);
             $trackPoint = new TrackPoint((double) $attributes['lat'], (double) $attributes['lon'], $dateTime);
             $trackPoint->setElevation((int) $point->ele);
             if (isset($point->extensions)) {
                 $trackPoint->setExtensions($this->parseExtensions($point->extensions));
             }
             $track->addTrackPoint($trackPoint);
         }
         $workout->addTrack($track);
     }
     return $workout;
 }
コード例 #4
0
ファイル: TCXTest.php プロジェクト: dragosprotung/stc-core
 /**
  * Get a track point.
  *
  * @param float $latitude The latitude.
  * @param float $longitude The longitude.
  * @param string $time The time.
  * @param float $distance The distance from start to that point.
  * @param integer $elevation The elevation.
  * @param integer $heartRate The heart rate.
  * @return TrackPoint
  */
 private function getTrackPoint(float $latitude, float $longitude, $time, $elevation, $distance = null, $heartRate = null)
 {
     $trackPoint = new TrackPoint($latitude, $longitude, new DateTime($time));
     $trackPoint->setElevation($elevation);
     $trackPoint->setDistance($distance);
     if ($heartRate !== null) {
         $trackPoint->setExtensions(array(new HR($heartRate)));
     }
     return $trackPoint;
 }