Skip to content

Predict ideal bedtime using Core ML - Project 4 of Hacking with Swift

Notifications You must be signed in to change notification settings

monophosphate/BetterRest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

BetterRest

In order to output your ideal bedtime, please input your desired wake up time, sleep time, and coffee consumption to calculate it using the Core ML implementation.

Demo

Notes

Under the hood:

This function allows the app to calculate a bedtime using the SleepCalculator class (CoreML implementation), it is then formatted to HH:MM and returned as a String

    func calculateBedtime() -> String {
        let components = Calendar.current.dateComponents([.hour, .minute], from: wakeUp)
        let hour = (components.hour ?? 0) * 60 * 60
        let minute = (components.minute ?? 0) * 60
        
        do {
            let model: SleepCalculator = try SleepCalculator(configuration: .init())
            let prediction = try model.prediction(wake: Double(hour + minute), 
            estimatedSleep: sleepAmount, coffee: Double(coffeeAmount))
           
            let formatter = DateFormatter()
            formatter.timeStyle = .short
            
            return formatter.string(from: sleepTime)
        } catch {
            return "Please try again..."
        }
    }

Credit

Check out this project at Hacking with Swift

About

Predict ideal bedtime using Core ML - Project 4 of Hacking with Swift

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages