1. Create report

Asleep.createReports()

var config: Asleep.Config?
var reports: Asleep.Reports?

if let config {
    reports = Asleep.createReports(config: config)
}
Property NameTypeDescription
configAsleep.ConfigEnter Asleep.Config instance

2. Get a single report

Asleep.Reports.report()

var reports: Asleep.Reports?
let sessionId: String

// Closure
reports?.report(sessionId: sessionId, completionBlock: { (report: Asleep.Report?, error: Asleep.AsleepError?) in
    if let error {
        print(error)
        return
    }
    
    if let report {
    }
})

// Async
Task {
    do {
        let report = try await reports?.report(sessionId: sessionId)
    } catch {
        print(error)
    }
}
Property NameTypeDescription
sessionIdStringsessionId that can be received when stopping tracking
completionBlockAsleep.Model.Report?If nil, an error occurs.
Asleep.AsleepError?Error Codes

3. Get multiple reports

Asleep.Reports.reports()

var reports: Asleep.Reports?
let fromDate: String = "2023-05-01"
let toDate: String = "2023-05-07"

// Closure
reports?.reports(fromDate: fromDate, toDate: toDate, completionBlock: { (reportSessions: [Asleep.Model.SleepSession]?, error: Asleep.AsleepError?) in
    if let error {
        print(error)
        return
    }
    
    if let reportSessions {
    }
})

// Async
Task {
    do {
        let reportSessions = try await reports?.reports(fromDate: fromDate, toDate: toDate)
    } catch {
        print(error)
    }
}
Property NameTypeDescription
fromDateString (YYYY-MM-DD)View date start
toDateString (YYYY-MM-DD)View date end
orderBy

- default value: .descending
Asleep.Model.OrderBy [.ascending, .descending]DESC: Descending prder
ASC: Ascending order
offset

- default value: 0
IntNumber of reports to skip
limit

- default value: 20
IntMaximum number of report
(0~100)
completionBlockArray<Asleep.Model.SleepSession>?If nil, an error occurs.
Asleep.AsleepError?Error Codes

4. Get average stats

Asleep.Reports.getAverageReport()

  • v2.3.0<=SDK
var reports: Asleep.Reports?
let fromDate: String = "2023-05-01"
let toDate: String = "2023-05-07"

// Closure
reports?.getAverageReport(fromDate: fromDate, toDate: toDate, completionBlock: { (averageReport: Asleep.Model.AverageReport?, error: Asleep.AsleepError?) in
    if let error {
        print(error)
        return
    }
    
    if let averageReport {
    }
})

// Async
Task {
    do {
        let averageReport = try await reports?.getAverageReport(fromDate: fromDate, toDate: toDate)
    } catch {
        print(error)
    }
}
Property NameTypeDescription
fromDateString (YYYY-MM-DD)The starting time for the period you want to check the average
toDateString (YYYY-MM-DD)The ending time for the period you want to check the average
completionBlockAsleep.Model.AverageReport?f nil, an error occurs.
Asleep.AsleepError?Error Codes

5. Delete report

❗️

When session data is deleted from the Asleep server upon a request, it becomes difficult to provide specific evidence for the deleted sessions during subsequent billing usage analysis.

Asleep.Reports.deleteReport()

var reports: Asleep.Reports?
let sessionId: String

// Closure
reports?.deleteReport(sessionId: sessionId, completionBlock: { (error: Asleep.AsleepError?) in
    if let error {
        print(error)
        return
    }
})

// Async
Task {
    do {
        try await deleteReport?.deleteReport(sessionId: sessionId)
    } catch {
        print(error)
    }
}
Property NameTypeDescription
sessionIdStringsessionId to be deleted
completionBlockAsleep.AsleepError?Error Codes

6. Data Type

Asleep.Model.Report

struct Report {
    let timezone: String
    let peculiarities: [Peculiarity]
    let missingDataRatio: Float
    let session: Session
    let stat: Stat?
}

enum Peculiarity {
    case inProgress
    case neverSlept
    case tooShortForAnalysis
    case tooLongForAnalysis
    case tooManyDefectsInSleepStages
    case noBreathingStability
    case noRealtimePolling
}
Property nameTypeDescription
timezoneStringThe adjusted time zone of the analysis result
e.g. UTC, Asia/Seoul (Timezone List)
peculiaritiesAsleep.Model.PeculiarityA field for describing any specific details or peculiarities of the sleep session. This field can include multiple labels below.

