Skip to content

Commit

Permalink
Further minor improvements to the FIT parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
igoramadas committed Nov 28, 2024
1 parent 41704b9 commit c272892
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/fitparser/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function readData(blob, fDef, startIndex) {
temp.push(blob[startIndex + i])
}
}
return Buffer.from(temp).toString("utf-8")
return Buffer.from(temp).toString("utf8")
}

if (fDef.type === "byte_array") {
Expand Down Expand Up @@ -108,7 +108,6 @@ function formatByType(data, type, scale, offset) {
case "uint32_array":
case "uint16_array":
return data.map((dataItem) => dataRounder(dataItem, scale, offset))
case "string":
default:
if (!FIT.types[type]) {
return data
Expand Down Expand Up @@ -268,7 +267,8 @@ export function readRecord(blob, messageTypes, developerFields, startIndex, opti
endianAbility: (baseType & 128) === 128,
littleEndian: lEnd,
baseTypeNo: baseType & 15,
name: field
name: field,
dataType: baseType & 15
}

mTypeDef.fieldDefs.push(fDef)
Expand All @@ -294,6 +294,7 @@ export function readRecord(blob, messageTypes, developerFields, startIndex, opti
littleEndian: lEnd,
baseTypeNo: baseType & 15,
name: devDef.field_name,
dataType: baseType & 15,
scale: devDef.scale || 1,
offset: devDef.offset || 0,
developerDataIndex: devDataIndex,
Expand Down
6 changes: 4 additions & 2 deletions src/fitparser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ export class FitParser {

// Get Sport profile.
for (let sp of fitObj.sports) {
if (sp.name) {
fitFileActivity.sportProfile = sp.name.replace(/[\u{0080}-\u{FFFF}]/gu, "")
if (!fitFileActivity.sportProfile && sp.name) {
fitFileActivity.sportProfile = sp.name.replace(/\\u[\dA-F]{4}/gi, (unicode) => {
return String.fromCharCode(parseInt(unicode.replace(/\\u/g, ""), 16))
})
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/loghelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {StravaActivity, StravaProcessedActivity} from "./strava/types"
import {BaseSubscription} from "./subscriptions/types"
import {UserData} from "./users/types"
import {WahooWebhookData} from "./wahoo/types"
import _ from "lodash"

/**
* Helper to get activity details for logging.
Expand Down Expand Up @@ -39,7 +40,7 @@ export const garminPing = (lPing: GarminPingActivityFile): string => {
*/
export const fitFileActivity = (lActivity: FitFileActivity): string => {
if (!lActivity) return "Activity unknown"
const details = [lActivity.name, lActivity.sportProfile, lActivity.workoutName]
const details = _.compact([lActivity.name, lActivity.sportProfile, lActivity.workoutName])
return `FIT ${lActivity.id} - ${details.join(", ")}`
}

Expand Down

0 comments on commit c272892

Please sign in to comment.