---
title: Scores
---


## Overview

Sahha analyzes user data such as sleep, steps and more to create daily scores which you can display to your users.

Use the the `getScores` method to return a variety of [Sahha Health Scores](/docs/products/scores).

---

## Get scores for today

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

{% tabs %}

{% tab label="iOS" %}

```swift title=MyApp.swift
// Get scores for last 24 hours

Sahha.getScores(
  types: [.wellbeing, .activity, .sleep],
  startDateTime: .now,
  endDateTime: .now)
  { error, json in
    if let error = error {
        print(error)
    } else if let json = json {
        print(json)
    }
}
```

{% /tab %}

{% tab label="Android" %}

```kotlin title=MainActivity.kt
// Get scores for last 24 hours
// Leave date range empty

Sahha.getScores(
  setOf(SahhaScoreType.wellbeing, SahhaScoreType.activity, SahhaScoreType.sleep)
	) { error, success ->
    error?.also {
        println(error)
    }
    success?.also {
        println(success)
    }
}
```

{% /tab %}

{% tab label="Flutter" %}

```typescript title=MyApp.dart
// Get scores for last 24 hours
// Leave date range empty

SahhaFlutter.getScores(
  types: [SahhaScoreType.activity, SahhaScoreType.sleep, SahhaScoreType.wellbeing],
  startDateTime: DateTime.now(),
  endDateTime: DateTime.now())
.then((value) {
    List<dynamic> data = jsonDecode(value);
    debugPrint(data.toString());
}).catchError((error, stackTrace) => {debugPrint(error.toString())});
```

{% /tab %}

{% tab label="React Native" %}

```typescript title=MyApp.tsx
// Get scores for last 24 hours
// Leave date range empty

let date = new Date();

Sahha.getScores(
	[SahhaScoreType.activity, SahhaScoreType.sleep, SahhaScoreType.wellbeing],
	date.getTime(),
	date.getTime(),
	(error: string, value: string) => {
		if (error) {
			console.error(`Error: ${error}`);
		} else if (value) {
			const jsonArray = JSON.parse(value);
			const jsonString = JSON.stringify(jsonArray);
			console.log(jsonString);
		}
	}
);
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript title=MyApp.js
// Get scores for last 24 hours
// Leave date range empty

let date: Date = new Date();

Sahha.getScores({
	types: [SahhaScoreType.wellbeing, SahhaScoreType.activity, SahhaScoreType.sleep],
	startDateTime: date.getTime(),
	endDateTime: date.getTime() })
.then(
    function (response) {
        const jsonArray = JSON.parse(response.value);
        const jsonString = JSON.stringify(jsonArray);
        console.log(jsonString);
    },
    function (error) {
        console.log(error);
    }
)
```

{% /tab %}

{% /tabs %}

---

## Get scores for the last week

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

{% tabs %}

{% tab label="iOS" %}

```swift title=MyApp.swift
// Get scores for last 7 days
// Add a date range

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

Sahha.getScores(
  types: [.wellbeing, .activity, .sleep],
  startDate: sevenDaysAgo,
  endDate: today)
  { error, json in
    if let error = error {
        print(error)
    } else if let json = json {
        print(json)
    }
}
```

{% /tab %}

{% tab label="Android" %}

```kotlin title=MainActivity.kt
// Get scores for last 7 days
// Add a date range

Sahha.getScores(
	types = setOf(SahhaScoreType.wellbeing, SahhaScoreType.activity, SahhaScoreType.sleep),
  dates = Pair(LocalDateTime.now().minusDays(7), LocalDateTime.now()),
  ) { error, success ->
    error?.also {
        println(error)
    }
    success?.also {
        println(success)
    }
}
```

{% /tab %}

{% tab label="Flutter" %}

```typescript title=MyApp.dart
// Get scores for last 7 days
// Add a date range

SahhaFlutter.getScores(types: [
        SahhaScoreType.activity,
        SahhaScoreType.sleep,
        SahhaScoreType.wellbeing
    ],
    startDateTime: DateTime.now().subtract(const Duration(days: 7)),
    endDateTime: DateTime.now())
.then((value) {
    List<dynamic> data = jsonDecode(value);
    debugPrint(data.toString());
}).catchError((error, stackTrace) => {debugPrint(error.toString())});
```

{% /tab %}

{% tab label="React Native" %}

