Skip to content

Commit 1ff0a30

Browse files
committed
Merge pull request #19 from someoneAnyone/dev
Dev
2 parents 6e1888a + 0182a56 commit 1ff0a30

15 files changed

+305
-127
lines changed

Nightscouter.xcodeproj/project.pbxproj

-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
1771B0691B7524AA006C1F5E /* NightscoutAPIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B0651B7524AA006C1F5E /* NightscoutAPIClient.swift */; };
3232
1771B0751B7524D5006C1F5E /* CompassControl+Convience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06B1B7524D5006C1F5E /* CompassControl+Convience.swift */; };
3333
1771B0761B7524D5006C1F5E /* Double+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06C1B7524D5006C1F5E /* Double+Extension.swift */; };
34-
1771B0771B7524D5006C1F5E /* Int+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06D1B7524D5006C1F5E /* Int+Extensions.swift */; };
3534
1771B0781B7524D5006C1F5E /* NSAssetKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06E1B7524D5006C1F5E /* NSAssetKit.swift */; };
3635
1771B0791B7524D5006C1F5E /* NSAssetKit+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06F1B7524D5006C1F5E /* NSAssetKit+Helpers.swift */; };
3736
1771B07A1B7524D5006C1F5E /* NSCalendar+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B0701B7524D5006C1F5E /* NSCalendar+Extension.swift */; };
@@ -126,7 +125,6 @@
126125
1771B0651B7524AA006C1F5E /* NightscoutAPIClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NightscoutAPIClient.swift; path = API/NightscoutAPIClient.swift; sourceTree = "<group>"; };
127126
1771B06B1B7524D5006C1F5E /* CompassControl+Convience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "CompassControl+Convience.swift"; path = "Extensions/CompassControl+Convience.swift"; sourceTree = "<group>"; };
128127
1771B06C1B7524D5006C1F5E /* Double+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Double+Extension.swift"; path = "Extensions/Double+Extension.swift"; sourceTree = "<group>"; };
129-
1771B06D1B7524D5006C1F5E /* Int+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Int+Extensions.swift"; path = "Extensions/Int+Extensions.swift"; sourceTree = "<group>"; };
130128
1771B06E1B7524D5006C1F5E /* NSAssetKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSAssetKit.swift; path = Extensions/NSAssetKit.swift; sourceTree = "<group>"; };
131129
1771B06F1B7524D5006C1F5E /* NSAssetKit+Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSAssetKit+Helpers.swift"; path = "Extensions/NSAssetKit+Helpers.swift"; sourceTree = "<group>"; };
132130
1771B0701B7524D5006C1F5E /* NSCalendar+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSCalendar+Extension.swift"; path = "Extensions/NSCalendar+Extension.swift"; sourceTree = "<group>"; };
@@ -370,7 +368,6 @@
370368
isa = PBXGroup;
371369
children = (
372370
1771B06C1B7524D5006C1F5E /* Double+Extension.swift */,
373-
1771B06D1B7524D5006C1F5E /* Int+Extensions.swift */,
374371
1771B0701B7524D5006C1F5E /* NSCalendar+Extension.swift */,
375372
1771B0711B7524D5006C1F5E /* NSURL-Extensions.swift */,
376373
1771B0721B7524D5006C1F5E /* String+Extensions.swift */,
@@ -614,7 +611,6 @@
614611
1771B0761B7524D5006C1F5E /* Double+Extension.swift in Sources */,
615612
1771B0751B7524D5006C1F5E /* CompassControl+Convience.swift in Sources */,
616613
1771B0781B7524D5006C1F5E /* NSAssetKit.swift in Sources */,
617-
1771B0771B7524D5006C1F5E /* Int+Extensions.swift in Sources */,
618614
1771B0671B7524AA006C1F5E /* AppTheme.swift in Sources */,
619615
1771B0871B7524FD006C1F5E /* WatchEntry.swift in Sources */,
620616
1771B0681B7524AA006C1F5E /* Constants.swift in Sources */,

Nightscouter/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</dict>
3333
</array>
3434
<key>CFBundleVersion</key>
35-
<string>130</string>
35+
<string>132</string>
3636
<key>LSRequiresIPhoneOS</key>
3737
<true/>
3838
<key>NSUserActivityTypes</key>

Nightscouter/Localizable.strings

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525
"uiAlertScreenOverrideTitle" = "Prevent Screen from Locking?";
2626
"uiAlertScreenOverrideMessage" = "Selecting Yes will prevent the application from going to sleep and locking while viewing this site.";
2727

