Skip to content

Commit

Permalink
Merge pull request #201 from ps2/ns-loop-plugin
Browse files Browse the repository at this point in the history
Ns loop plugin
  • Loading branch information
ps2 authored Aug 20, 2016
2 parents 834819c + b5f96fe commit 7a41c31
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 107 deletions.
3 changes: 1 addition & 2 deletions NightscoutUploadKit/DeviceStatus/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public struct DeviceStatus {
}

if let loop = loopStatus {
// Would like to change this to avoid confusion about whether or not this was uploaded from Loop or openaps
rval["openaps"] = loop.dictionaryRepresentation
rval["loop"] = loop.dictionaryRepresentation
}

return rval
Expand Down
12 changes: 3 additions & 9 deletions NightscoutUploadKit/DeviceStatus/LoopEnacted.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ public struct LoopEnacted {
let duration: NSTimeInterval
let timestamp: NSDate
let received: Bool
let predBGs: PredictedBG?

public init(rate: Double, duration: NSTimeInterval, timestamp: NSDate, received: Bool, predBGs: PredictedBG? = nil) {

public init(rate: Double, duration: NSTimeInterval, timestamp: NSDate, received: Bool) {
self.rate = rate
self.duration = duration
self.timestamp = timestamp
self.received = received
self.predBGs = predBGs
}

public var dictionaryRepresentation: [String: AnyObject] {
Expand All @@ -30,11 +28,7 @@ public struct LoopEnacted {
rval["rate"] = rate
rval["duration"] = duration / 60.0
rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)
rval["recieved"] = received // [sic]

if let predBGs = predBGs {
rval["predBGs"] = predBGs.dictionaryRepresentation
}
rval["received"] = received
return rval
}
}
47 changes: 32 additions & 15 deletions NightscoutUploadKit/DeviceStatus/LoopStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ public struct LoopStatus {

let iob: IOBStatus?
let cob: COBStatus?
let suggested: LoopSuggested?
let predicted: PredictedBG?
let recommendedTempBasal: RecommendedTempBasal?
let recommendedBolus: Double?
let enacted: LoopEnacted?

let rileylinks: [RileyLinkStatus]?
let failureReason: ErrorType?
public init(name: String, version: String, timestamp: NSDate, glucose: Int? = nil, iob: IOBStatus? = nil, cob: COBStatus? = nil, suggested: LoopSuggested? = nil, enacted: LoopEnacted?, failureReason: ErrorType? = nil) {

public init(name: String, version: String, timestamp: NSDate, iob: IOBStatus? = nil, cob: COBStatus? = nil, predicted: PredictedBG? = nil, recommendedTempBasal:RecommendedTempBasal? = nil, recommendedBolus: Double? = nil, enacted: LoopEnacted? = nil, rileylinks: [RileyLinkStatus]? = nil, failureReason: ErrorType? = nil) {
self.name = name
self.version = version
self.timestamp = timestamp
self.suggested = suggested
self.enacted = enacted
self.iob = iob
self.cob = cob
self.predicted = predicted
self.recommendedTempBasal = recommendedTempBasal
self.recommendedBolus = recommendedBolus
self.enacted = enacted
self.rileylinks = rileylinks
self.failureReason = failureReason
}

Expand All @@ -37,27 +42,39 @@ public struct LoopStatus {
rval["name"] = name
rval["version"] = version
rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)

if let suggested = suggested {
rval["suggested"] = suggested.dictionaryRepresentation
}

if let enacted = enacted {
rval["enacted"] = enacted.dictionaryRepresentation
}


if let iob = iob {
rval["iob"] = iob.dictionaryRepresentation
}

if let cob = cob {
rval["cob"] = cob.dictionaryRepresentation
}

if let predicted = predicted {
rval["predicted"] = predicted.dictionaryRepresentation
}

if let recommendedTempBasal = recommendedTempBasal {
rval["recommendedTempBasal"] = recommendedTempBasal.dictionaryRepresentation
}

if let recommendedBolus = recommendedBolus {
rval["recommendedBolus"] = recommendedBolus
}

if let enacted = enacted {
rval["enacted"] = enacted.dictionaryRepresentation
}

if let failureReason = failureReason {
rval["failureReason"] = String(failureReason)
}

if let rileylinks = rileylinks {
rval["rileylinks"] = rileylinks.map { $0.dictionaryRepresentation }
}

return rval
}
}
Expand Down
76 changes: 0 additions & 76 deletions NightscoutUploadKit/DeviceStatus/LoopSuggested.swift

This file was deleted.

6 changes: 5 additions & 1 deletion NightscoutUploadKit/DeviceStatus/PredictedBG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import Foundation
import HealthKit

public struct PredictedBG {
let startDate: NSDate
let values: [Int]
let cob: [Int]?
let iob: [Int]?

public init(values: [HKQuantity], cob: [HKQuantity]? = nil, iob: [HKQuantity]? = nil) {
public init(startDate: NSDate, values: [HKQuantity], cob: [HKQuantity]? = nil, iob: [HKQuantity]? =
nil) {
self.startDate = startDate
// BG values in nightscout are in mg/dL.
let unit = HKUnit.milligramsPerDeciliterUnit()
self.values = values.map { Int(round($0.doubleValueForUnit(unit))) }
Expand All @@ -26,6 +29,7 @@ public struct PredictedBG {

var rval = [String: AnyObject]()

rval["startDate"] = TimeFormat.timestampStrFromDate(startDate)
rval["values"] = values

if let cob = cob {
Expand Down
31 changes: 31 additions & 0 deletions NightscoutUploadKit/DeviceStatus/RecommendedTempBasal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// LoopSuggested.swift
// RileyLink
//
// Created by Pete Schwamb on 7/28/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct RecommendedTempBasal {
let timestamp: NSDate
let rate: Double
let duration: NSTimeInterval

public init(timestamp: NSDate, rate: Double, duration: NSTimeInterval) {
self.timestamp = timestamp
self.rate = rate
self.duration = duration
}

public var dictionaryRepresentation: [String: AnyObject] {

var rval = [String: AnyObject]()

rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)
rval["rate"] = rate
rval["duration"] = duration / 60.0
return rval
}
}
45 changes: 45 additions & 0 deletions NightscoutUploadKit/DeviceStatus/RileyLinkStatus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// RileyLinkStatus.swift
// RileyLink
//
// Created by Pete Schwamb on 8/12/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct RileyLinkStatus {

public enum State: String {
case Connected = "connected"
case Connecting = "connecting"
case Disconnected = "disconnected"
}

let name: String
let state: State
let lastIdle: NSDate?
let version: String?
let rssi: Double?

public var dictionaryRepresentation: [String: AnyObject] {
var rval = [String: AnyObject]()

rval["name"] = name
rval["state"] = state.rawValue

if let lastIdle = lastIdle {
rval["lastIdle"] = TimeFormat.timestampStrFromDate(lastIdle)
}

if let version = version {
rval["version"] = version
}

if let rssi = rssi {
rval["rssi"] = rssi
}

return rval
}
}
12 changes: 8 additions & 4 deletions RileyLink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
C18C8C531D64123400E043FB /* EnableBolusWizardPumpEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C18C8C521D64123400E043FB /* EnableBolusWizardPumpEvent.swift */; };
C1A492631D4A5A19008964FF /* IOBStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A492621D4A5A19008964FF /* IOBStatus.swift */; };
C1A492651D4A5DEB008964FF /* BatteryStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A492641D4A5DEB008964FF /* BatteryStatus.swift */; };
C1A492671D4A65D9008964FF /* LoopSuggested.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A492661D4A65D9008964FF /* LoopSuggested.swift */; };
C1A492671D4A65D9008964FF /* RecommendedTempBasal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A492661D4A65D9008964FF /* RecommendedTempBasal.swift */; };
C1A492691D4A66C0008964FF /* LoopEnacted.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A492681D4A66C0008964FF /* LoopEnacted.swift */; };
C1AACC6B1CECD5F500C07049 /* RileyLinkListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1AACC6A1CECD5F500C07049 /* RileyLinkListTableViewController.swift */; };
C1AF21E21D4838C90088C41D /* DeviceStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1AF21E11D4838C90088C41D /* DeviceStatus.swift */; };
Expand Down Expand Up @@ -241,6 +241,7 @@
C1C3578F1C927303009BDD4F /* MeterMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1C3578E1C927303009BDD4F /* MeterMessage.swift */; };
C1C357911C92733A009BDD4F /* MeterMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1C357901C92733A009BDD4F /* MeterMessageTests.swift */; };
C1E535EA1991E36700C2AC49 /* NSData+Conversion.m in Sources */ = {isa = PBXBuildFile; fileRef = C1E535E91991E36700C2AC49 /* NSData+Conversion.m */; };
C1E5BEAD1D5E26F200BD4390 /* RileyLinkStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E5BEAC1D5E26F200BD4390 /* RileyLinkStatus.swift */; };
C1EAD6B31C826B6D006DBA60 /* AlertType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1EAD6AE1C826B6D006DBA60 /* AlertType.swift */; };
C1EAD6B41C826B6D006DBA60 /* MessageBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1EAD6AF1C826B6D006DBA60 /* MessageBody.swift */; };
C1EAD6B51C826B6D006DBA60 /* MessageType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1EAD6B01C826B6D006DBA60 /* MessageType.swift */; };
Expand Down Expand Up @@ -583,7 +584,7 @@
C18C8C521D64123400E043FB /* EnableBolusWizardPumpEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnableBolusWizardPumpEvent.swift; sourceTree = "<group>"; };
C1A492621D4A5A19008964FF /* IOBStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IOBStatus.swift; sourceTree = "<group>"; };
C1A492641D4A5DEB008964FF /* BatteryStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatteryStatus.swift; sourceTree = "<group>"; };
C1A492661D4A65D9008964FF /* LoopSuggested.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoopSuggested.swift; sourceTree = "<group>"; };
C1A492661D4A65D9008964FF /* RecommendedTempBasal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecommendedTempBasal.swift; sourceTree = "<group>"; };
C1A492681D4A66C0008964FF /* LoopEnacted.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoopEnacted.swift; sourceTree = "<group>"; };
C1AACC6A1CECD5F500C07049 /* RileyLinkListTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RileyLinkListTableViewController.swift; sourceTree = "<group>"; };
C1AF21E11D4838C90088C41D /* DeviceStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceStatus.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -611,6 +612,7 @@
C1C357901C92733A009BDD4F /* MeterMessageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MeterMessageTests.swift; path = Messages/MeterMessageTests.swift; sourceTree = "<group>"; };
C1E535E81991E36700C2AC49 /* NSData+Conversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Conversion.h"; sourceTree = "<group>"; };
C1E535E91991E36700C2AC49 /* NSData+Conversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Conversion.m"; sourceTree = "<group>"; };
C1E5BEAC1D5E26F200BD4390 /* RileyLinkStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RileyLinkStatus.swift; sourceTree = "<group>"; };
C1EAD6AE1C826B6D006DBA60 /* AlertType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertType.swift; sourceTree = "<group>"; };
C1EAD6AF1C826B6D006DBA60 /* MessageBody.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageBody.swift; sourceTree = "<group>"; };
C1EAD6B01C826B6D006DBA60 /* MessageType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MessageType.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
Expand Down Expand Up @@ -1123,9 +1125,10 @@
C178845E1D5166BE00405663 /* COBStatus.swift */,
C1A492641D4A5DEB008964FF /* BatteryStatus.swift */,
C1AF21E31D4865320088C41D /* LoopStatus.swift */,
C1A492661D4A65D9008964FF /* LoopSuggested.swift */,
C1A492661D4A65D9008964FF /* RecommendedTempBasal.swift */,
C1A492681D4A66C0008964FF /* LoopEnacted.swift */,
C133CF921D5943780034B82D /* PredictedBG.swift */,
C1E5BEAC1D5E26F200BD4390 /* RileyLinkStatus.swift */,
);
path = DeviceStatus;
sourceTree = "<group>";
Expand Down Expand Up @@ -1906,6 +1909,7 @@
C1AF21F01D4901220088C41D /* BolusNightscoutTreatment.swift in Sources */,
C1AF21F21D4901220088C41D /* BGCheckNightscoutTreatment.swift in Sources */,
C1AF21E61D48667F0088C41D /* UploaderStatus.swift in Sources */,
C1E5BEAD1D5E26F200BD4390 /* RileyLinkStatus.swift in Sources */,
C1AF21F31D4901220088C41D /* MealBolusNightscoutTreatment.swift in Sources */,
C1A492691D4A66C0008964FF /* LoopEnacted.swift in Sources */,
C1A492651D4A5DEB008964FF /* BatteryStatus.swift in Sources */,
Expand All @@ -1915,7 +1919,7 @@
C133CF931D5943780034B82D /* PredictedBG.swift in Sources */,
C1AF21E41D4865320088C41D /* LoopStatus.swift in Sources */,
C1AF21F11D4901220088C41D /* NightscoutTreatment.swift in Sources */,
C1A492671D4A65D9008964FF /* LoopSuggested.swift in Sources */,
C1A492671D4A65D9008964FF /* RecommendedTempBasal.swift in Sources */,
C178845F1D5166BE00405663 /* COBStatus.swift in Sources */,
43B0ADC91D1268B300AAD278 /* TimeFormat.swift in Sources */,
C1AF21E21D4838C90088C41D /* DeviceStatus.swift in Sources */,
Expand Down

0 comments on commit 7a41c31

Please sign in to comment.