IN_PROGRESS: If the session is OPEN, CLOSED
NEVER_SLEPT: If it is determined that there was no sleep at all during the session measurement time
TOO_SHORT_FOR_ANALYSIS: When the measurement time is too short to conduct a valid analysis (currently less than 20 minutes)
TOO_LONG_FOR_ANALYSIS: Analysis has been conducted successfully, but the session measurement time is excessively long, making it difficult to trust (currently exceeding 24 hours)
TOO_MANY_DEFECTS_IN_SLEEP_STAGES: When the error rate is high due to factors like missing audio uploads, resulting in insufficient sleep analysis results.
NO_BREATHING_STABILITY: When the customer's contract conditions do not support breathing stability analysis.
NO_REALTIME_POLLING: When, according to the customer's contract, real-time access to sleep information is not available.
missing_data_ratioFloatt(0~1 range, decimal points)The error rate in sleep analysis results due to reasons such as missing audio uploads
sessionAsleep.Model.SessionSession Report information
statAsleep.Model.StatAnalysis Report information

Asleep.Model.Session

struct Session {
    let id: String
    let state: State
    let startTime: Date
    let endTime: Date?
    let unexpectedEndTime: Date?
    let createdTimezone: String
    let sleepStages: [Int]?
    let breathStages: [Int]?
}

enum State {
    case open
    case closed
    case complete
}
Property nameTypeDescriptionVersion
idStringSession Id
stateAsleep.Model.StateSleep session state (OPEN, CLOSED, or COMPLETE)
startTimeDateSession start time
endTimeDate?Session end time
unexpectedEndTimeDate?If a session fails to proceed and terminate properly due to app crashes or similar issues, and the client later executes initConfig to terminate the session, the time at which this happens is recorded. In this case, the "end_time" is calculated based on the sequence number of the last uploaded audio file. Therefore, if "end_time" is not null, it indicates an abnormal session.2.2.0<=SDK
createdTimezoneStringTimezone of session creation (Timezone List)2.2.0<=SDK
sleepStagesArray<Int>Sleep stages
-1: error
0 : wake
1 : light
2 : deep
3 : rem
breathStagesArray<Int>Breathing Stability stages
-1: error
0 : stable
1 : unstable

Asleep.Model.Stat

struct Stat {
    let sleepEfficiency: Float?
    let sleepLatency: Int?
    let sleepTime: Date?
    let wakeupLatency: Int?
    let wakeTime: Date?
    let lightLatency: Int?
    let deepLatency: Int?
    let remLatency: Int?
    let timeInWake: Int?
    let timeInSleepPeriod: Int?
    let timeInSleep: Int?
    let timeInBed: Int?
    let timeInRem: Int?
    let timeInLight: Int?
    let timeInDeep: Int?
    let timeInStableBreath: Int?
    let timeInUnstableBreath: Int?
		let timeInSnoring: Int?
  	let timeInNoSnoring: Int?
  	let wakeRatio: Float?
    let sleepRatio: Float?
    let remRatio: Float?
    let lightRatio: Float?
    let deepRatio: Float?
    let stableBreathRatio: Float?
    let unstableBreathRatio: Float?
	  let snoringRatio: Float?
  	let noSnoringRatio: Float?
    let unstableBreathCount: Int?
    let breathingPattern: BreathingPattern?
    let breathingIndex: Float?
    let sleepCycle: Int?
    let sleepCycleCount: Int?
    let sleepCycleTime: [Date]?
    let wasoCount: Int?
    let longestWaso: Int?
    let sleepIndex: Int?
  	let snoringCount: Int?
}