28-
"sgvLowString" = "Low";
28+
"sgvLowString" = "Low";
29+
30+
"nightscoutTitleString" = "Nightscouter";

Nightscouter/SiteDetailViewController.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ extension SiteDetailViewController {
8686
let updateData = "updateData(\(self.data))"
8787

8888
if let configuration = site?.configuration {
89-
let updateUnits = "updateUnits(\(configuration.displayUnits.rawValue))"
89+
90+
let updateUnits = "updateUnits(\(configuration.displayUnits.hashValue))"
9091
webView.stringByEvaluatingJavaScriptFromString(updateUnits)
9192
}
9293
webView.stringByEvaluatingJavaScriptFromString(updateData)
@@ -167,9 +168,15 @@ extension SiteDetailViewController {
167168

168169
// Raw label
169170
if let rawValue = watchEntry.raw {
170-
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(Int(rawValue)))
171+
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(rawValue))
172+
173+
var raw = "\(rawValue.formattedForMgdl)"
174+
if configuration.displayUnits == .Mmol {
175+
raw = rawValue.formattedForMmol
176+
}
177+
171178
self.siteRawLabel?.textColor = color
172-
self.siteRawLabel?.text = "\(NSNumberFormatter.localizedStringFromNumber(rawValue, numberStyle: NSNumberFormatterStyle.DecimalStyle)) : \(sgv.noise)"
179+
self.siteRawLabel?.text = "\(raw) : \(sgv.noise)"
173180
}
174181

