Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
import power data from fit files
Browse files Browse the repository at this point in the history
  • Loading branch information
laufhannes committed Sep 10, 2015
1 parent 35227b5 commit aa6e4f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion inc/import/parser/class.ParserFITSingle.php
Expand Up @@ -189,7 +189,7 @@ protected function readFileId() {
* Read device info
*/
protected function readDeviceInfo() {
if (isset($this->Values['garmin_product']))
if (isset($this->Values['garmin_product']) && isset($this->Values['device_index']) && $this->Values['device_index'][0] == 0)
$this->TrainingObject->setCreator($this->Values['garmin_product'][1]);
}

Expand Down Expand Up @@ -308,6 +308,8 @@ protected function readRecord() {
$this->gps['km'][] = isset($this->Values['distance']) ? round($this->Values['distance'][0] / 1e5, ParserAbstract::DISTANCE_PRECISION) : end($this->gps['km']);
$this->gps['heartrate'][] = isset($this->Values['heart_rate']) ? (int)$this->Values['heart_rate'][0] : 0;
$this->gps['rpm'][] = isset($this->Values['cadence']) ? (int)$this->Values['cadence'][0] : 0;
$this->gps['power'][] = isset($this->Values['power']) ? (int)$this->Values['power'][0] : 0;
//$this->gps['left_right'][] = isset($this->Values['left_right_balance']) ? (int)$this->Values['left_right_balance'][0] : 0;

$this->gps['temp'][] = isset($this->Values['temperature']) ? (int)$this->Values['temperature'][0] : 0;

Expand Down
26 changes: 26 additions & 0 deletions tests/inc/import/filetypes/ImporterFiletypeFITTest.php
Expand Up @@ -354,4 +354,30 @@ public function testHRV() {

}
}

/*
* Test: with power data
* Filename: "with-power.fit"
*/
public function testWithPowerData() {
if (Shell::isPerlAvailable()) {
$this->object->parseFile('../tests/testfiles/fit/with-power.fit');

$this->assertFalse( $this->object->hasMultipleTrainings() );
$this->assertFalse( $this->object->failed() );

$this->assertEquals('edge810', $this->object->object()->getCreator());
$this->assertEquals(3600 + 18*60 + 9, $this->object->object()->getTimeInSeconds());
$this->assertEquals(39.023, $this->object->object()->getDistance());

$this->assertTrue($this->object->object()->hasArrayTime());
$this->assertTrue($this->object->object()->hasArrayDistance());
$this->assertTrue($this->object->object()->hasArrayAltitude());
$this->assertTrue($this->object->object()->hasArrayHeartrate());
$this->assertTrue($this->object->object()->hasArrayCadence());
$this->assertTrue($this->object->object()->hasArrayTemperature());
$this->assertTrue($this->object->object()->hasArrayPower());

}
}
}
Binary file added tests/testfiles/fit/with-power.fit
Binary file not shown.

0 comments on commit aa6e4f6

Please sign in to comment.