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

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.

MyApp.swift
Swift
// Get stats for today
// getStats is deprecated in iOS SDK 1.4.0. Use getBiomarkers for new code.

Sahha.getStats(
    sensor: .steps,
    startDateTime: .now,
    endDateTime: .now)
{ error, stats in
    if let error = error {
        print(error)
    } else if stats.isEmpty == false {
        print(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.

MyApp.swift
Swift
// Get stats for last 7 days
// Add a date range
// getStats is deprecated in iOS SDK 1.4.0. Use getBiomarkers for new code.

let today = Date()
let sevenDaysAgo = Calendar.current.date(byAdding: .day, value: -7, to: today) ?? Date()

Sahha.getStats(
    sensor: .steps,
    startDateTime: sevenDaysAgo,
    endDateTime: today)
{ error, stats in
    if let error = error {
        print(error)
    } else if stats.isEmpty == false {
        print(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, stats are returned as an array of SahhaStat objects. For Android, they are returned as a list of SahhaStatistics objects.

SahhaStat.swift
Swift
public struct SahhaStat: Comparable, Codable, Sendable {
    public var id: String
    public var category: String
    public var type: String
    public var aggregation: String
    public var periodicity: String
    public var value: Double
    public var unit: String
    public var startDateTime: Date
    public var endDateTime: Date
    public var sources: [String]
}

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:

RESPONSE
JSON
[
	{
		"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.

RESPONSE
JSON
"No stats found"

Using SahhaSensor

Stats are grouped by SahhaSensor type.

For example, use getStats with the heart_rate sensor to get stats of a user's heart rate.

Choose a SahhaSensor

You must specify which SahhaSensor to use for getStats.

SahhaSensorAndroidiOS
genderSensor Not AvailableSensor Not Available
date_of_birthSensor Not AvailableSensor Not Available
sleep✔✔
steps✔✔
floors_climbed✔✔
heart_rate✔✔
resting_heart_rate✔✔
walking_heart_rate_averageSensor Not Available✔
heart_rate_variability_rmssdSensor Not AvailableSensor Not Available
heart_rate_variability_sdnnSensor Not Available✔
blood_pressure_systolic✔✔
blood_pressure_diastolic✔✔
blood_glucoseSensor Not Available✔
vo2_maxSensor Not Available✔
oxygen_saturationSensor Not Available✔
respiratory_rateSensor Not Available✔
active_energy_burned✔✔
basal_energy_burnedSensor Not Available✔
total_energy_burned✔Sensor Not Available
basal_metabolic_rate✔Sensor Not Available
time_in_daylightSensor Not Available✔
body_temperatureSensor Not Available✔
basal_body_temperatureSensor Not Available✔
sleeping_wrist_temperatureSensor Not Available✔
height✔✔
weight✔✔
lean_body_massSensor Not Available✔
body_mass_indexSensor Not Available✔
body_fatSensor Not Available✔
body_water_massSensor Not AvailableSensor Not Available
bone_massSensor Not AvailableSensor Not Available
waist_circumferenceSensor Not Available✔
stand_timeSensor Not Available✔
move_timeSensor Not Available✔
exercise_timeSensor Not Available✔
activity_summarySensor Not AvailableSensor Not Available
device_lockSensor Not AvailableSensor Not Available
exercise✔✔
energy_intakeSensor Not Available✔
water_intakeSensor Not Available✔
protein_intakeSensor Not Available✔
fat_intakeSensor Not Available✔
fat_saturated_intakeSensor Not Available✔
fat_monounsaturated_intakeSensor Not Available✔
fat_polyunsaturated_intakeSensor Not Available✔
cholesterol_intakeSensor Not Available✔
carbohydrate_intakeSensor Not Available✔
sugar_intakeSensor Not Available✔
fiber_intakeSensor Not Available✔
vitamin_a_intakeSensor Not Available✔
vitamin_c_intakeSensor Not Available✔
vitamin_d_intakeSensor Not Available✔
vitamin_e_intakeSensor Not Available✔
vitamin_k_intakeSensor Not Available✔
thiamin_intakeSensor Not Available✔
riboflavin_intakeSensor Not Available✔
niacin_intakeSensor Not Available✔
pantothenic_acid_intakeSensor Not Available✔
vitamin_b6_intakeSensor Not Available✔
biotin_intakeSensor Not Available✔
folate_intakeSensor Not Available✔
vitamin_b12_intakeSensor Not Available✔
calcium_intakeSensor Not Available✔
iron_intakeSensor Not Available✔
magnesium_intakeSensor Not Available✔
phosphorus_intakeSensor Not Available✔
potassium_intakeSensor Not Available✔
sodium_intakeSensor Not Available✔
zinc_intakeSensor Not Available✔
chloride_intakeSensor Not Available✔
copper_intakeSensor Not Available✔
manganese_intakeSensor Not Available✔
chromium_intakeSensor Not Available✔
molybdenum_intakeSensor Not Available✔
selenium_intakeSensor Not Available✔
iodine_intakeSensor Not Available✔
caffeine_intakeSensor Not Available✔
menstrual_flowSensor Not AvailableSensor Not Available
menstrual_periodSensor Not AvailableSensor Not Available
intermenstrual_bleedingSensor Not AvailableSensor Not Available
cervical_mucusSensor Not AvailableSensor Not Available
ovulation_testSensor Not AvailableSensor Not Available
sexual_activitySensor Not AvailableSensor Not Available
running_ground_contact_timeSensor Not Available✔
running_powerSensor Not Available✔
running_speedSensor Not Available✔
running_stride_lengthSensor Not Available✔
running_vertical_oscillationSensor Not Available✔
six_minute_walk_test_distanceSensor Not Available✔
stair_ascent_speedSensor Not Available✔
stair_descent_speedSensor Not Available✔
walking_asymmetry_percentageSensor Not Available✔
walking_double_support_percentageSensor Not Available✔
walking_speedSensor Not Available✔
walking_steadinessSensor Not Available✔
walking_step_lengthSensor Not Available✔
infrequent_menstrual_cyclesSensor Not AvailableSensor Not Available
irregular_menstrual_cyclesSensor Not AvailableSensor Not Available
persistent_intermenstrual_bleedingSensor Not AvailableSensor Not Available
prolonged_menstrual_periodsSensor Not AvailableSensor Not Available
contraceptiveSensor Not AvailableSensor Not Available
pregnancySensor Not AvailableSensor Not Available
pregnancy_testSensor Not AvailableSensor Not Available
progesterone_testSensor Not AvailableSensor Not Available
lactationSensor Not AvailableSensor Not Available
abdominal_crampsSensor Not AvailableSensor Not Available
acneSensor Not AvailableSensor Not Available
appetite_changesSensor Not AvailableSensor Not Available
bladder_incontinenceSensor Not AvailableSensor Not Available
bloatingSensor Not AvailableSensor Not Available
breast_painSensor Not AvailableSensor Not Available
chest_tightness_or_painSensor Not AvailableSensor Not Available
chillsSensor Not AvailableSensor Not Available
constipationSensor Not AvailableSensor Not Available
coughingSensor Not AvailableSensor Not Available
diarrheaSensor Not AvailableSensor Not Available
dizzinessSensor Not AvailableSensor Not Available
dry_skinSensor Not AvailableSensor Not Available
faintingSensor Not AvailableSensor Not Available
fatigueSensor Not AvailableSensor Not Available
feverSensor Not AvailableSensor Not Available
generalized_body_acheSensor Not AvailableSensor Not Available
hair_lossSensor Not AvailableSensor Not Available
headacheSensor Not AvailableSensor Not Available
heartburnSensor Not AvailableSensor Not Available
hot_flashesSensor Not AvailableSensor Not Available
loss_of_smellSensor Not AvailableSensor Not Available
loss_of_tasteSensor Not AvailableSensor Not Available
lower_back_painSensor Not AvailableSensor Not Available
memory_lapseSensor Not AvailableSensor Not Available
mood_changesSensor Not AvailableSensor Not Available
nauseaSensor Not AvailableSensor Not Available
night_sweatsSensor Not AvailableSensor Not Available
pelvic_painSensor Not AvailableSensor Not Available
rapid_pounding_or_fluttering_heartbeatSensor Not AvailableSensor Not Available
runny_noseSensor Not AvailableSensor Not Available
shortness_of_breathSensor Not AvailableSensor Not Available
sinus_congestionSensor Not AvailableSensor Not Available
skipped_heartbeatSensor Not AvailableSensor Not Available
sleep_changesSensor Not AvailableSensor Not Available
sore_throatSensor Not AvailableSensor Not Available
vaginal_drynessSensor Not AvailableSensor Not Available
vomitingSensor Not AvailableSensor Not Available
wheezingSensor Not AvailableSensor Not Available
nutritionSensor Not Available✔
reproductiveSensor Not AvailableSensor Not Available
symptomSensor Not AvailableSensor Not Available
Docs