175182
let timeAgo = watchEntry.date.timeIntervalSinceNow
@@ -195,7 +202,7 @@ extension SiteDetailViewController {
195202
if let entries = entries {
196203
for entry in entries {
197204
if let sgv = entry.sgv {
198-
if (sgv.sgv > Constants.EntryCount.LowerLimitForValidSGV) {
205+
if (sgv.sgv > Double(Constants.EntryCount.LowerLimitForValidSGV)) {
199206
self.data.append(entry.jsonForChart)
200207
}
201208
}

Nightscouter/SiteTableViewCell.swift

+15-4
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,27 @@ class SiteTableViewCell: UITableViewCell {
6363

6464
if let sgvValue = watchEntry.sgv {
6565

66-
let color = colorForDesiredColorState(site.configuration!.boundedColorForGlucoseValue(sgvValue.sgv))
66+
var boundedColor = configuration.boundedColorForGlucoseValue(sgvValue.sgv)
67+
if configuration.displayUnits == .Mmol {
68+
boundedColor = configuration.boundedColorForGlucoseValue(sgvValue.sgv.toMgdl)
69+
}
70+
let color = colorForDesiredColorState(boundedColor)
71+
6772
siteColorBlockView.backgroundColor = color
6873

6974
if let enabledOptions = configuration.enabledOptions {
7075
let rawEnabled = contains(enabledOptions, EnabledOptions.rawbg)
7176
if rawEnabled {
7277
if let rawValue = watchEntry.raw {
73-
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(Int(rawValue)))
78+
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(rawValue))
79+
80+
var raw = "\(rawValue.formattedForMgdl)"
81+
if configuration.displayUnits == .Mmol {
82+
raw = rawValue.formattedForMmol
83+
}
84+
7485
siteRawLabel?.textColor = color
75-
siteRawLabel.text = "\(NSNumberFormatter.localizedStringFromNumber(rawValue, numberStyle: .DecimalStyle)) : \(sgvValue.noise)"
86+
siteRawLabel.text = "\(raw) : \(sgvValue.noise)"
7687
}
7788
} else {
7889
siteRawHeader.hidden = true
@@ -132,7 +143,7 @@ class SiteTableViewCell: UITableViewCell {
132143
siteColorBlockView.backgroundColor = siteCompassControl.color
133144
siteLastReadingLabel.text = Constants.LocalizedString.tableViewCellLoading.localized
134145
siteLastReadingLabel.textColor = Theme.Color.labelTextColor
135-
146+
136147
siteRawHeader.hidden = false
137148
siteRawLabel.hidden = false
138149
siteRawLabel.textColor = Theme.Color.labelTextColor

Nightscouter/TestHarnessForCompassViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extension TestHarnessForCompassViewController {
9898

9999
func updateDelta(){
100100
print("newValue: \(newValue); oldValue: \(oldValue); delta: \(newValue - oldValue)")
101-
let deltaValue = newValue - oldValue
101+
let deltaValue = Double(newValue - oldValue)
102102
compassControlView.delta = "\(deltaValue.formattedForBGDelta) " + bgUnits
103103
}
104104

NightscouterKit/Extensions/CompassControl+Convience.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010

1111
public extension CompassControl {
1212

13-
func configure(sgvText: String, color: UIColor, direction: Direction, bgdelta: Int, units: String) -> Void {
13+
func configure(sgvText: String, color: UIColor, direction: Direction, bgdelta: Double, units: String) -> Void {
1414
self.sgvText = sgvText
1515
self.color = color
1616
self.direction = direction
@@ -20,11 +20,16 @@ public extension CompassControl {
2020
public func configureWith(site: Site){
2121
if let configuration: ServerConfiguration = site.configuration, watch: WatchEntry = site.watchEntry, sgv: SensorGlucoseValue = watch.sgv {
2222

23-
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(sgv.sgv))
23+
var boundedColor = configuration.boundedColorForGlucoseValue(sgv.sgv)
2424

2525
var units: Units = configuration.displayUnits
26+
if units == .Mmol {
27+
boundedColor = configuration.boundedColorForGlucoseValue(sgv.sgv.toMgdl)
28+
}
2629

27-
configure(sgv.sgvString, color: color, direction: sgv.direction, bgdelta: watch.bgdelta, units: units.rawValue)
30+
let color = colorForDesiredColorState(boundedColor)
31+
32+
configure(sgv.sgvString, color: color, direction: sgv.direction, bgdelta: watch.bgdelta, units: units.description)
2833
}
2934
}
3035

NightscouterKit/Extensions/Double+Extension.swift

+60
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,65 @@ public extension Double {
2121
let date = NSDate(timeIntervalSince1970:millisecondsToSecondsTimeInterval())
2222
return date
2323
}
24+
25+
}
26+
27+
public extension Double {
28+
public var toMmol: Double {
29+
get{
30+
return (self / 18)
31+
}
32+
}
33+
34+
public var toMgdl: Double {
35+
get{
36+
return self * 18
37+
}
38+
}
39+
40+
internal var mgdlFormatter: NSNumberFormatter {
41+
let numberFormat = NSNumberFormatter()
42+
numberFormat.numberStyle = .NoStyle
43+
44+
return numberFormat
45+
}
46+
47+
public var formattedForMgdl: String {
48+
return self.mgdlFormatter.stringFromNumber(self)!
49+
}
50+
51+
internal var mmolFormatter: NSNumberFormatter {
52+
let numberFormat = NSNumberFormatter()
53+
numberFormat.numberStyle = .DecimalStyle
54+
numberFormat.minimumFractionDigits = 1
55+
numberFormat.maximumFractionDigits = 1
56+
numberFormat.secondaryGroupingSize = 1
57+
58+
return numberFormat
59+
}
60+
61+
public var formattedForMmol: String {
62+
return self.mmolFormatter.stringFromNumber(self.toMmol)!
63+
}
64+
}
65+
66+
public extension Double {
67+
internal var bgDeltaFormatter: NSNumberFormatter {
68+
let numberFormat = NSNumberFormatter()
69+
numberFormat.numberStyle = .DecimalStyle
70+
numberFormat.positivePrefix = numberFormat.plusSign
71+
numberFormat.negativePrefix = numberFormat.minusSign
72+
73+
return numberFormat
74+
}
75+
76+
public var formattedForBGDelta: String {
77+
return self.bgDeltaFormatter.stringFromNumber(self)!
78+
}
2479
}
2580

81+
public extension Double {
82+
var isInteger: Bool {
83+
return rint(self) == self
84+
}
85+
}

NightscouterKit/Extensions/Int+Extensions.swift

-24
This file was deleted.

NightscouterKit/Extensions/String+Extensions.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99
import Foundation
1010

11-
extension String {
11+
public extension String {
1212
public var localized: String {
1313
return NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: "")
1414
}
1515
public func localizedWithComment(comment:String) -> String {
1616
return NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: comment)
1717
}
18-
18+
}
19+
20+
public extension String {
1921
public var versions: [String] {
2022
return self.componentsSeparatedByString(".")
2123
}
22-
2324
public var majorVersion: Int {
2425
return versions.first!.toInt()!
2526
}
@@ -29,4 +30,13 @@ extension String {
2930
public var buildVersion: Int {
3031
return versions.last!.toInt()!
3132
}
33+
}
34+
35+
public extension String {
36+
public var floatValue: Float? {
37+
return NSNumberFormatter().numberFromString(self)?.floatValue //(self as NSString).floatValue
38+
}
39+
public var toDouble: Double? {
40+
return NSNumberFormatter().numberFromString(self)?.doubleValue
41+
}
3242
}

0 commit comments

Comments
 (0)