Create goal type
This commit is contained in:
parent
ac96e6d4a5
commit
5daf92c5bb
@ -41,6 +41,7 @@
|
|||||||
E201EC7B2B6275CA005B83D3 /* Metadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC7A2B6275CA005B83D3 /* Metadata.swift */; };
|
E201EC7B2B6275CA005B83D3 /* Metadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC7A2B6275CA005B83D3 /* Metadata.swift */; };
|
||||||
E201EC7D2B62930E005B83D3 /* Sample+SQLite.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC7C2B62930E005B83D3 /* Sample+SQLite.swift */; };
|
E201EC7D2B62930E005B83D3 /* Sample+SQLite.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC7C2B62930E005B83D3 /* Sample+SQLite.swift */; };
|
||||||
E201EC7F2B629B4C005B83D3 /* SampleListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC7E2B629B4C005B83D3 /* SampleListView.swift */; };
|
E201EC7F2B629B4C005B83D3 /* SampleListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC7E2B629B4C005B83D3 /* SampleListView.swift */; };
|
||||||
|
E201EC812B631708005B83D3 /* Goal.swift in Sources */ = {isa = PBXBuildFile; fileRef = E201EC802B631708005B83D3 /* Goal.swift */; };
|
||||||
E27BC67A2B5D99AC003A8873 /* LocationSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = E27BC6792B5D99AC003A8873 /* LocationSample.swift */; };
|
E27BC67A2B5D99AC003A8873 /* LocationSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = E27BC6792B5D99AC003A8873 /* LocationSample.swift */; };
|
||||||
E27BC67E2B5E6CE3003A8873 /* Sequence+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E27BC67D2B5E6CE3003A8873 /* Sequence+Extensions.swift */; };
|
E27BC67E2B5E6CE3003A8873 /* Sequence+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E27BC67D2B5E6CE3003A8873 /* Sequence+Extensions.swift */; };
|
||||||
E27BC6802B5E74D7003A8873 /* LocationSampleListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E27BC67F2B5E74D7003A8873 /* LocationSampleListView.swift */; };
|
E27BC6802B5E74D7003A8873 /* LocationSampleListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E27BC67F2B5E74D7003A8873 /* LocationSampleListView.swift */; };
|
||||||
@ -90,6 +91,7 @@
|
|||||||
E201EC7A2B6275CA005B83D3 /* Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metadata.swift; sourceTree = "<group>"; };
|
E201EC7A2B6275CA005B83D3 /* Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metadata.swift; sourceTree = "<group>"; };
|
||||||
E201EC7C2B62930E005B83D3 /* Sample+SQLite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sample+SQLite.swift"; sourceTree = "<group>"; };
|
E201EC7C2B62930E005B83D3 /* Sample+SQLite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sample+SQLite.swift"; sourceTree = "<group>"; };
|
||||||
E201EC7E2B629B4C005B83D3 /* SampleListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleListView.swift; sourceTree = "<group>"; };
|
E201EC7E2B629B4C005B83D3 /* SampleListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleListView.swift; sourceTree = "<group>"; };
|
||||||
|
E201EC802B631708005B83D3 /* Goal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Goal.swift; sourceTree = "<group>"; };
|
||||||
E27BC6792B5D99AC003A8873 /* LocationSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSample.swift; sourceTree = "<group>"; };
|
E27BC6792B5D99AC003A8873 /* LocationSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSample.swift; sourceTree = "<group>"; };
|
||||||
E27BC67D2B5E6CE3003A8873 /* Sequence+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sequence+Extensions.swift"; sourceTree = "<group>"; };
|
E27BC67D2B5E6CE3003A8873 /* Sequence+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sequence+Extensions.swift"; sourceTree = "<group>"; };
|
||||||
E27BC67F2B5E74D7003A8873 /* LocationSampleListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSampleListView.swift; sourceTree = "<group>"; };
|
E27BC67F2B5E74D7003A8873 /* LocationSampleListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSampleListView.swift; sourceTree = "<group>"; };
|
||||||
@ -194,6 +196,7 @@
|
|||||||
885002812B5C37B700E7D4DB /* Model */ = {
|
885002812B5C37B700E7D4DB /* Model */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E201EC802B631708005B83D3 /* Goal.swift */,
|
||||||
E27BC6792B5D99AC003A8873 /* LocationSample.swift */,
|
E27BC6792B5D99AC003A8873 /* LocationSample.swift */,
|
||||||
E201EC7A2B6275CA005B83D3 /* Metadata.swift */,
|
E201EC7A2B6275CA005B83D3 /* Metadata.swift */,
|
||||||
E201EC762B626FC1005B83D3 /* MetadataKey.swift */,
|
E201EC762B626FC1005B83D3 /* MetadataKey.swift */,
|
||||||
|
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 {
|
private static func insert(_ element: Workout, in database: Database) throws {
|
||||||
let rowid = try database.run(table.insert(
|
let rowid = try database.run(table.insert(
|
||||||
columnTotalDistance <- element.totalDistance,
|
columnTotalDistance <- element.totalDistance,
|
||||||
columnGoalType <- element.goalType,
|
columnGoalType <- element.goal?.goalType,
|
||||||
columnGoalType <- element.goalType,
|
columnGoal <- element.goal?.gaol,
|
||||||
columnGoal <- element.goal,
|
|
||||||
columnCondenserVersion <- element.condenserVersion,
|
columnCondenserVersion <- element.condenserVersion,
|
||||||
columnCondenserDate <- element.condenserDate?.timeIntervalSinceReferenceDate)
|
columnCondenserDate <- element.condenserDate?.timeIntervalSinceReferenceDate)
|
||||||
)
|
)
|
||||||
|
@ -16,9 +16,7 @@ struct Workout {
|
|||||||
/// The distance in km (?)
|
/// The distance in km (?)
|
||||||
let totalDistance: Double?
|
let totalDistance: Double?
|
||||||
|
|
||||||
let goalType: Int?
|
let goal: Goal?
|
||||||
|
|
||||||
let goal: Double?
|
|
||||||
|
|
||||||
let condenserVersion: Int?
|
let condenserVersion: Int?
|
||||||
|
|
||||||
@ -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] = [:]) {
|
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.id = id
|
||||||
self.totalDistance = totalDistance
|
self.totalDistance = totalDistance
|
||||||
self.goalType = goalType
|
self.goal = .init(goalType: goalType, goal: goal)
|
||||||
self.goal = goal
|
|
||||||
self.condenserVersion = condenserVersion
|
self.condenserVersion = condenserVersion
|
||||||
self.condenserDate = condenserDate
|
self.condenserDate = condenserDate
|
||||||
self.events = events
|
self.events = events
|
||||||
|
@ -13,7 +13,6 @@ struct WorkoutDetailView: View {
|
|||||||
Section("Info") {
|
Section("Info") {
|
||||||
DetailRow("ID", value: workout.id)
|
DetailRow("ID", value: workout.id)
|
||||||
DetailRow("Total Distance", kilometer: workout.totalDistance)
|
DetailRow("Total Distance", kilometer: workout.totalDistance)
|
||||||
DetailRow("Goal Type", value: workout.goalType)
|
|
||||||
DetailRow("Goal", value: workout.goal)
|
DetailRow("Goal", value: workout.goal)
|
||||||
DetailRow("Condenser Version", value: workout.condenserVersion)
|
DetailRow("Condenser Version", value: workout.condenserVersion)
|
||||||
DetailRow("Condenser Date", date: workout.condenserDate)
|
DetailRow("Condenser Date", date: workout.condenserDate)
|
||||||
|
Loading…
Reference in New Issue
Block a user