Skip to content

Commit

Permalink
Updates to upload trend/trendRate/mbg (#18)
Browse files Browse the repository at this point in the history
* Updates to upload trend/trendRate/mbg

* Use actual device info for NS device string

* Fix build warnings
  • Loading branch information
ps2 authored Apr 3, 2022
1 parent 31e5853 commit 4edd730
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 5 additions & 1 deletion NightscoutServiceKit/Extensions/HKUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ extension HKUnit {
static let millimolesPerLiter: HKUnit = {
return HKUnit.moleUnit(with: .milli, molarMass: HKUnitMolarMassBloodGlucose).unitDivided(by: .liter())
}()


static let milligramsPerDeciliterPerMinute: HKUnit = {
return HKUnit.milligramsPerDeciliter.unitDivided(by: .minute())
}()

}
2 changes: 1 addition & 1 deletion NightscoutServiceKit/Extensions/NightscoutUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension NightscoutUploader {
return
}

uploadEntries(samples.compactMap { $0.nightscoutEntry }) { result in
uploadEntries(samples.compactMap { $0.glucoseEntry }) { result in
switch result {
case .failure(let error):
completion(.failure(error))
Expand Down
30 changes: 24 additions & 6 deletions NightscoutServiceKit/Extensions/StoredGlucoseSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@ import NightscoutUploadKit

extension StoredGlucoseSample {

var nightscoutEntry: NightscoutEntry {
return NightscoutEntry(
glucose: Int(quantity.doubleValue(for: .milligramsPerDeciliter)),
timestamp: startDate,
device: "loop://\(UIDevice.current.name)",
glucoseType: .Sensor
var glucoseEntry: GlucoseEntry {
let glucoseTrend: GlucoseEntry.GlucoseTrend?
if let trend = trend {
glucoseTrend = GlucoseEntry.GlucoseTrend(rawValue: trend.rawValue)
} else {
glucoseTrend = nil
}

let deviceString: String

if let device = device, let manufacturer = device.manufacturer, let model = device.model, let software = device.softwareVersion {
deviceString = "loop://\(manufacturer)/\(model)/\(software)"
} else {
deviceString = "loop://\(UIDevice.current.name)"
}

return GlucoseEntry(
glucose: quantity.doubleValue(for: .milligramsPerDeciliter),
date: startDate,
device: deviceString,
glucoseType: wasUserEntered ? .meter : .sensor,
trend: glucoseTrend,
changeRate: trendRate?.doubleValue(for: .milligramsPerDeciliterPerMinute),
isCalibration: isDisplayOnly
)
}

Expand Down
2 changes: 1 addition & 1 deletion NightscoutServiceKitUI/Extensions/IdentifiableClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

protocol IdentifiableClass: class {
protocol IdentifiableClass: AnyObject {

static var className: String { get }

Expand Down

0 comments on commit 4edd730

Please sign in to comment.