|
@@ -124,42 +124,6 @@ extension NSPredicate {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-extension GlucoseStored: Encodable {
|
|
|
|
|
- enum CodingKeys: String, CodingKey {
|
|
|
|
|
- case date
|
|
|
|
|
- case dateString
|
|
|
|
|
- case sgv
|
|
|
|
|
- case glucose
|
|
|
|
|
- case direction
|
|
|
|
|
- case id
|
|
|
|
|
- case type
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public func encode(to encoder: Encoder) throws {
|
|
|
|
|
- var container = encoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
-
|
|
|
|
|
- let dateFormatter = ISO8601DateFormatter()
|
|
|
|
|
- dateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
|
|
|
|
-
|
|
|
|
|
- try container.encode(dateFormatter.string(from: date ?? Date()), forKey: .dateString)
|
|
|
|
|
-
|
|
|
|
|
- let dateAsUnixTimestamp = String(format: "%.0f", (date?.timeIntervalSince1970 ?? Date().timeIntervalSince1970) * 1000)
|
|
|
|
|
- try container.encode(dateAsUnixTimestamp, forKey: .date)
|
|
|
|
|
-
|
|
|
|
|
- try container.encode(direction, forKey: .direction)
|
|
|
|
|
- try container.encode(id, forKey: .id)
|
|
|
|
|
-
|
|
|
|
|
- // TODO: Handle the type of the glucose entry conditionally not hardcoded
|
|
|
|
|
- try container.encode("sgv", forKey: .type)
|
|
|
|
|
-
|
|
|
|
|
- if isManual {
|
|
|
|
|
- try container.encode(glucose, forKey: .glucose)
|
|
|
|
|
- } else {
|
|
|
|
|
- try container.encode(glucose, forKey: .sgv)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
// In order to show the correct direction in the bobble we convert the direction property of the NSManagedObject GlucoseStored back to the Direction type
|
|
// In order to show the correct direction in the bobble we convert the direction property of the NSManagedObject GlucoseStored back to the Direction type
|
|
|
extension GlucoseStored {
|
|
extension GlucoseStored {
|
|
|
var directionEnum: BloodGlucose.Direction? {
|
|
var directionEnum: BloodGlucose.Direction? {
|