These docs are for v1.0. Click to read the latest docs for v2.0.

1. Create reports

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
completionBlockArray<Asleep.Model.SleepSession>?If nil, an error occurs.
Asleep.AsleepError?Error Codes

4. 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

5. Data Type

Asleep.Model.Report

struct Report {
    let timezone: String
    let validity: Validity
    let session: Session
    let stat: Stat?
}

enum Validity {
    case inProgress
    case invalidSleepStage
    case invalidOsaStage
    case VALID
}
Property nameTypeDescription
timezoneStringThe adjusted time zone of the analysis result
e.g. UTC, Asia/Seoul
validityAsleep.Model.ValidityWhether the analysis of that sleep session is valid
If some of the uploaded audio files are invalid, or if the percentage lost is more than a certain number, the analysis is inaccurate and displays a field

IN_PROGRESS: If session is OPEN
INVALID:TOO_MANDY_DEFECTS_IN_SLEEP_STAGES: Sleep stage analysis result is not enough
INVALID:TOO_MANY_DEFECTS_IN_OSA_STAGES: Sleep apnea stage analysis result is not enough
VALID: Analysis is valid
sessionAsleep.Model.SessionSession analysis information
statAsleep.Model.StatAnalysis statistical information

Asleep.Model.Session

struct Session {
    let id: String
    let state: State
    let startTime: Date
    let endTime: Date?
    let sleepStages: [SleepStage]
    let osaStages: [OSAStage]
}

enum State {
    case open
    case closed
    case complete
}

enum SleepStage {
    case error
    case wake
    case light
    case deep
    case rem
} 

enum OSAStage {
    case stable
    case unstable
} 
Property nameTypeDescription
idStringSession Id
stateAsleep.Model.StateSleep session state (OPEN, CLOSED, or COMPLETE)
startTimeDateSession start time
endTimeDate?Session end time
sleepStagesArray<Asleep.Model.SleepStage>Sleep stages
osaStagesArray<Asleep.Model.OSAStage>Sleep apnea stages

Asleep.Model.Stat

struct Stat {
    let sleepEfficiency: Float
    let sleepLatency: Int?
    let sleepTime: Date?
    let wakeupLatency: Int?
    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 wakeRatio: Float?
    let sleepRatio: Float?
    let remRatio: Float?
    let lightRatio: Float?
    let deepRatio: Float?
    let stableBreathRatio: Float?
    let unstableBreathRatio: Float?
    let breathingPattern: BreathingPattern?
    let estimatedAhi: Float?
}

enum BreathingPattern {
    case veryStable
    case stable
    case unstable
}
Property nameTypeDescription
sleepEfficiencyFloatThe 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
timeInWakeIntwake 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
timeInSleepIntDuring sleep measurement time, the time you were actually sleeping
Classified into three stages: deep, light, rem
timeInBedIntThe time from the start of the sleep measurement to the end of the sleep measurement
timeInRemIntTotal time the sleep phase progressed to rem
timeInLightIntTotal time the sleep phase progressed to light
timeInDeepIntTotal time the sleep phase progressed to deep
timeInStableBreathIntTotal time in the breathing stable section
timeInUnstableBreathIntTotal time in the breathing unstable section
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
breathingPatternAsleep.Model.BreathingPattern?Breathing stability stage
VERY_STABLE: Very Stable
STABLE: Stable
UNSTABLE: Unstable
estimatedAhiFloat?Values for determining respiratory instability levels

Asleep.Model.SleepSession

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

enum State {
    case open
    case closed
    case complete
}
Property nameTypeDescription
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
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