Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit b65562c

Browse files
committed
added isPaused()
1 parent 8f29f4e commit b65562c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ $pFFA->criticalPower($time_periods); // e.g. 300 or [300, 600, 900, 1200]
303303

304304
Note that ```$pFFA->criticalPower``` and some power metrics (Normalised Power, Variability Index, Intensity Factor, Training Stress Score) will use the [PHP Trader](http://php.net/manual/en/book.trader.php) extension if it is loaded on the server. If the extension is not loaded then it will use the built-in Simple Moving Average algorithm, which is far less performant particularly for larger files!
305305

306-
307306
A demo of power analysis is available [here](http://www.adriangibbons.com/php-fit-file-analysis/demo/power-analysis.php).
308307

308+
##Other methods
309+
```isPaused()``` - Returns array of booleans using timestamp as key. true == timer paused (e.g. autopause).
310+
309311
##Acknowledgement
310312
This class has been created using information available in a Software Development Kit (SDK) made available by ANT ([thisisant.com](http://www.thisisant.com/resources/fit)).
311313

src/phpFITFileAnalysis.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,55 @@ public function criticalPower($time_periods)
17871787
}
17881788
}
17891789

1790+
/**
1791+
* Returns array of booleans using timestamp as key.
1792+
* true == timer paused (e.g. autopause)
1793+
*/
1794+
public function isPaused()
1795+
{
1796+
/**
1797+
* Event enumerated values of interest
1798+
* 0 = timer
1799+
*/
1800+
$tek = array_keys($this->data_mesgs['event']['event'], 0); // timer event keys
1801+
1802+
$timer_start = [];
1803+
$timer_stop = [];
1804+
foreach ($tek as $v) {
1805+
if ($this->data_mesgs['event']['event_type'][$v] === 0) {
1806+
$timer_start[$v] = $this->data_mesgs['event']['timestamp'][$v];
1807+
}
1808+
elseif ($this->data_mesgs['event']['event_type'][$v] === 4) {
1809+
$timer_stop[$v] = $this->data_mesgs['event']['timestamp'][$v];
1810+
}
1811+
}
1812+
1813+
$first_ts = min($this->data_mesgs['record']['timestamp']); // first timestamp
1814+
$last_ts = max($this->data_mesgs['record']['timestamp']); // last timestamp
1815+
1816+
reset($timer_start);
1817+
$cur_start = next($timer_start);
1818+
$cur_stop = reset($timer_stop);
1819+
1820+
$is_paused = [];
1821+
$bPaused = false;
1822+
1823+
for ($i = $first_ts; $i < $last_ts; ++$i) {
1824+
if ($i == $cur_stop) {
1825+
$bPaused = true;
1826+
$cur_stop = next($timer_stop);
1827+
}
1828+
elseif ($i == $cur_start) {
1829+
$bPaused = false;
1830+
$cur_start = next($timer_start);
1831+
}
1832+
$is_paused[$i] = $bPaused;
1833+
}
1834+
$is_paused[$last_ts] = end($this->data_mesgs['record']['speed']) == 0 ? true : false;
1835+
1836+
return $is_paused;
1837+
}
1838+
17901839
/**
17911840
* Outputs tables of information being listened for and found within the processed FIT file.
17921841
*/

0 commit comments

Comments
 (0)