diff --git a/src/fit/activity.js b/src/fit/activity.js index f94b78f..ecc7fd8 100644 --- a/src/fit/activity.js +++ b/src/fit/activity.js @@ -151,6 +151,7 @@ function Session(args = {}) { avg_heart_rate: 0, max_heart_rate: 0, total_distance: 0, // meters + total_calories: 0, }; let encoders = { @@ -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 = [ @@ -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}) ]; diff --git a/src/fit/local-message-definitions.js b/src/fit/local-message-definitions.js index 2eb5af1..de7fae0 100644 --- a/src/fit/local-message-definitions.js +++ b/src/fit/local-message-definitions.js @@ -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}, @@ -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: {