enum BreathingPattern {
    case stableBreath
    case mildlyUnstableBreath
    case moderatelyUnstableBreath
    case severelyUnstableBreath
}
Property nameTypeDescriptionVersion
sleepEfficiencyFloat?The percentage of time you actually slept during sleep measurement
sleepLatencyInt?time it took to fall asleep
sleepTimeDate?The time it takes to fall asleep after the start of sleep measurement
wakeupLatencyInt?The time it takes to wake up and end your sleep measurement
wakeTimeDate?wake up time
lightLatencyInt?The time it takes to the first Light after the start of sleep.2.2.0<=SDK
deepLatencyInt?The time it takes to the first Deep after the start of sleep.2.2.0<=SDK
remLatencyInt?The time it takes to the first REM after the start of sleep.2.2.0<=SDK
timeInWakeInt?wake during sleep
timeInSleepPeriodInt?During sleep measurement time, excluding the time it took from the start of the sleep measurement to fall asleep and the time it took from the wake to the end of the sleep measurement
timeInSleepInt?During sleep measurement time, the time you were actually sleeping
Classified into three stages: deep, light, rem
timeInBedInt?The time from the start of the sleep measurement to the end of the sleep measurement
timeInRemInt?Total time the sleep phase progressed to rem
timeInLightInt?Total time the sleep phase progressed to light
timeInDeepInt?Total time the sleep phase progressed to deep
timeInStableBreathInt?Total time in the breathing stable section
timeInUnstableBreathInt?Total time in the breathing unstable section
timeInSnoringInt?Total time of snoring2.4.0<=SDK
timeInNoSnoringInt?Total time of no snoring2.4.0<=SDK
wakeRatioFloat?Rate of waking time in the middle during sleep stage
sleepRatioFloat?The percentage of time you sleep without waking during the sleep phase
remRatioFloat?Rate of REM sleep during sleep stage
lightRatioFloat?Rate of light sleep during sleep stage
deepRatioFloat?Rate of deep sleep during sleep stage
stableBreathRatioFloat?The percentage of time that was a breathing stable section during the sleep stage
unstableBreathRatioFloat?The percentage of time that was a breathing unstable section during the sleep stage
snoringRatioFloat?The percentage of time during the sleep phase that there was a snoring section2.4.0<=SDK
noSnoringRatioFloat?The percentage of time during the sleep phase that there was no snoring.2.4.0<=SDK
unstableBreathCountInt?The number of times unstable breathing occurred.2.2.0<=SDK
breathingPatternAsleep.Model.BreathingPattern?Breathing stability stage
STABLE_BREATH: Stable breathing
MILDLY_UNSTABLE_BREATH: Slightly unstable breathing
MODERATELY_UNSTABLE_BREATH: Moderately unstable breathing
SEVERELY_UNSTABLE_BREATH: Severely irregular, unstable breathing.
breathingIndexFloat?Values for determining respiratory instability levels
sleepCycleInt?The average duration of one sleep cycle.2.2.0<=SDK
sleepCycleCountInt?The number of sleep cycles.2.2.0<=SDK
sleepCycleTime[Date]?Transition time for sleep cycles
[First sleep cycle onset time, first sleep cycle end time, second sleep cycle end time, ..., last sleep cycle end time]
2.2.0<=SDK
wasoCountInt?The number of times 'wake' occurred during the sleep period2.2.0<=SDK
longestWasoInt?The duration of the longest 'wake' during the sleep period2.2.0<=SDK
sleepIndexInt?The metric that comprehensively represents sleep quality, defined by learning from the distribution of sleep data2.3.0<=SDK
snoringCountInt?The number of times snoring occurred2.4.0<=SDK

Asleep.Model.SleepSession

struct SleepSession {
    let sessionId: String
    let state: State
    let sessionStartTime: Date
    let sessionEndTime: Date?
    let createdTimezone: String
    let unexpectedEndTime: Date?
    let lastReceivedSeqNum: Int
    let timeInBed: Int
}

enum State {
    case open
    case closed
    case complete
}
Property nameTypeDescriptionVersion
sessionIdStringSleep session ID
stateAsleep.Model.StateStatus of Session
'OPEN': An in-progress session, with audio uploads available
'CLOSED': The session terminated by sending an end session request. Unable to upload audio files. Analysis of uploaded sleep audio is still in progress
'COMPLETE': All sleep analysis completed after the end of the session
sessionStartTimeDateSession start time
sessionEndTimeDate?Session end time
createdTimezoneStringTimezone of session creation (Timezone List)2.2.0<=SDK
unexpectedEndTimeDate?If a session fails to proceed and terminate properly due to app crashes or similar issues, and the client later executes initConfig to terminate the session, the time at which this happens is recorded. In this case, the "end_time" is calculated based on the sequence number of the last uploaded audio file. Therefore, if "end_time" is not null, it indicates an abnormal session.2.2.0<=SDK
lastReceivedSeqNumIntThe sequence number of the last uploaded audio file
timeInBedIntThe time from the start of the sleep measurement to the end of the sleep measurement

Asleep.Model.AverageReport

  • v2.3.0<=SDK
struct AverageReport {
    let period: Period
    let peculiarities: [Peculiarity]
    let averageStats: AverageStats?
    let neverSleptSessions: [NeverSleptSession]
    let sleptSessions: [SleptSession]
}
Property nameTypeDescription
periodAsleep.Model.Period Timezone (Timezone List)
peculiarities[Asleep.Model.Peculiarity]Special considerations when calculating the average of sleep sessions

