Reports
Create report
Asleep.createReports()
var config: Asleep.Config?
var reports: Asleep.Reports?
if let config {
    reports = Asleep.createReports(config: config)
}| Property Name | Type | Description | 
|---|---|---|
| config | Asleep.Config | Enter Asleep.Config instance | 
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 Name | Type | Description | 
|---|---|---|
| sessionId | String | sessionId that can be received when stopping tracking | 
| completionBlock | Asleep.Model.Report? | If nil, an error occurs. | 
| Asleep.AsleepError? | Error Codes | 
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 Name | Type | Description | 
|---|---|---|
| fromDate | String (YYYY-MM-DD) | View date start | 
| toDate | String (YYYY-MM-DD) | View date end | 
| orderBy | Asleep.Model.OrderBy | Default value: .descendingOptions: .ascending,.descendingDESC: Descending orderASC: Ascending order | 
| offset | Int | Default value: 0Number of reports to skip | 
| limit | Int | Default value: 20Maximum number of report (0~100) | 
| completionBlock | Array of SleepSession | If nil, an error occurs | 
| AsleepError | Error Codes | 
Get average stats
Asleep.Reports.getAverageReport()
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 Name | Type | Description | 
|---|---|---|
| fromDate | String ( YYYY-MM-DD) | The starting time for the period you want to check the average | 
| toDate | String ( YYYY-MM-DD) | The ending time for the period you want to check the average | 
| completionBlock | Asleep.Model.AverageReport? | If nil, an error occurs. | 
| Asleep.AsleepError? | Error Codes | 
Delete report
Caution: Data DeletionWhen 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 Name | Type | Description | 
|---|---|---|
| sessionId | String | sessionId to be deleted | 
| completionBlock | Asleep.AsleepError? | Error Codes | 
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 Name | Type | Description | 
|---|---|---|
| timezone | String | The adjusted time zone of the analysis result e.g. UTC,Asia/Seoul(Timezone List) | 
| peculiarities | Asleep.Model.Peculiarity | A 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, CLOSEDNEVER_SLEPT: If it is determined that there was no sleep at all during the session measurement timeTOO_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 resultsNO_BREATHING_STABILITY: When the customer's contract conditions do not support breathing stability analysisNO_REALTIME_POLLING: When, according to the customer's contract, real-time access to sleep information is not available | 
| missing_data_ratio | Float ( 0~1 range, decimal points) | The error rate in sleep analysis results due to reasons such as missing audio uploads | 
| session | Asleep.Model.Session | Session Report information | 
| stat | Asleep.Model.Stat | Analysis 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 snoringStages: [Int]?
}
enum State {
    case open
    case closed
    case complete
}| Property Name | Type | Description | 
|---|---|---|
| id | String | Session Id | 
| state | Asleep.Model.State | Sleep session state ( OPEN,CLOSED, orCOMPLETE) | 
| startTime | Date | Session start time | 
| endTime | Date? | Session end time | 
| unexpectedEndTime | Date? | If a session fails to proceed and terminate properly due to app crashes or similar issues, and the client later executes initConfigto 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. | 
| createdTimezone | String | Timezone of session creation (Timezone List) | 
| sleepStages | Array<Int> | Sleep stages -1: error0: wake1: light2: deep3: rem | 
| snoringStages | Array<Int> | Snoring stages -1: error0: no snoring1: snoring | 
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 timeInSnoring: Int?
    let timeInNoSnoring: Int?
    let wakeRatio: Float?
    let sleepRatio: Float?
    let remRatio: Float?
    let lightRatio: Float?
    let deepRatio: Float?
    let snoringRatio: Float?
    let noSnoringRatio: Float?
    let sleepCycle: Int?
    let sleepCycleCount: Int?
    let sleepCycleTime: [Date]?
    let wasoCount: Int?
    let longestWaso: Int?
    let sleepIndex: Int?
    let snoringCount: Int?
}| Property Name | Type | Description | 
|---|---|---|
| sleepEfficiency | Float? | The percentage of time you actually slept during sleep measurement | 
| sleepLatency | Int? | time it took to fall asleep | 
| sleepTime | Date? | The time it takes to fall asleep after the start of sleep measurement | 
| wakeupLatency | Int? | The time it takes to wake up and end your sleep measurement | 
| wakeTime | Date? | wake up time | 
| lightLatency | Int? | The time it takes to the first Light after the start of sleep. | 
| deepLatency | Int? | The time it takes to the first Deep after the start of sleep. | 
| remLatency | Int? | The time it takes to the first REM after the start of sleep. | 
| timeInWake | Int? | wake during sleep | 
| timeInSleepPeriod | Int? | 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 | 
| timeInSleep | Int? | During sleep measurement time, the time you were actually sleeping Classified into three stages: deep, light, rem | 
| timeInBed | Int? | The time from the start of the sleep measurement to the end of the sleep measurement | 
| timeInRem | Int? | Total time the sleep phase progressed to rem | 
| timeInLight | Int? | Total time the sleep phase progressed to light | 
| timeInDeep | Int? | Total time the sleep phase progressed to deep | 
| timeInSnoring | Int? | Total time of snoring | 
| timeInNoSnoring | Int? | Total time of no snoring | 
| wakeRatio | Float? | Rate of waking time in the middle during sleep stage | 
| sleepRatio | Float? | The percentage of time you sleep without waking during the sleep phase | 
| remRatio | Float? | Rate of REM sleep during sleep stage | 
| lightRatio | Float? | Rate of light sleep during sleep stage | 
| deepRatio | Float? | Rate of deep sleep during sleep stage | 
| snoringRatio | Float? | The percentage of time during the sleep phase that there was a snoring section | 
| noSnoringRatio | Float? | The percentage of time during the sleep phase that there was no snoring. | 
| sleepCycle | Int? | The average duration of one sleep cycle. | 
| sleepCycleCount | Int? | The number of sleep cycles. | 
| 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] | 
| wasoCount | Int? | The number of times 'wake' occurred during the sleep period | 
| longestWaso | Int? | The duration of the longest 'wake' during the sleep period | 
| sleepIndex | Int? | The metric that comprehensively represents sleep quality, defined by learning from the distribution of sleep data | 
| snoringCount | Int? | The number of times snoring occurred | 
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 Name | Type | Description | 
|---|---|---|
| sessionId | String | Sleep session ID | 
| state | Asleep.Model.State | Status 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 | 
| sessionStartTime | Date | Session start time | 
| sessionEndTime | Date? | Session end time | 
| createdTimezone | String | Timezone of session creation (Timezone List) | 
| unexpectedEndTime | Date? | If a session fails to proceed and terminate properly due to app crashes or similar issues, and the client later executes initConfigto 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. | 
| lastReceivedSeqNum | Int | The sequence number of the last uploaded audio file | 
| timeInBed | Int | The time from the start of the sleep measurement to the end of the sleep measurement | 
Asleep.Model.AverageReport
struct AverageReport {
    let period: Period
    let peculiarities: [Peculiarity]
    let averageStats: AverageStats?
    let neverSleptSessions: [NeverSleptSession]
    let sleptSessions: [SleptSession]
}| Property Name | Type | Description | 
|---|---|---|
| period | Asleep.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 | ||
| averageStats | Asleep.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
struct Period {
    let timezone: String
    let startDate: Date
    let endDate: Date
}| Property Name | Type | Description | 
|---|---|---|
| timezone | String | requested timezone 예. UTC, Asia/Seoul | 
| startDate | Date | requested start date | 
| endDate | Date | requested end date | 
Asleep.Model.AverageStats
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 timeInSnoring: Int?
	  let timeInNoSnoring: Int?
  	let sleepEfficiency: Double
    let wakeRatio: Double
    let sleepRatio: Double
    let lightRatio: Double?
    let deepRatio: Double?
    let remRatio: Double?
	  let snoringRatio: Double?
		let noSnoringRatio: Double?
    let wasoCount: Int
    let longestWaso: Int
    let sleepCycleCount: Int
  	let snoringCount: Int?
}| Property Name | Type | Description | 
|---|---|---|
| startTime | String( hh:mm:ss) | Session start time | 
| endTime | String( hh:mm:ss) | Session end time | 
| sleepTime | String( hh:mm:ss) | The time it takes to fall asleep after the start of sleep staging | 
| wakeTime | String( hh:mm:ss) | Wake time | 
| sleepLatency | Int | Time to fall asleep | 
| wakeupLatency | Int | The time it takes to wake up and end your sleep measurement | 
| timeInBed | Int | The time from the start of the sleep measurement to the end of the sleep measurement | 
| timeInSleepPeriod | Int | 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 (time_in_bed - sleep_latency - wakeup_latency) | 
| timeInSleep | Int | During sleep measurement time, the time you were actually sleeping This time is divided into three stages: deep,light,and rem | 
| timeInWake | Int | Wake time during sleep | 
| timeInLight | Int? | Total time the sleep phase progressed to light | 
| timeInDeep | Int? | Total time the sleep phase progressed to deep | 
| timeInRem | Int? | Total time the sleep phase progressed to rem | 
| timeInSnoring | Int? | Total time of snoring | 
| timeInNoSnoring | Int? | Total time of no snoring | 
| sleepEfficiency | Double | The percentage of time you actually slept during sleep measurement | 
| wakeRatio | Double | Rate of waking time in the middle during sleep phase | 
| sleepRatio | Double | During sleep stage, sleep ratio, not wake | 
| lightRatio | Double? | Rate of light sleep during sleep phase | 
| deepRatio | Double? | Rate of deep sleep during sleep phase | 
| remRatio | Double? | rem sleep ratio | 
| snoringRatio | Double? | The percentage of time during the sleep phase that there was a snoring section | 
| noSnoringRatio | Double? | The percentage of time during the sleep phase that there was no snoring. | 
| wasoCount | Int | The number of times 'wake' occurred during the sleep period | 
| longestWaso | Int | The duration of the longest 'wake' during the sleep period | 
| sleepCycleCount | Int? | The number of sleep cycles. | 
| snoringCount | Int? | The number of times snoring occurred. | 
Asleep.Model.NeverSleptSession
struct NeverSleptSession {
    let id: String
    let startTime: Date
    let endTime: Date
    let completedTime: Date
}| Property name | Type | Description | 
|---|---|---|
| id | String | session id | 
| startTime | Date | Session start time | 
| endTime | Date | Session end time | 
| completedTime | Date | Time of session analysis completion | 
Asleep.Model.SleptSession
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 timeInSnoring: Int?
    let timeInNoSnoring: Int?
    let wakeRatio: Double
    let sleepRatio: Double
    let remRatio: Double?
    let lightRatio: Double?    
    let snoringRatio: Double?
    let noSnoringRatio: Double?
    let sleepCycle: Int?
    let sleepCycleCount: Int?
    let wasoCount: Int?
    let longestWaso: Int?
    let snoringCount: Int?
}| Property name | Type | Description | 
|---|---|---|
| id | String | session id | 
| createdTimezone | String | Timezone of session creation (Timezone List) | 
| startTime | Date | Session start time | 
| endTime | Date | Session end time | 
| completedTime | Date | Time of session analysis completion | 
| sleepEfficiency | Double | The percentage of time you actually slept during sleep measurement | 
| sleepLatency | Int? | Time to fall asleep | 
| wakeupLatency | Int? | The time it takes to wake up and end your sleep measurement | 
| lightLatency | Int? | The time it takes to the first Light after the start of sleep | 
| deepLatency | Int? | The time it takes to the first Deep after the start of sleep | 
| sleepTime | Date? | The time it takes to fall asleep after the start of sleep staging | 
| wakeTime | Date? | Wake time | 
| timeInWake | Int | Wake time during sleep | 
| timeInSleepPeriod | Int | 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 (time_in_bed - sleep_latency - wakeup_latency) | 
| timeInSleep | Int | During sleep measurement time, the time you were actually sleeping This time is divided into three stages: deep,light,and rem | 
| timeInBed | Int | The time from the start of the sleep measurement to the end of the sleep measurement | 
| timeInRem | Int? | Total time the sleep phase progressed to rem | 
| timeInLight | Int? | Total time the sleep phase progressed to light | 
| timeInDeep | Int? | Total time the sleep phase progressed to deep | 
| timeInSnoring | Int? | Total time of snoring | 
| timeInNoSnoring | Int? | Total time of no snoring | 
| wakeRatio | Double | Rate of waking time in the middle during sleep phase | 
| sleepRatio | Double | During sleep stage, sleep ratio, not wake | 
| remRatio | Double? | rem sleep ratio | 
| lightRatio | Double? | Rate of light sleep during sleep phase | 
| deepRatio | Double? | Rate of deep sleep during sleep phase | 
| snoringRatio | Double? | The percentage of time during the sleep phase that there was a snoring section | 
| noSnoringRatio | Double? | The percentage of time during the sleep phase that there was no snoring. | 
| sleepCycle | Int? | The average duration of one sleep cycle | 
| sleepCycleCount | Int? | The number of sleep cycles | 
| wasoCount | Int? | The number of times 'wake' occurred during the sleep period | 
| longestWaso | Int? | The duration of the longest 'wake' during the sleep period | 
| snoringCount | Int? | The number of times snoring occurred. | 
Updated 5 months ago