```typescript title=MyApp.tsx
// Get scores for last 7 days
// Add date range as milliseconds since epoch time

let endDate: Date = new Date();
let sevenDaysAgo = endDate.getDate() - 7;
var startDate = new Date();
startDate.setDate(sevenDaysAgo);

Sahha.getScores(
	[SahhaScoreType.activity, SahhaScoreType.sleep, SahhaScoreType.wellbeing],
	startDate.getTime(),
	endDate.getTime(),
	(error: string, value: string) => {
		if (error) {
			console.error(`Error: ${error}`);
		} else if (value) {
			const jsonArray = JSON.parse(value);
			const jsonString = JSON.stringify(jsonArray);
			console.log(jsonString);
		}
	}
);
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript title=MyApp.js
// Get scores for last 7 days
// Add date range as milliseconds since epoch time

let endDate: Date = new Date();
let sevenDaysAgo = endDate.getDate() - 7;
var startDate = new Date();
startDate.setDate(sevenDaysAgo);

Sahha.getScores({
	types: [SahhaScoreType.wellbeing, SahhaScoreType.activity, SahhaScoreType.sleep],
	startDateTime: startDate.getTime(),
	endDateTime: endDate.getTime() })
.then(
    function (response) {
        const jsonArray = JSON.parse(response.value);
        const jsonString = JSON.stringify(jsonArray);
        console.log(jsonString);
    },
    function (error) {
        console.log(error);
    }
)
```

{% /tab %}

{% /tabs %}

---

## Score response

Scores are generated via the Sahha API.

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

