Skip to content

Commit

Permalink
[Bugfix] Bug fixes
Browse files Browse the repository at this point in the history
Fix bug at generate heart_rate on physical activity resource.
  • Loading branch information
lucasrochagit committed Jan 23, 2020
1 parent 5d35a37 commit fbab7e2
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/infrastructure/repository/fitbit.data.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,21 @@ export class FitbitDataRepository implements IFitbitDataRepository {
private parsePhysicalActivity(item: any, userId: string): PhysicalActivity {
if (!item) return item

const heartrate: any = { average: undefined, heart_rate_zones: undefined }
const activity: any = {
type: 'physical_activity',
start_time: moment(item.startTime).utc().format(),
end_time: moment(item.startTime).add(item.duration, 'milliseconds').utc().format(),
duration: item.duration,
child_id: userId,
name: item.activityName,
calories: item.calories,
steps: item.steps,
distance: item.distance ? this.convertDistanceToMetter(item.distance, item.distanceUnit) : undefined,
levels: item.activityLevel.map(level => {
return { duration: level.minutes * 60000, name: level.name }
})
}
if (item.averageHeartRate !== undefined && item.heartRateZones !== undefined) {
heartrate.average = item.averageHeartRate

const out_of_range = item.heartRateZones.filter(zone => zone.name = 'Out of Range')[0]
const fat_burn = item.heartRateZones.filter(zone => zone.name = 'Fat Burn')[0]
Expand All @@ -654,24 +666,10 @@ export class FitbitDataRepository implements IFitbitDataRepository {
const cardio_zone = { min: cardio.min, max: cardio.max, duration: cardio.minutes * 60000 }
const peak_zone = { min: peak.min, max: peak.max, duration: peak.minutes * 60000 }

heartrate.heart_rate_zones = { out_of_range_zone, fat_burn_zone, cardio_zone, peak_zone }
}
activity.heart_rate = { average: item.averageHeartRate, out_of_range_zone, fat_burn_zone, cardio_zone, peak_zone }

return new PhysicalActivity().fromJSON({
type: 'physical_activity',
start_time: moment(item.startTime).utc().format(),
end_time: moment(item.startTime).add(item.duration, 'milliseconds').utc().format(),
duration: item.duration,
child_id: userId,
name: item.activityName,
calories: item.calories,
steps: item.steps,
distance: item.distance ? this.convertDistanceToMetter(item.distance, item.distanceUnit) : undefined,
levels: item.activityLevel.map(level => {
return { duration: level.minutes * 60000, name: level.name }
}),
heart_rate: heartrate.average && heartrate.heart_rate_zones ? heartrate : undefined
})
}
return new PhysicalActivity().fromJSON(activity)
}

private convertDistanceToMetter(distance: number, unit: string): number {
Expand Down

0 comments on commit fbab7e2

Please sign in to comment.