NO_BREATHING_STABILITY: When the customer's contract conditions do not support breathing stability analysis
averageStatsAsleep.Model.AverageStats?An object containing the averages of sleep metrics for "sleptSessions"
neverSleptSessions[Asleep.Model.NeverSleptSession]A list of sessions during which it is determined that no sleep occurred at all during the measurement time.
sleptSessions[Asleep.Model.SleptSession]A list of sessions during which it is determined that sleep occurred during the measurement time.

Asleep.Model.Period

  • v2.3.0<=SDK
struct Period {
    let timezone: String
    let startDate: Date
    let endDate: Date
}
Property nameTypeDescription
timezoneStringrequested timezone
예. UTC, Asia/Seoul
startDateDaterequested start date
endDateDaterequested end date

Asleep.Model.AverageStats

  • v2.3.0<=SDK
struct AverageStats {
    let startTime: String
    let endTime: String
    let sleepTime: String
    let wakeTime: String
    let sleepLatency: Int
    let wakeupLatency: Int
    let timeInBed: Int
    let timeInSleepPeriod: Int
    let timeInSleep: Int
    let timeInWake: Int
    let timeInLight: Int?
    let timeInDeep: Int?
    let timeInRem: Int?
    let timeInStableBreath: Int?
    let timeInUnstableBreath: Int?
		let timeInSnoring: Int?
	  let timeInNoSnoring: Int?
  	let sleepEfficiency: Double
    let wakeRatio: Double
    let sleepRatio: Double
    let lightRatio: Double?
    let deepRatio: Double?
    let remRatio: Double?
    let stableBreathRatio: Double?
    let unstableBreathRatio: Double?
	  let snoringRatio: Double?
		let noSnoringRatio: Double?
    let breathingIndex: Double?
    let wasoCount: Int
    let longestWaso: Int
    let unstableBreathCount: Int
    let sleepCycleCount: Int
  	let snoringCount: Int?
}
Property nameTypeDescription
startTimeString(hh:mm:ss)Session start time
endTimeString(hh:mm:ss)Session end time
sleepTimeString(hh:mm:ss)The time it takes to fall asleep after the start of sleep staging
wakeTimeString(hh:mm:ss)Wake time
sleepLatencyIntTime to fall asleep
wakeupLatencyIntThe time it takes to wake up and end your sleep measurement
timeInBedIntThe time from the start of the sleep measurement to the end of the sleep measurement
timeInSleepPeriodIntDuring sleep measurement time, excluding the time it took from the start of the sleep measurement to fall asleep and the time it took from the wake to the end of the sleep measurement
(time_in_bed - sleep_latency - wakeup_latency)
timeInSleepIntDuring sleep measurement time, the time you were actually sleeping
This time is divided into three stages: deep,light,and rem
timeInWakeIntWake time during sleep
timeInLightInt?Total time the sleep phase progressed to light
timeInDeepInt?Total time the sleep phase progressed to deep
timeInRemInt?Total time the sleep phase progressed to rem
timeInStableBreathInt?Total time in the breathing stable section
timeInUnstableBreathInt?Total time of breath instability
timeInSnoringInt?Total time of snoring
timeInNoSnoringInt?Total time of no snoring
sleepEfficiencyDoubleThe percentage of time you actually slept during sleep measurement
wakeRatioDoubleRate of waking time in the middle during sleep phase
sleepRatioDoubleDuring sleep stage, sleep ratio, not wake
lightRatioDouble?Rate of light sleep during sleep phase
deepRatioDouble?Rate of deep sleep during sleep phase
remRatioDouble?rem sleep ratio
stableBreathRatioDouble?The percentage of time that was a breathing stable section during the sleep phase
unstableBreathRatioDouble?The percentage of time during the sleep phase that there was a breathing instability section
snoringRatioDouble?The percentage of time during the sleep phase that there was a snoring section
noSnoringRatioDouble?The percentage of time during the sleep phase that there was no snoring.
breathingIndexDouble?Values for determining respiratory instability levels
wasoCountIntThe number of times 'wake' occurred during the sleep period
longestWasoIntThe duration of the longest 'wake' during the sleep period
unstableBreathCountInt?The number of times unstable breathing occurred.
sleepCycleCountInt?The number of sleep cycles.
snoringCountInt?The number of times snoring occurred.

Asleep.Model.NeverSleptSession

  • v2.3.0<=SDK
