Skip to content

Commit

Permalink
use entries endpoint instead of pebble due to inconsistency in units
Browse files Browse the repository at this point in the history
  • Loading branch information
kenstack committed May 27, 2019
1 parent 3ee60e2 commit e34357d
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 198 deletions.
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Created by Kenneth Stack on 4/12/18.
// Copyright © 2018 Perceptus.org. All rights reserved.
//
unique_id = 87655
unique_id = 342
6 changes: 1 addition & 5 deletions nsapple WatchKit App/Interface.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14490.70" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
<device id="watch44" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14490.21"/>
</dependencies>
Expand Down Expand Up @@ -130,7 +126,7 @@
<outlet property="bgGraph" destination="v8P-Xw-gHJ" id="3FM-44-uu6"/>
<outlet property="deltaBG" destination="drV-DZ-SeX" id="hVe-q7-5Oy"/>
<outlet property="errorDisplay" destination="o6T-Uw-G7S" id="IdW-IR-f7Z"/>
<outlet property="graphHours" destination="oz4-fb-Ktb" id="lCb-Bl-oFm"/>
<outlet property="graphHoursDisplay" destination="oz4-fb-Ktb" id="lCb-Bl-oFm"/>
<outlet property="hourSlider" destination="t7h-De-bBi" id="66r-Am-noX"/>
<outlet property="loopStatus2" destination="8Qo-he-BQ1" id="Xcb-1B-meO"/>
<outlet property="minAgo" destination="IwJ-4k-L7w" id="2kZ-8q-Xj1"/>
Expand Down
46 changes: 17 additions & 29 deletions nsapple WatchKit Extension/InterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import WatchKit
import Foundation






