Skip to content

Commit

Permalink
Merge pull request #170 from dvmarinoff/develop
Browse files Browse the repository at this point in the history
add total calories to .FIT file
  • Loading branch information
dvmarinoff authored Dec 14, 2023
2 parents 9213241 + 76b82f5 commit bb218fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/fit/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function Session(args = {}) {
avg_heart_rate: 0,
max_heart_rate: 0,
total_distance: 0, // meters
total_calories: 0,
};

let encoders = {
Expand Down Expand Up @@ -230,13 +231,16 @@ function decode(args = {}) {
}

function encode(args = {}) {
const records = existance(args.records);
const laps = existance(args.laps);
const now = existance(args.now, Date.now());
const time_created = now;
const timestamp = now;
const num_laps = laps.length;
const summary = Summary({records: records});
const records = existance(args.records);
const laps = existance(args.laps);
const now = existance(args.now, Date.now());
const time_created = now;
const timestamp = now;
const num_laps = laps.length;
const summary = Summary({records: records});
const total_calories = summary.avg_power * records.length / 1000;

console.log(`:activity :total-calories ${total_calories}`);

// records and laps to FITjs
const fitjs = [
Expand All @@ -257,7 +261,7 @@ function encode(args = {}) {
start_time: l.startTime,
message_index: i})),
lmd.session,
Session(Object.assign({timestamp, num_laps}, summary)),
Session(Object.assign({timestamp, num_laps, total_calories,}, summary)),
lmd.activity,
Activity({timestamp})
];
Expand Down
5 changes: 3 additions & 2 deletions src/fit/local-message-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const localMessageDefinitions = {
type: 'definition',
message: 'session',
local_number: 5,
length: 6+(18*3),
data_msg_length: 1+40,
length: 6+(19*3),
data_msg_length: 1+42,
fields: [
{field: 'timestamp', number: 253, size: 4, base_type: 134},
{field: 'start_time', number: 2, size: 4, base_type: 134},
Expand All @@ -101,6 +101,7 @@ const localMessageDefinitions = {
{field: 'avg_heart_rate', number: 16, size: 1, base_type: 2},
{field: 'max_heart_rate', number: 17, size: 1, base_type: 2},
{field: 'total_distance', number: 9, size: 4, base_type: 134},
{field: 'total_calories', number: 11, size: 2, base_type: 132},
]
},
activity: {
Expand Down

1 comment on commit bb218fc

@vercel
Copy link

@vercel vercel bot commented on bb218fc Dec 14, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.