- **Parameters**:

  - `id`: UUID for the score
  - `type`: The type of the score (`wellbeing`, `activity`, `sleep`, etc.)
  - `state`: The state of the score (`low`, `medium`, `high`, etc.)
  - `scoreDateTime`: The user's local date-time for the score in `"yyyy-MM-dd'T'HH:mm:ss.SSZZZZZ"` format (`"2021-10-27T16:34:06-06:00"`)
  - `createdAtUtc`: The date-time the score was created via the server in `"yyyy-MM-dd'T'HH:mm:ss.SSZZZZZ"` format (`"2021-10-27T16:44:06-06:00"`)
  - `value`: Numerical value of the score (`100`, `200`, etc.)
  - `unit`: The unit for measuring the value (`count`, `minute`, `kg`, `bpm`, etc.)
  - `version`: Version number of the scoring algorithm used
  - `dataSources`: Any array of data sources which were used to calculate the score (`age`, `gender`, `sleep`, etc.)
  - `factors`: An array of factors which contributed to the score

  You can [learn more about factors here.](/docs/products/scores#factor-schema)

### Array response

The response will be in JSON format. An example response includes these fields:

```json title=RESPONSE
[
[
  {
    "id": "8292bd3b-babd-5229-8b8a-47e9fb6ea4e7",
    "type": "wellbeing",
    "state": "medium",
    "score": 0.75,
    "factors": [
      {
        "id": "6706845e-403d-5164-bbcf-01b4edf10393",
        "name": "sleep_duration",
        "value": 407,
        "goal": 480,
        "score": 0.81,
        "state": "medium",
        "unit": "minute"
      },
      {
        "id": "eb87ae1d-8b1f-55e0-9e61-eb730d614c5c",
        "name": "sleep_regularity",
        "value": 0.472,
        "goal": 1,
        "score": 0.47,
        "state": "low",
        "unit": "index"
      },
      {
        "id": "51bc5fc3-1a01-5ed3-9cb5-526343ea7776",
        "name": "sleep_continuity",
        "value": 9,
        "goal": 10,
        "score": 0.96,
        "state": "high",
        "unit": "minute"
      },
      {
        "id": "75f1528e-a856-5906-a710-32a35c3ec22d",
        "name": "sleep_debt",
        "value": 4.288,
        "goal": 0,
        "score": 0.77,
        "state": "minimal",
        "unit": "hour"
      },
      {
        "id": "223a84d3-b26a-5d31-9b0f-3cbfba436cda",
        "name": "circadian_alignment",
        "value": 65.5,
        "goal": 30,
        "score": 0.8,
        "state": "medium",
        "unit": "minute"
      },
      {
        "id": "595b47a0-efb4-5d97-8aab-bc715cd11e01",
        "name": "mental_recovery",
        "value": 93,
        "goal": 120,
        "score": 0.86,
        "state": "medium",
        "unit": "minute"
      },
      {
        "id": "e5ccd2a7-ae90-5f74-aa5b-f05eb2850e72",
        "name": "physical_recovery",
        "value": 38,
        "goal": 90,
        "score": 0.69,
        "state": "low",
        "unit": "minute"
      }
    ],
    "dataSources": [
      "age",
      "gender",
      "sleep"
    ],
    "scoreDateTime": "2024-12-19T15:00:00+00:00",
    "createdAtUtc": "2024-12-20T06:04:33.573051+00:00",
    "version": 1
  },
  {
    "id": "6345291b-2e0a-50d6-9fb9-767d82ba7d42",
    "type": "sleep",
    "state": "medium",
    "score": 0.75,
    "factors": [
      {
        "id": "434d2ac4-62e6-591a-a712-52b275671f27",
        "name": "sleep_duration",
        "value": 407,
        "goal": 480,
        "score": 0.81,
        "state": "medium",
        "unit": "minute"
      },
      {
        "id": "ccdd2e93-cf8e-543c-bd8c-61c2851ee2bf",
        "name": "sleep_regularity",
        "value": 0.472,
        "goal": 1,
        "score": 0.47,
        "state": "low",
        "unit": "index"
      },
      {
        "id": "f516ed53-9f8a-58b6-875c-b0e152e89356",
        "name": "sleep_continuity",
        "value": 9,
        "goal": 10,
        "score": 0.96,
        "state": "high",
        "unit": "minute"
      },
      {
        "id": "a840caa5-e541-509a-bf7f-9dd06244940d",
        "name": "sleep_debt",
        "value": 4.288,
        "goal": 0,
        "score": 0.77,
        "state": "minimal",
        "unit": "hour"
      },
      {
        "id": "7d97eda2-4e07-53d1-ad3f-0d0d91cc905e",
        "name": "circadian_alignment",
        "value": 65.5,
        "goal": 30,
        "score": 0.8,
        "state": "medium",
        "unit": "minute"
      },
      {
        "id": "53d90a66-ef66-5ee8-93bd-69aaff889125",
        "name": "mental_recovery",
        "value": 93,
        "goal": 120,
        "score": 0.86,
        "state": "medium",
        "unit": "minute"
      },
      {
        "id": "5242b459-964a-5fc6-af6c-ad6dd1473b65",
        "name": "physical_recovery",
        "value": 38,
        "goal": 90,
        "score": 0.69,
        "state": "low",
        "unit": "minute"
      }
    ],
    "dataSources": [
      "age",
      "gender",
      "sleep"
    ],
    "scoreDateTime": "2024-12-19T15:00:00+00:00",
    "createdAtUtc": "2024-12-20T06:04:25.302778+00:00",
    "version": 1
  }
]
```

### Empty response

An empty JSON but successful response.

{% callout title="MINIMUM DATA REQUIREMENTS" %}

The scoring engine requires a minimum amount of device sensor data to be uploaded and processed before a score can be determined.

If you call `getScores` for a new user profile or a user that has been inactive lately, it's possible for the response to be `204 No Content`. This is not an error.

**You will need to wait and try again every few hours until a score is available.**
{% /callout %}

```json title=RESPONSE
// Scores are not ready yet
// Try again in a few hours
// Empty JSON
{}
```

---

## Data sources

Data sources are required to generate a score.

{% callout title="The score is created from various data sources" %}

To receive an score, a minimum of one data source must be configured by the SDK.

The more data sources that you configure via the SDK, the better the score that will be generated.

Some data sources are not yet available on all platforms. Sahha continues to improve its scoring engine by bringing feature parity between platforms as well as adding new data sources.
a
{% /callout %}

| Data Source | Description             | Android | iOS |
| ----------- | ----------------------- | :-----: | :-: |
| sleep       | User sleep patterns     |    ✓    |  ✓  |
| steps       | User walking patterns   |    ✓    |  ✓  |
| screen      | User device screen time |    ✓    |  X  |
| heart       | User heart patterns     |    ✓    |  ✓  |
| blood       | User blood patterns     |    ✓    |  ✓  |
| age         | User age                |    ✓    |  ✓  |
| gender      | User gender             |    ✓    |  ✓  |

---

### Device sensors

{% callout title="Use Sensors as a Data Source" %}

Learn how to configure device sensors to collect data.

[Configure Sensors](/docs/connect/sdk/collection)
{% /callout %}

---

### Demographics

{% callout title="Use Demographics as a Data Source" %}

Learn how to configure demographics as a data source.

[Configure Demographics](/docs/connect/sdk/data/demographics)
{% /callout %}