class InterfaceController: WKInterfaceController {

@IBOutlet weak var bgGraph: WKInterfaceImage!
@IBOutlet weak var primaryBG: WKInterfaceLabel!
@IBOutlet weak var bgDirection: WKInterfaceLabel!
@IBOutlet weak var deltaBG: WKInterfaceLabel!
@IBOutlet weak var minAgo: WKInterfaceLabel!
@IBOutlet weak var graphHours: WKInterfaceLabel!
@IBOutlet weak var graphHoursDisplay: WKInterfaceLabel!
@IBOutlet weak var hourSlider: WKInterfaceSlider!
@IBOutlet var statusOverride: WKInterfaceLabel!
@IBOutlet var loopStatus2: WKInterfaceLabel!
Expand All @@ -30,7 +26,7 @@ class InterfaceController: WKInterfaceController {
@IBOutlet weak var velocity: WKInterfaceLabel!
@IBOutlet var errorDisplay: WKInterfaceLabel!
@IBOutlet var basalDisplay: WKInterfaceLabel!
var graphLength:Int=3
var graphHours:Int=3
var mmol = false as Bool
var urlUser = "No User URL" as String
var token = "" as String
Expand All @@ -43,7 +39,7 @@ class InterfaceController: WKInterfaceController {
@IBAction func hourslidervalue(_ value: Float) {
let sliderMap:[Int:Int]=[1:24,2:12,3:6,4:3,5:1]
let sliderValue=Int(round(value*1000)/1000)
graphLength=sliderMap[sliderValue]!
graphHours=sliderMap[sliderValue]!
loadData(urlUser:urlUser, mmol: mmol)

}
Expand All @@ -60,13 +56,11 @@ class InterfaceController: WKInterfaceController {
let name : String = "group.com." + unique_id[0] + ".nsapple"
defaults = UserDefaults(suiteName: name)
}

else
{
self.errorDisplay.setTextColor(UIColor.red)
self.errorDisplay.setText("Could Not Read Bundle Idenifier")
}

}

}

Expand Down Expand Up @@ -137,9 +131,9 @@ class InterfaceController: WKInterfaceController {
return
}

let points = String(self.graphLength * 12 + 1)
let points = String(self.graphHours * 12 + 1)

var urlPath: String = urlUser + "/pebble?"
var urlPath: String = urlUser + "/api/v1/entries.json?"
if token == "" {
urlPath = urlPath + "count=" + points
}
Expand Down Expand Up @@ -174,10 +168,11 @@ class InterfaceController: WKInterfaceController {
return
}
let decoder = JSONDecoder()
let pebbleResponse = try? decoder.decode(dataPebble.self, from: data)
if let pebbleResponse = pebbleResponse {

let entriesResponse = try? decoder.decode([sgvData].self, from: data)
if let entriesResponse = entriesResponse {
DispatchQueue.main.async {
self.updateBG(pebbleResponse: pebbleResponse, mmol:mmol)
self.updateBG(entriesResponse: entriesResponse, mmol:mmol)
}
}
else
Expand Down Expand Up @@ -388,18 +383,11 @@ class InterfaceController: WKInterfaceController {
if consoleLogging == true {print("end updatePump")}
}

func updateBG (pebbleResponse: dataPebble, mmol: Bool) {
func updateBG (entriesResponse: [sgvData], mmol: Bool) {
if consoleLogging == true {print("in update BG")}

var entries = [entriesData]()
var j: Int = 0
//cast string sgvs to int
//to do there must be a simpler way ......
while j < pebbleResponse.bgs.count {
entries.append(entriesData(sgv: Int(pebbleResponse.bgs[j].sgv) ?? 0, date: pebbleResponse.bgs[j].datetime, direction: pebbleResponse.bgs[j].direction ))
j=j+1
}
//successfully received pebble end point data
var entries = entriesResponse

if entries.count > 0 {
let currentBG=entries[0].sgv
let priorBG = entries[1].sgv
Expand Down Expand Up @@ -457,14 +445,14 @@ class InterfaceController: WKInterfaceController {
return
}

createGraph(hours: self.graphLength, bghist: entries, mmol: mmol)
self.graphHours.setText(String(self.graphLength) + " Hour Graph")
createGraph(hours: self.graphHours, bghist: entries, mmol: mmol)
self.graphHoursDisplay.setText(String(self.graphHours) + " Hour Graph")

if consoleLogging == true {print("end update bg")}
}


func createGraph(hours:Int, bghist:[entriesData], mmol: Bool) {
func createGraph(hours:Int, bghist:[sgvData], mmol: Bool) {
// create graph

// Create a graphics context
Expand Down Expand Up @@ -626,7 +614,7 @@ class InterfaceController: WKInterfaceController {



func bgScaling(_ hours:Int,bgHist:[entriesData], width: CGFloat)-> ([Double], [Double], [UIColor], Double, Double) {
func bgScaling(_ hours:Int,bgHist:[sgvData], width: CGFloat)-> ([Double], [Double], [UIColor], Double, Double) {


let ct2=NSInteger(Date().timeIntervalSince1970)
Expand Down
11 changes: 1 addition & 10 deletions nsapple WatchKit Extension/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ import WatchKit


struct sgvData: Codable {
var sgv: String
var datetime: TimeInterval
var direction: String
}
struct dataPebble: Codable{
var bgs: [sgvData]

}
struct entriesData: Codable {
var sgv: Int
var date: TimeInterval
var direction: String
Expand Down Expand Up @@ -113,7 +104,7 @@ public struct watch {
}
}

func velocity_cf(_ bgs:[entriesData])->Double {
func velocity_cf(_ bgs:[sgvData])->Double {
//linear fit to 3 data points get slope (ie velocity)
var v=0 as Double
var n=0 as Int
Expand Down
16 changes: 8 additions & 8 deletions nsapple.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
CODE_SIGN_ENTITLEMENTS = nsapple/nsapple.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
INFOPLIST_FILE = nsapple/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -665,7 +665,7 @@
CODE_SIGN_ENTITLEMENTS = nsapple/nsapple.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
INFOPLIST_FILE = nsapple/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -685,7 +685,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -711,7 +711,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -735,7 +735,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "nsapple WatchKit App/nsapple WatchKit App.entitlements";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -758,7 +758,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "nsapple WatchKit App/nsapple WatchKit App.entitlements";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
IBSC_MODULE = nsapple_WatchKit_Extension;
INFOPLIST_FILE = "nsapple WatchKit App/Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "$(unique_id).nsapple.watchkitapp";
Expand All @@ -777,7 +777,7 @@
CODE_SIGN_ENTITLEMENTS = "nsapple WatchKit Extension/nsapple WatchKit Extension.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/watchOS",
Expand Down Expand Up @@ -809,7 +809,7 @@
CODE_SIGN_ENTITLEMENTS = "nsapple WatchKit Extension/nsapple WatchKit Extension.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 9B53A6G255;
DEVELOPMENT_TEAM = 6Q7ZC8Q56M;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/watchOS",
Expand Down
Loading

0 comments on commit e34357d

Please sign in to comment.