Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timer_time field to record #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ Allowed properties :
- `true`: Continues even if they are errors (**default for now**)
- `false`: Stops if an error occurs
- `elapsedRecordField`: Boolean
- `true`: Includes a `elapsed_time` field inside each `record` field, containing the elapsed time in seconds since the first record (**default**)
- `false`
- `true`: Includes `elapsed_time`, containing the elapsed time in seconds since the first record, and `timer_time`, containing the time shown on the device, inside each `record` field
- `false` (**default**)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like false is the default.


### easyFit.parse(Buffer _file_, Function _callback_)
_callback_ receives two arguments, the first as a error String, and the second as Object, result of parsing.
Expand Down
3 changes: 2 additions & 1 deletion dist/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function applyOptions(data, field, options) {
}
}

function readRecord(blob, messageTypes, startIndex, options, startDate) {
function readRecord(blob, messageTypes, startIndex, options, startDate, pausedTime) {
var recordHeader = blob[startIndex];
var localMessageType = recordHeader & 15;

Expand Down Expand Up @@ -228,6 +228,7 @@ function readRecord(blob, messageTypes, startIndex, options, startDate) {

if (message.name === 'record' && options.elapsedRecordField) {
fields.elapsed_time = (fields.timestamp - startDate) / 1000;
fields.timer_time = fields.elapsed_time - pausedTime;
}
}

Expand Down
14 changes: 12 additions & 2 deletions dist/easy-fit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ var EasyFit = function () {
var isModeCascade = this.options.mode === 'cascade';
var isCascadeNeeded = isModeCascade || this.options.mode === 'both';

var startDate = void 0;
var startDate = void 0,
lastStopTimestamp = void 0;
var pausedTime = 0;

while (loopIndex < crcStart) {
var _readRecord = (0, _binary.readRecord)(blob, messageTypes, loopIndex, this.options, startDate),
var _readRecord = (0, _binary.readRecord)(blob, messageTypes, loopIndex, this.options, startDate, pausedTime),
nextIndex = _readRecord.nextIndex,
messageType = _readRecord.messageType,
message = _readRecord.message;
Expand All @@ -122,12 +124,20 @@ var EasyFit = function () {
sessions.push(message);
break;
case 'event':
if (message.event === 'timer') {
if (message.event_type === 'stop_all') {
lastStopTimestamp = message.timestamp;
} else if (message.event_type === 'start' && lastStopTimestamp) {
pausedTime += (message.timestamp - lastStopTimestamp) / 1000;
}
}
events.push(message);
break;
case 'record':
if (!startDate) {
startDate = message.timestamp;
message.elapsed_time = 0;
message.timer_time = 0;
}
records.push(message);
if (isCascadeNeeded) {
Expand Down
3 changes: 2 additions & 1 deletion src/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function applyOptions(data, field, options) {
}
}

export function readRecord(blob, messageTypes, startIndex, options, startDate) {
export function readRecord(blob, messageTypes, startIndex, options, startDate, pausedTime) {
const recordHeader = blob[startIndex];
const localMessageType = (recordHeader & 15);

Expand Down Expand Up @@ -188,6 +188,7 @@ export function readRecord(blob, messageTypes, startIndex, options, startDate) {

if (message.name === 'record' && options.elapsedRecordField) {
fields.elapsed_time = (fields.timestamp - startDate) / 1000;
fields.timer_time = fields.elapsed_time - pausedTime;
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/easy-fit.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ export default class EasyFit {
const isModeCascade = this.options.mode === 'cascade';
const isCascadeNeeded = isModeCascade || this.options.mode === 'both';

let startDate;
let startDate, lastStopTimestamp;
let pausedTime = 0;

while (loopIndex < crcStart) {
const { nextIndex,
messageType,
message } = readRecord(blob, messageTypes, loopIndex, this.options, startDate);
message } = readRecord(blob, messageTypes, loopIndex, this.options, startDate, pausedTime);
loopIndex = nextIndex;
switch (messageType) {
case 'lap':
Expand All @@ -104,12 +105,20 @@ export default class EasyFit {
sessions.push(message);
break;
case 'event':
if (message.event === 'timer') {
if (message.event_type === 'stop_all') {
lastStopTimestamp = message.timestamp;
} else if (message.event_type === 'start' && lastStopTimestamp) {
pausedTime += (message.timestamp - lastStopTimestamp) / 1000;
}
}
events.push(message);
break;
case 'record':
if (!startDate) {
startDate = message.timestamp;
message.elapsed_time = 0;
message.timer_time = 0;
}
records.push(message);
if (isCascadeNeeded) {
Expand Down