Data Flow

Stats

Overview

Sahha provides your app with daily stats directly from Apple Health and Google Health Connect.

Stats are daily summaries of user activity.

For example:

  • the total number of steps taken in a day
  • the average heart rate for a day
  • the total minutes slept at night
Sahha Stats

Stats are calculated in realtime for a 24 hour period

Using the getStats method will give you the most up-to-date calculation for a SahhaSensor for the current day.

For example, if you'd like to monitor a user's daily steps, you can call getStats(.steps) multiple times during the day - we suggest using it everytime the user opens your app.

The total number of steps for the current day will continue to increase until midnight in the user's local timezone.

This is very useful for monitoring daily changes in user activity.

After midnight, a new day will begin and a new stat will start to be calculated.

Using getStats for previous days will always return the total value that was calculated at midnight for that day.


Get stats for today

Get the most recent stats for the current day in the user's local timezone.

// Get stats for today
// Leave date range empty
Sahha.getStats(
SahhaSensor.steps,
Pair(LocalDateTime.now(), LocalDateTime.now())
) { error, stats ->
error?.also {
println(error)
}
stats?.also {
println(stats)
}
}

Get stats for the last week

You can provide a data range if you would like to receive multiple stats over a specific time period. The response will include an array of stats for each 24 hour segment in that time period.

// Get stats for last 7 days
// Add a date range
Sahha.getStats(
sensor = SahhaSensor.steps,
dates = Pair(LocalDateTime.now().minusDays(7), LocalDateTime.now())
) { error, stats ->
error?.also {
println(error)
}
stats?.also {
println(stats)
}
}

Stat response

Stats are returned as an array of objects in JSON format.

  • Parameters :
    • id: UUID for the stat
    • type: The type of the stat ( steps, sleep, etc.)
    • startDateTime: Start date-time in "yyyy-MM-dd'T'HH:mm:ss.SSZZZZZ" format ( "2021-10-27T16:34:06-06:00")
    • endDateTime: End date-time in "yyyy-MM-dd'T'HH:mm:ss.SSZZZZZ" format ( "2021-10-27T16:44:06-06:00")
    • value: Numerical value of the stat ( 100, 200, etc.)
    • unit: The unit for measuring the value ( count, minute, kg, bpm, etc.)
    • sources: An array of sources which recorded the stat in com.company.app format ( ["com.apple.health"])

For iOS and Android, stats are returned as an array of objects in SahhaStat format.

data class SahhaStat(
val id: String,
val type: String,
val value: Double,
val unit: String,
val startDateTime: ZonedDateTime,
val endDateTime: ZonedDateTime,
val sources: List<String> = emptyList(),
)

Array response

Stats are returned as an array of objects in JSON format.

Older stats will be at the start of the array.

Newer stats will be at the end of the array.

An example response includes these fields:

[
{
"value": 5616,
"id": "464A029C-D2B6-4A49-A94F-01BFEC642CBA",
"sources": ["com.apple.health.0C1972B1-DBA3-4B25-9FE7-E9C00DF1DCE6"],
"unit": "count",
"startDateTime": "2024-12-13T00:00:00.00+09:00",
"endDateTime": "2024-12-14T00:00:00.00+09:00",
"type": "steps"
},
{
"value": 7576,
"sources": ["com.apple.health.0C1972B1-DBA3-4B25-9FE7-E9C00DF1DCE6"],
"endDateTime": "2024-12-15T00:00:00.00+09:00",
"unit": "count",
"id": "A3313BE9-AD16-4C1B-B8DE-0D1916A517F1",
"type": "steps",
"startDateTime": "2024-12-14T00:00:00.00+09:00"
},
{
"startDateTime": "2024-12-15T00:00:00.00+09:00",
"type": "steps",
"sources": ["com.apple.health.0C1972B1-DBA3-4B25-9FE7-E9C00DF1DCE6"],
"unit": "count",
"id": "24CB1DE7-7B3B-40CE-BF51-1584364991C3",
"value": 227,
"endDateTime": "2024-12-16T00:00:00.00+09:00"
}
]

Empty response

If no stats are found for the SahhaSensor and time period you specify, you will receive an error message.

"No stats found"

Using SahhaSensor

Stats are grouped by SahhaSensor type.

For example, use getStats(.heartRate) to get stats of a user's heart rate.

Choose a SahhaSensor

You must specify which SahhaSensor to use for getStats.

SahhaSensor Android iOS
gender Sensor Not Available Sensor Not Available
date_of_birth Sensor Not Available Sensor Not Available
sleep
steps
floors_climbed
heart_rate
resting_heart_rate
walking_heart_rate_average Sensor Not Available
heart_rate_variability_rmssd Sensor Not Available
heart_rate_variability_sdnn Sensor Not Available
blood_pressure_systolic Sensor Not Available
blood_pressure_diastolic Sensor Not Available
blood_glucose Sensor Not Available
vo2_max Sensor Not Available
oxygen_saturation Sensor Not Available
respiratory_rate Sensor Not Available
active_energy_burned
basal_energy_burned Sensor Not Available
total_energy_burned Sensor Not Available
basal_metabolic_rate Sensor Not Available
time_in_daylight Sensor Not Available
body_temperature Sensor Not Available
basal_body_temperature Sensor Not Available
sleeping_wrist_temperature Sensor Not Available
height
weight
lean_body_mass Sensor Not Available
body_mass_index Sensor Not Available
body_fat Sensor Not Available
body_water_mass Sensor Not Available Sensor Not Available
bone_mass Sensor Not Available Sensor Not Available
waist_circumference Sensor Not Available
stand_time Sensor Not Available
move_time Sensor Not Available
exercise_time Sensor Not Available
activity_summary Sensor Not Available Sensor Not Available
device_lock Sensor Not Available Sensor Not Available
exercise Sensor Not Available