struct NeverSleptSession {
    let id: String
    let startTime: Date
    let endTime: Date
    let completedTime: Date
}
Property nameTypeDescription
idStringsession id
startTimeDateSession start time
endTimeDateSession end time
completedTimeDateTime of session analysis completion

Asleep.Model.SleptSession

  • v2.3.0<=SDK
struct SleptSession {
    let id: String
    let createdTimezone: String
    let startTime: Date
    let endTime: Date
    let completedTime: Date
    let sleepEfficiency: Double
    let sleepLatency: Int?
    let wakeupLatency: Int?
    let lightLatency: Int?
    let deepLatency: Int?
    let remLatency: Int?
    let sleepTime: Date?
    let wakeTime: Date?
    let timeInWake: Int
    let timeInSleepPeriod: Int
    let timeInSleep: Int
    let timeInBed: Int
    let timeInRem: Int?
    let timeInLight: Int?
    let timeInDeep: Int?
    let timeInStableBreath: Int?
    let timeInUnstableBreath: Int?
 	  let timeInSnoring: Int?
  	let timeInNoSnoring: Int?
    let wakeRatio: Double
    let sleepRatio: Double
    let remRatio: Double?
    let lightRatio: Double?
    let deepRatio: Double?
    let stableBreathRatio: Double?
    let unstableBreathRatio: Double?
  	let snoringRatio: Double?
  	let noSnoringRatio: Double?
    let unstableBreathCount: Int?
    let breathingPattern: BreathingPattern?
    let sleepCycle: Int?
    let sleepCycleCount: Int?
    let wasoCount: Int?
    let longestWaso: Int?
	  let snoringCount: Int?
}
Property nameTypeDescription
idStringsession id
createdTimezoneStringTimezone of session creation
(Timezone List)
startTimeDateSession start time
endTimeDateSession end time
completedTimeDateTime of session analysis completion
sleepEfficiencyDoubleThe percentage of time you actually slept during sleep measurement
sleepLatencyInt?Time to fall asleep
wakeupLatencyInt?The time it takes to wake up and end your sleep measurement
lightLatencyInt?The time it takes to the first Light after the start of sleep
deepLatencyInt?The time it takes to the first Deep after the start of sleep
remLatencyInt?The time it takes to the first REM after the start of sleep
sleepTimeDate?The time it takes to fall asleep after the start of sleep staging
wakeTimeDate?Wake time
timeInWakeIntWake time during sleep
timeInSleepPeriodIntDuring sleep measurement time, excluding the time it took from the start of the sleep measurement to fall asleep and the time it took from the wake to the end of the sleep measurement
(time_in_bed - sleep_latency - wakeup_latency)
timeInSleepIntDuring sleep measurement time, the time you were actually sleeping
This time is divided into three stages: deep,light,and rem
timeInBedIntThe time from the start of the sleep measurement to the end of the sleep measurement
timeInRemInt?Total time the sleep phase progressed to rem
timeInLightInt?Total time the sleep phase progressed to light
timeInDeepInt?Total time the sleep phase progressed to deep
timeInStableBreathInt?Total time in the breathing stable section
timeInUnstableBreathInt?Total time of breath instability
timeInSnoringInt?Total time of snoring
timeInNoSnoringInt?Total time of no snoring
wakeRatioDoubleRate of waking time in the middle during sleep phase
sleepRatioDoubleDuring sleep stage, sleep ratio, not wake
remRatioDouble?rem sleep ratio
lightRatioDouble?Rate of light sleep during sleep phase
deepRatioDouble?Rate of deep sleep during sleep phase
stableBreathRatioDouble?The percentage of time that was a breathing stable section during the sleep phase
unstableBreathRatioDouble?The percentage of time during the sleep phase that there was a breathing instability section
unstableBreathCountInt?The number of times unstable breathing occurred.
snoringRatioDouble?The percentage of time during the sleep phase that there was a snoring section
noSnoringRatioDouble?The percentage of time during the sleep phase that there was no snoring.
breathingPatternBreathingPattern?Breathing Instability Level

STABLE_BREATH: stable
MILDLY_UNSTABLE_BREATH: mildly unstable
MODERTATELY_UNSTABLE_BREATH:
moderately unstable
SEVERELY_UNSTABLE_BREATH: severely unstable
sleepCycleInt?The average duration of one sleep cycle
sleepCycleCountInt?The number of sleep cycles
wasoCountInt?The number of times 'wake' occurred during the sleep period
longestWasoInt?The duration of the longest 'wake' during the sleep period
snoringCountInt?The number of times snoring occurred.