Skip to content

Commit

Permalink
Merge pull request #30 from someoneAnyone/dev
Browse files Browse the repository at this point in the history
Syncing master with dev for the 1.0.2 release to the Apple AppStore.
  • Loading branch information
someoneAnyone committed Dec 9, 2015
2 parents df117a7 + 4055f8d commit cfa5094
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 186 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Peter Ina & Nightscouter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
138 changes: 99 additions & 39 deletions Nightscouter/Base.lproj/Labs.storyboard

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions Nightscouter/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Nightscouter/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -32,9 +32,14 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>138</string>
<string>151</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>com.nothingonline.$(PRODUCT_NAME:rfc1034identifier).sites</string>
Expand Down
2 changes: 1 addition & 1 deletion NightscouterKit/Extensions/CompassControl+Convience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension CompassControl {

let color = colorForDesiredColorState(boundedColor)

configure(sgv.sgvString, color: color, direction: sgv.direction, bgdelta: watch.bgdelta, units: units.description)
configure(sgv.sgvString(forUnits: units), color: color, direction: sgv.direction, bgdelta: watch.bgdelta, units: units.description)
}
}

Expand Down
10 changes: 8 additions & 2 deletions NightscouterKit/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public extension String {
}

public extension String {
var formatter: NSNumberFormatter {
let formatter = NSNumberFormatter()
formatter.locale = NSLocale.systemLocale()
return formatter
}

public var floatValue: Float? {
return NSNumberFormatter().numberFromString(self)?.floatValue //(self as NSString).floatValue
return formatter.numberFromString(self)?.floatValue
}
public var toDouble: Double? {
return NSNumberFormatter().numberFromString(self)?.doubleValue
return formatter.numberFromString(self)?.doubleValue
}
}
2 changes: 1 addition & 1 deletion NightscouterKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
99 changes: 58 additions & 41 deletions NightscouterKit/Models/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public enum Device: String {
case xDripDexcomShare = "xDrip-DexcomShare"
case WatchFace = "watchFace"
case Share2 = "share2"
case MedtronicCGM = "Medtronic_CGM"

}

