forked from C3-PRO/c3-pro-ios-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoreMotionActivitySum.swift
100 lines (84 loc) · 2.18 KB
/
CoreMotionActivitySum.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// CoreMotionActivitySum.swift
// C3PRO
//
// Created by Pascal Pfiffner on 24/05/16.
// Copyright © 2016 University Hospital Zurich. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import SMART
/**
Contains information about activity duration of a given type.
*/
public struct CoreMotionActivitySum: CustomStringConvertible, CustomDebugStringConvertible {
public let type: CoreMotionActivityInterpretation
public let duration: Duration
public init(type: CoreMotionActivityInterpretation, duration: Duration) {
self.type = type
self.duration = duration
}
// MARK: - Helper
public var preferredPosition: Int {
switch type {
case .sleeping:
return 0
case .stationary:
return 4
case .automotive:
return 10
case .walking:
return 100
case .running:
return 120
case .cycling:
return 200
case .unknown:
return 999
}
}
public func preferredColorComponentsHSB() -> (hue: Float, saturation: Float, brightness: Float) {
var hue: Float = 0.0
var sat: Float = 0.7
var bright: Float = 0.94
switch type {
case .sleeping:
hue = 0.0
sat = 0.0
bright = 0.85
case .stationary:
hue = 0.54
case .automotive:
hue = 0.61
case .walking:
hue = 0.4
case .running:
hue = 0.04
case .cycling:
hue = 0.1
case .unknown:
hue = 0.0
sat = 0.0
bright = 0.7
}
return (hue: hue, saturation: sat, brightness: bright)
}
// MARK: - String Convertible
public var description: String {
return "<\(type(of: self))> “\(type.rawValue)” of \(duration.value?.description ?? "0") \(duration.unit ?? "")"
}
public var debugDescription: String {
return description
}
}