title: GoogleFit Rest API - Correct aggregate data source for daily steps
body: <p>The APIs documentation says that, to get a result like the Google Fit App, one should request the steps of the <code>derived:com.google.step_count.delta:com.google.android.gms:estimated_steps</code> datasource
  <a href="https://developers.google.com/fit/scenarios/read-daily-step-total" rel="nofollow noreferrer">https://developers.google.com/fit/scenarios/read-daily-step-total</a>
  <a href="https://developers.google.com/fit/faq#get-step-count" rel="nofollow noreferrer">https://developers.google.com/fit/faq#get-step-count</a></p>
  
  <p>In practice, it mostly seems right but, occasionaly, the results are way off.</p>
  
  <p>Doing some tests, I noticed that, sometimes, using the <code>derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas</code> datasource gets me better results or, at least, values more similar to the ones showed in the Google Fit app.</p>
  
  <p>I think though that, if a user uses more devices to count the steps, this datasource will get me all the steps combined and that's wrong.</p>
  
  <p>Is it correct to use the <code>estimated_steps</code> datasource or should I switch to the <code>merge_step_deltas</code> one?
  Or is it something else I can do to get the correct number of steps?</p>
  
  <h1>Real example</h1>
  
  <p>A client's steps don't match with the ones showed by the Google Fit app.</p>
  
  <p>Here are his datasources list</p>
  
  <pre class="lang-json prettyprint-override"><code>{
    "dataSource": [
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "duration", 
              "format": "integer"
            }
          ], 
          "name": "com.google.active_minutes"
        }, 
        "dataStreamName": "from_activity&lt;-merge_activity_segments", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.active_minutes:com.google.android.gms:from_activity&lt;-merge_activity_segments", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "duration", 
              "format": "integer"
            }
          ], 
          "name": "com.google.active_minutes"
        }, 
        "dataStreamName": "from_steps&lt;-estimated_steps", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.active_minutes:com.google.android.gms:from_steps&lt;-estimated_steps", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "duration", 
              "format": "integer"
            }
          ], 
          "name": "com.google.active_minutes"
        }, 
        "dataStreamName": "merge_active_minutes", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.active_minutes:com.google.android.gms:merge_active_minutes", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "activity", 
              "format": "integer"
            }
          ], 
          "name": "com.google.activity.segment"
        }, 
        "dataStreamName": "merge_activity_segments", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "activity", 
              "format": "integer"
            }
          ], 
          "name": "com.google.activity.segment"
        }, 
        "dataStreamName": "platform_activity_segments", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.activity.segment:com.google.android.gms:platform_activity_segments", 
        "type": "derived"
      }, 
      {
        "dataStreamName": "activity_from_steps", 
        "dataType": {
          "field": [
            {
              "name": "activity", 
              "format": "integer"
            }
          ], 
          "name": "com.google.activity.segment"
        }, 
        "dataQualityStandard": [], 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "device": {
          "model": "SM-A600FN", 
          "version": "", 
          "type": "phone", 
          "uid": "324bd687", 
          "manufacturer": "samsung"
        }, 
        "dataStreamId": "derived:com.google.activity.segment:com.google.android.gms:samsung:SM-A600FN:324bd687:activity_from_steps", 
        "type": "derived"
      }, 
      {
        "dataStreamName": "from_activity_samples&lt;-derived:com.google.activity.samples:com.google.android.gms:samsung:SM-A600FN:324bd687:detailed", 
        "dataType": {
          "field": [
            {
              "name": "activity", 
              "format": "integer"
            }
          ], 
          "name": "com.google.activity.segment"
        }, 
        "dataQualityStandard": [], 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "device": {
          "model": "SM-A600FN", 
          "version": "", 
          "type": "phone", 
          "uid": "324bd687", 
          "manufacturer": "samsung"
        }, 
        "dataStreamId": "derived:com.google.activity.segment:com.google.android.gms:samsung:SM-A600FN:324bd687:from_activity_samples&lt;-derived:com.google.activity.samples:com.google.android.gms:samsung:SM-A600FN:324bd687:detailed", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "calories", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.calories.expended"
        }, 
        "dataStreamName": "from_activities", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.calories.expended:com.google.android.gms:from_activities", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "calories", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.calories.expended"
        }, 
        "dataStreamName": "merge_calories_expended", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.calories.expended:com.google.android.gms:merge_calories_expended", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "calories", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.calories.expended"
        }, 
        "dataStreamName": "platform_calories_expended", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.calories.expended:com.google.android.gms:platform_calories_expended", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "intensity", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.heart_minutes"
        }, 
        "dataStreamName": "from_activity&lt;-merge_activity_segments", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.heart_minutes:com.google.android.gms:from_activity&lt;-merge_activity_segments", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "intensity", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.heart_minutes"
        }, 
        "dataStreamName": "from_heart_rate&lt;-merge_heart_rate_bpm", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.heart_minutes:com.google.android.gms:from_heart_rate&lt;-merge_heart_rate_bpm", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "intensity", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.heart_minutes"
        }, 
        "dataStreamName": "from_steps&lt;-estimated_steps", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.heart_minutes:com.google.android.gms:from_steps&lt;-estimated_steps", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "intensity", 
              "format": "floatPoint"
            }
          ], 
          "name": "com.google.heart_minutes"
        }, 
        "dataStreamName": "merge_heart_minutes", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes", 
        "type": "derived"
      }, 
      {
        "dataStreamName": "soft_step_counter", 
        "dataType": {
          "field": [
            {
              "name": "steps", 
              "format": "integer"
            }
          ], 
          "name": "com.google.step_count.cumulative"
        }, 
        "dataQualityStandard": [], 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "device": {
          "model": "SM-A600FN", 
          "version": "", 
          "type": "phone", 
          "uid": "324bd687", 
          "manufacturer": "samsung"
        }, 
        "dataStreamId": "derived:com.google.step_count.cumulative:com.google.android.gms:samsung:SM-A600FN:324bd687:soft_step_counter", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "steps", 
              "format": "integer"
            }
          ], 
          "name": "com.google.step_count.delta"
        }, 
        "dataStreamName": "estimated_steps", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", 
        "type": "derived"
      }, 
      {
        "dataQualityStandard": [], 
        "dataType": {
          "field": [
            {
              "name": "steps", 
              "format": "integer"
            }
          ], 
          "name": "com.google.step_count.delta"
        }, 
        "dataStreamName": "merge_step_deltas", 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "dataStreamId": "derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas", 
        "type": "derived"
      }, 
      {
        "dataStreamName": "derive_step_deltas&lt;-derived:com.google.step_count.cumulative:com.google.android.gms:samsung:SM-A600FN:324bd687:soft_step_counter", 
        "dataType": {
          "field": [
            {
              "name": "steps", 
              "format": "integer"
            }
          ], 
          "name": "com.google.step_count.delta"
        }, 
        "dataQualityStandard": [], 
        "application": {
          "packageName": "com.google.android.gms"
        }, 
        "device": {
          "model": "SM-A600FN", 
          "version": "", 
          "type": "phone", 
          "uid": "324bd687", 
          "manufacturer": "samsung"
        }, 
        "dataStreamId": "derived:com.google.step_count.delta:com.google.android.gms:samsung:SM-A600FN:324bd687:derive_step_deltas&lt;-derived:com.google.step_count.cumulative:com.google.android.gms:samsung:SM-A600FN:324bd687:soft_step_counter", 
        "type": "derived"
      }, 
      {
        "name": "Generic ANT+ Sensor", 
        "dataStreamName": "AntPlus.0.124", 
        "dataType": {
          "field": [
            {
              "name": "steps", 
              "format": "integer"
            }
          ], 
          "name": "com.google.step_count.delta"
        }, 
        "dataQualityStandard": [], 
        "application": {
          "packageName": "com.dsi.ant.plugins.antplus"
        }, 
        "dataStreamId": "raw:com.google.step_count.delta:com.dsi.ant.plugins.antplus:AntPlus.0.124", 
        "type": "raw"
      }
    ]
  }
  </code></pre>
  
  <p>On the day of May 2nd, the app shows something like 15000 steps (matched by the <code>merge_step_deltas</code> datasource) while requesting the steps from the <code>estimated_steps</code> datasource gets me about 7000 steps.</p>
  
  <p><code>derived:com.google.step_count.delta:com.google.android.gms:estimated_steps</code></p>
  
  <pre class="lang-json prettyprint-override"><code>{
    "bucket": [
      {
        "startTimeMillis": "1556748000000", 
        "endTimeMillis": "1556834400000", 
        "dataset": [
          {
            "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:aggregated", 
            "point": [
              {
                "startTimeNanos": "1556748469517481594", 
                "originDataSourceId": "derived:com.google.step_count.cumulative:com.google.android.gms:samsung:SM-A600FN:4dc460aaeb28b288:soft_step_counter", 
                "endTimeNanos": "1556831065968126307", 
                "value": [
                  {
                    "mapVal": [], 
                    "intVal": 7601
                  }
                ], 
                "dataTypeName": "com.google.step_count.delta"
              }
            ]
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p><code>derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas</code></p>
  
  <pre class="lang-json prettyprint-override"><code>{
    "bucket": [
      {
        "startTimeMillis": "1556748000000", 
        "endTimeMillis": "1556834400000", 
        "dataset": [
          {
            "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:aggregated", 
            "point": [
              {
                "startTimeNanos": "1556748469517481594", 
                "originDataSourceId": "derived:com.google.step_count.cumulative:com.google.android.gms:samsung:SM-A600FN:4dc460aaeb28b288:soft_step_counter", 
                "endTimeNanos": "1556831065968126307", 
                "value": [
                  {
                    "mapVal": [], 
                    "intVal": 15368
                  }
                ], 
                "dataTypeName": "com.google.step_count.delta"
              }
            ]
          }
        ]
      }
    ]
  }
  </code></pre>