Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I get the total per day? #388

Open
bitdelve opened this issue Oct 1, 2024 · 1 comment
Open

How do I get the total per day? #388

bitdelve opened this issue Oct 1, 2024 · 1 comment

Comments

@bitdelve
Copy link

bitdelve commented Oct 1, 2024

I see that the returned results for getDailyStepCountSamples returns multiple objects per day. Is there a way to have it return the total for each day?

@seanblonien
Copy link

seanblonien commented Oct 4, 2024

not that I am aware of. I use the getDailyStepCountSamples API and then simply do the aggregation into a day with the given start/end timestamps myself. I am unsure if the API guarantees a standard interval/range for each object returned, so knowing that, it is left up to you to decide how to aggregate the data according to your domain/user requirements.

for example, your definition of what a "day" is may change if you are doing absolute timing (i.e. every time is in UTC) vs. doing day aggregations based on relative timing (i.e. in a timezone offset). I recommend always store data as UTC, and simply present it to your users in their local timezone, but the point is it is YOUR decision as the developer what constitutes a "day" and so you have to program that aggregation yourself

it's quite simply tho conceptually, in rough pseudo code for it:

// ⬇️ your specific aggregate function below
// ...may be simply determining if same calendar day for example
const getHealthValueKey = (value: HealthValue) => { //... } 

const steps: HealthValue[] = getDailyStepCountSamples();

const stepsAggregatedByDay = steps.reduce((accum, current) => {
    const key = getKey(current);
    const existingValue = accum[key];

    if (existingValue) {
      existingValue.value += current.value; // Aggregate the value for the same key
    } else {
      accum[key] = { ...current }; // Create a new entry for this key
    }

    return accum;
  }, {});

const stepsAggregatedByDayArray = Object.values(stepsAggregatedByDay);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants