Create goal type
This commit is contained in:
46
HealthImport/Model/Goal.swift
Normal file
46
HealthImport/Model/Goal.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
|
||||
enum Goal {
|
||||
|
||||
case time(TimeInterval)
|
||||
|
||||
init?(goalType: Int?, goal: Double?) {
|
||||
switch goalType {
|
||||
case .none:
|
||||
return nil
|
||||
case 0:
|
||||
return nil
|
||||
case 2:
|
||||
guard let goal else {
|
||||
print("Time goal, but no goal value set")
|
||||
return nil
|
||||
}
|
||||
self = .time(goal)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var gaol: Double {
|
||||
switch self {
|
||||
case .time(let timeInterval):
|
||||
return timeInterval
|
||||
}
|
||||
}
|
||||
|
||||
var goalType: Int {
|
||||
switch self {
|
||||
case .time: return 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Goal: CustomStringConvertible {
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .time(let seconds):
|
||||
return seconds.durationString
|
||||
}
|
||||
}
|
||||
}
|
@@ -64,9 +64,8 @@ extension Workout {
|
||||
private static func insert(_ element: Workout, in database: Database) throws {
|
||||
let rowid = try database.run(table.insert(
|
||||
columnTotalDistance <- element.totalDistance,
|
||||
columnGoalType <- element.goalType,
|
||||
columnGoalType <- element.goalType,
|
||||
columnGoal <- element.goal,
|
||||
columnGoalType <- element.goal?.goalType,
|
||||
columnGoal <- element.goal?.gaol,
|
||||
columnCondenserVersion <- element.condenserVersion,
|
||||
columnCondenserDate <- element.condenserDate?.timeIntervalSinceReferenceDate)
|
||||
)
|
||||
|
@@ -16,10 +16,8 @@ struct Workout {
|
||||
/// The distance in km (?)
|
||||
let totalDistance: Double?
|
||||
|
||||
let goalType: Int?
|
||||
|
||||
let goal: Double?
|
||||
|
||||
let goal: Goal?
|
||||
|
||||
let condenserVersion: Int?
|
||||
|
||||
let condenserDate: Date?
|
||||
@@ -56,8 +54,7 @@ struct Workout {
|
||||
init(id: Int, totalDistance: Double? = nil, goalType: Int? = nil, goal: Double? = nil, condenserVersion: Int? = nil, condenserDate: Date? = nil, events: [WorkoutEvent] = [], activities: [WorkoutActivity] = [], metadata: [Metadata.Key : Metadata.Value] = [:]) {
|
||||
self.id = id
|
||||
self.totalDistance = totalDistance
|
||||
self.goalType = goalType
|
||||
self.goal = goal
|
||||
self.goal = .init(goalType: goalType, goal: goal)
|
||||
self.condenserVersion = condenserVersion
|
||||
self.condenserDate = condenserDate
|
||||
self.events = events
|
||||
|
@@ -13,7 +13,6 @@ struct WorkoutDetailView: View {
|
||||
Section("Info") {
|
||||
DetailRow("ID", value: workout.id)
|
||||
DetailRow("Total Distance", kilometer: workout.totalDistance)
|
||||
DetailRow("Goal Type", value: workout.goalType)
|
||||
DetailRow("Goal", value: workout.goal)
|
||||
DetailRow("Condenser Version", value: workout.condenserVersion)
|
||||
DetailRow("Condenser Date", date: workout.condenserDate)
|
||||
|
Reference in New Issue
Block a user