// type = cal
Expand All @@ -122,42 +124,44 @@ public struct SensorGlucoseValue {
enum ReservedValues: Double {
case NoGlucose=0, SensoreNotActive=1, MinimalDeviation=2, NoAntenna=3, SensorNotCalibrated=5, CountsDeviation=6, AbsoluteDeviation=9, PowerDeviation=10, BadRF=12, HupHolland=17
}

public func sgvString(forUnits units: Units) -> String {

let mgdlSgvValue: Double = (units == .Mgdl) ? sgv : sgv.toMgdl // If the units are set to mgd/L do nothing let it pass... if its mmol/L then convert it back to mgd/L to get its proper string.

if let special:ReservedValues = ReservedValues(rawValue: mgdlSgvValue) {
switch (special) {
case .NoGlucose:
return "?NG"
case .SensoreNotActive:
return "?NA"
case .MinimalDeviation:
return "?MD"
case .NoAntenna:
return "?NA"
case .SensorNotCalibrated:
return "?NC"
case .CountsDeviation:
return "?CD"
case .AbsoluteDeviation:
return "?AD"
case .PowerDeviation:
return "?PD"
case .BadRF:
return "?RF✖"
case .HupHolland:
return "MH"
}
}
if sgv >= 30 && sgv < 40 {
return NSLocalizedString("sgvLowString", tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: "Label used to indicate a very low blood sugar.")
}
return NSNumberFormatter.localizedStringFromNumber(self.sgv, numberStyle: NSNumberFormatterStyle.DecimalStyle)
}

public var sgvString: String { // Consider moving this to a Printable or similar protocal?
public var sgvString: String { // moved its logic to [public func sgvString(forUnits units: Units) -> String]
get {

let mgdlSgvValue: Double = sgv.isInteger ? sgv : sgv.toMgdl

if let special:ReservedValues = ReservedValues(rawValue: mgdlSgvValue) {
switch (special) {
case .NoGlucose:
return "?NG"
case .SensoreNotActive:
return "?NA"
case .MinimalDeviation:
return "?MD"
case .NoAntenna:
return "?NA"
case .SensorNotCalibrated:
return "?NC"
case .CountsDeviation:
return "?CD"
case .AbsoluteDeviation:
return "?AD"
case .PowerDeviation:
return "?PD"
case .BadRF:
return "?RF✖"
case .HupHolland:
return "MH"
// default:
// return "✖"
}
}
if sgv >= 30 && sgv < 40 {
return NSLocalizedString("sgvLowString", tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: "Label used to indicate a very low blood sugar.")
}
return NSNumberFormatter.localizedStringFromNumber(self.sgv, numberStyle: NSNumberFormatterStyle.DecimalStyle)
return sgvString(forUnits: .Mgdl)
}
}
}
Expand Down Expand Up @@ -258,7 +262,7 @@ public class Entry {
self.device = device
}

public init(identifier: String, date: NSDate, device: String, dateString: String, sgv: SensorGlucoseValue?, cal: Calibration?, mbg: MeterBloodGlucose?, type: Type) {
public init(identifier: String, date: NSDate, device: String, dateString: String?, sgv: SensorGlucoseValue?, cal: Calibration?, mbg: MeterBloodGlucose?, type: Type) {
self.identifier = identifier
self.date = date
self.device = device
Expand Down Expand Up @@ -308,18 +312,24 @@ public extension Entry {

let dateString = dict[EntryPropertyKey.dateStringKey] as? String

/*
guard let stringForType = dict[EntryPropertyKey.typeKey] as? String,
type: Type = Type(rawValue: stringForType) else {

self.init(identifier: "none", date: NSDate(), device:"none")

return
type: Type = Type(rawValue: stringForType) else {

self.init(identifier: "none", date: date, device: device)
return
}
*/

var sgValue: SensorGlucoseValue! = nil
var calValue: Calibration! = nil
var mbgValue: MeterBloodGlucose! = nil

var type: Type = .none
if let stringForType = dict[EntryPropertyKey.typeKey] as? String, t: Type = Type(rawValue: stringForType) {
type = t
}

switch type {
case .sgv:

Expand Down Expand Up @@ -359,9 +369,16 @@ public extension Entry {
#if DEBUG
print(errorString)
#endif
if let directionString = dict[EntryPropertyKey.directionKey] as? String,
direction = Direction(rawValue: directionString),
sgv = dict[EntryPropertyKey.sgvKey] as? Double {

sgValue = SensorGlucoseValue(sgv: sgv, direction: direction, filtered: 0, unfiltered: 0, rssi: 0, noise: .None)
}

break
}
self.init(identifier: identifier, date: date, device:device, dateString: dateString!, sgv: sgValue, cal: calValue, mbg: mbgValue, type: type)
self.init(identifier: identifier, date: date, device:device, dateString: dateString, sgv: sgValue, cal: calValue, mbg: mbgValue, type: type)
}
}

Expand Down
52 changes: 36 additions & 16 deletions NightscouterKit/Models/ServerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct ConfigurationPropertyKey {
static let nameKey = "name"
static let statusKey = "status"
static let thresholdsKey = "thresholds"

// ver 7.0
static let bg_highKey = "bg_high"
static let bg_lowKey = "bg_low"
Expand All @@ -159,10 +159,10 @@ struct ConfigurationPropertyKey {
static let versionKey = "version"

// Not implmented yet
static let extendedSettingsKey = "extendedSettings"
static let settingsKey = "settings"
static let enableKey = "enable"
static let showPluginsKey = "showPlugins"
static let extendedSettingsKey = "extendedSettings"
static let settingsKey = "settings"
static let enableKey = "enable"
static let showPluginsKey = "showPlugins"
}

public struct ServerConfiguration: CustomStringConvertible {
Expand All @@ -171,7 +171,7 @@ public struct ServerConfiguration: CustomStringConvertible {
public var careportalEnabled: Bool?
public var enabledOptions: [EnabledOptions]?
public var defaults: Defaults?
// public let settings: Defaults?
// public let settings: Defaults?
public var unitsRoot: Units?
public var head:String?
public var version: String?
Expand Down Expand Up @@ -278,7 +278,7 @@ public extension ServerConfiguration {
let bg_target_top = thresholdsDict[ConfigurationPropertyKey.bg_target_topKey] as! Double
threshold = Threshold(bg_high: bg_high, bg_low: bg_low, bg_target_bottom: bg_target_bottom, bg_target_top: bg_target_top)
}


var defaultsDefaults: Defaults?
if let defaultsDictionary = root[ConfigurationPropertyKey.defaultsKey] as? [String: AnyObject] {
Expand All @@ -305,7 +305,7 @@ public extension ServerConfiguration {
let alarms = Alarm(alarmHigh: aHigh, alarmLow: aLow, alarmTimeAgoUrgent: aTAU, alarmTimeAgoUrgentMins: aTAUMin, alarmTimeAgoWarn: aTAW, alarmTimeAgoWarnMins: aTAWMin, alarmUrgentHigh: aTUH, alarmUrgentLow: aTUL)

let language = defaultsDictionary[ConfigurationPropertyKey.languageKey] as! String

defaultsDefaults = Defaults(units: units, timeFormat: timeFormat, nightMode: nightMode, showRawbg: showRawbg, customTitle: customTitle, theme: theme, alarms: alarms, language: language, showPlugins: nil, enable: nil, thresholds: nil, defaultFeatures: nil)
}

Expand All @@ -315,6 +315,7 @@ public extension ServerConfiguration {

var timeFormat: Int = 12

// Some sites seem to post a number other seem to have strings.
if let stringTimeFormat = settingsDictionary[ConfigurationPropertyKey.timeFormatKey] as? String {
timeFormat = Int(stringTimeFormat)!
}
Expand All @@ -334,11 +335,31 @@ public extension ServerConfiguration {
let aHigh = settingsDictionary[ConfigurationPropertyKey.alarmHighKey] as! Bool
let aLow = settingsDictionary[ConfigurationPropertyKey.alarmLowKey] as! Bool
let aTAU = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoUrgentKey] as! Bool
let aTAUMDouble = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoUrgentMinsKey] as! Double

// Some sites seem to post a number other seem to have strings.
var aTAUMDouble: Double = 0
if let doubleATAUM = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoUrgentMinsKey] as? Double {
aTAUMDouble = doubleATAUM
}

if let stringATAUM = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoUrgentMinsKey] as? String {
aTAUMDouble = Double(stringATAUM)!
}

let aTAUMin: NSTimeInterval = aTAUMDouble * 60 // Convert minutes to seconds.

let aTAW = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoWarnKey] as! Bool
let aTAWMDouble = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoWarnMinsKey] as! Double

var aTAWMDouble: Double = 0

if let doubATAW = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoWarnMinsKey] as? Double {
aTAWMDouble = doubATAW
}

if let stringATAW = settingsDictionary[ConfigurationPropertyKey.alarmTimeagoWarnMinsKey] as? String {
aTAWMDouble = Double(stringATAW)!
}

let aTAWMin: NSTimeInterval = aTAWMDouble * 60 // Convert minutes to seconds.
let aTUH = settingsDictionary[ConfigurationPropertyKey.alarmUrgentHighKey] as! Bool
let aTUL = settingsDictionary[ConfigurationPropertyKey.alarmUrgentLowKey] as! Bool
Expand All @@ -347,7 +368,6 @@ public extension ServerConfiguration {

let language = settingsDictionary[ConfigurationPropertyKey.languageKey] as! String


if let enableArray = settingsDictionary[ConfigurationPropertyKey.enableKey] as? [String] {
for stringItem in enableArray{
if let item = EnabledOptions(rawValue: stringItem){
Expand All @@ -363,18 +383,18 @@ public extension ServerConfiguration {
let bg_target_top = thresholdsDict[ConfigurationPropertyKey.bgTargetTopKey] as! Double
threshold = Threshold(bg_high: bg_high, bg_low: bg_low, bg_target_bottom: bg_target_bottom, bg_target_top: bg_target_top)
}



defaultsDefaults = Defaults(units: units, timeFormat: timeFormat, nightMode: nightMode, showRawbg: showRawbg, customTitle: customTitle, theme: theme, alarms: alarms, language: language, showPlugins: nil, enable: options, thresholds: threshold, defaultFeatures: nil)

}

serverConfig.defaults = defaultsDefaults

serverConfig.thresholds = threshold
serverConfig.enabledOptions = options

self = serverConfig
}
}
Expand Down
Loading

0 comments on commit cfa5094

Please sign in to comment.