-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor style updates, fixing the "combined" steps provider (#112)
* Fix steps daily data, other style tweaks * early exit * Fixing a couple other issues * Revert story change * Fix query device data to catch errors --------- Co-authored-by: Chris Nowak <chris@Christophers-MacBook-Pro.local>
- Loading branch information
1 parent
1c99f6b
commit c519952
Showing
8 changed files
with
64 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
import { add } from "date-fns"; | ||
import { appleHealthStepsDataProvider, fitbitStepsDataProvider, garminStepsDataProvider } from "."; | ||
import getDayKey from "../get-day-key"; | ||
import MyDataHelps from "@careevolution/mydatahelps-js"; | ||
|
||
export default function (startDate: Date, endDate: Date) { | ||
var fitbitSteps = fitbitStepsDataProvider(startDate, endDate); | ||
var appleSteps = appleHealthStepsDataProvider(startDate, endDate); | ||
var garminSteps = garminStepsDataProvider(startDate, endDate); | ||
let providers: Promise<{ [key: string]: number }>[] = []; | ||
|
||
return Promise.all([fitbitSteps, appleSteps, garminSteps]).then((values) => { | ||
var data: { [key: string]: number } = {}; | ||
while (startDate < endDate) { | ||
var dayKey = getDayKey(startDate); | ||
var steps: number | null = null; | ||
if (values[0][dayKey]) { | ||
steps = values[0][dayKey]; | ||
} | ||
return MyDataHelps.getDataCollectionSettings().then((settings) => { | ||
if (settings.fitbitEnabled) { | ||
providers.push(fitbitStepsDataProvider(startDate, endDate)); | ||
} | ||
if (settings.garminEnabled) { | ||
providers.push(garminStepsDataProvider(startDate, endDate)); | ||
} | ||
if (settings.queryableDeviceDataTypes.find(s => s.namespace == "AppleHealth" && s.type == "HourlySteps")) { | ||
providers.push(appleHealthStepsDataProvider(startDate, endDate)); | ||
} | ||
|
||
if (values[1][dayKey] && (steps == null || values[1][dayKey] > steps)) { | ||
steps = values[1][dayKey]; | ||
} | ||
if (steps) { | ||
data[dayKey] = steps; | ||
} | ||
startDate = add(startDate, { days: 1 }); | ||
if (!providers.length) { | ||
return {}; | ||
} | ||
return data; | ||
|
||
return Promise.all(providers).then((values) => { | ||
var data: { [key: string]: number } = {}; | ||
while (startDate < endDate) { | ||
var dayKey = getDayKey(startDate); | ||
var steps: number | null = null; | ||
values.forEach((value) => { | ||
if (value[dayKey] || steps == null || steps < value[dayKey]) { | ||
steps = value[dayKey]; | ||
} | ||
}); | ||
if (steps) { | ||
data[dayKey] = steps; | ||
} | ||
startDate = add(startDate, { days: 1 }); | ||
} | ||
return data; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters