-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
240 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Sources/LoopIssueReportParser/Parsers/PersistedPumpEventParser.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// PersistedPumpEventParser.swift | ||
// | ||
// | ||
// Created by Pete Schwamb on 6/16/23. | ||
// | ||
|
||
import Parsing | ||
import HealthKit | ||
import LoopKit | ||
|
||
//* PersistedPumpEvent(date: 2023-06-15 14:26:41 +0000, persistedDate: 2023-06-15 14:27:04 +0000, dose: Optional(LoopKit.DoseEntry(type: LoopKit.DoseType.tempBasal, startDate: 2023-06-15 14:26:41 +0000, endDate: 2023-06-15 14:27:04 +0000, value: 0.0, unit: LoopKit.DoseUnit.unitsPerHour, deliveredUnits: Optional(0.0), description: nil, insulinType: Optional(LoopKit.InsulinType.novolog), automatic: Optional(true), manuallyEntered: false, syncIdentifier: Optional("a7e2601949dc4e4599ff07eeea3aa473"), isMutable: true, wasProgrammedByPumpUI: false, scheduledBasalRate: nil)), isUploaded: false, objectIDURL: x-coredata://D8510943-8CBA-4D7B-8398-AE7BCA863599/PumpEvent/p520493, raw: Optional(16 bytes), title: Optional("Temp Basal"), type: Optional(LoopKit.PumpEventType.tempBasal), automatic: Optional(true), alarmType: nil) | ||
|
||
public struct PersistedPumpEventParser: Parser { | ||
|
||
public var body: some Parser<Substring, PersistedPumpEvent> { | ||
let p = Parse { | ||
"PersistedPumpEvent(" | ||
AttributeValueParser(name: "date") { | ||
DebugDateParser() | ||
} | ||
", " | ||
AttributeValueParser(name: "persistedDate") { | ||
DebugDateParser() | ||
} | ||
", " | ||
AttributeValueParser(name: "dose") { | ||
OptionalParser { | ||
"LoopKit." | ||
DoseEntryParser() | ||
} | ||
} | ||
", " | ||
AttributeValueParser(name: "isUploaded") { | ||
Bool.parser() | ||
} | ||
", " | ||
AttributeValueParser(name: "objectIDURL") { | ||
Prefix() { | ||
$0 != "," | ||
} | ||
} | ||
", " | ||
AttributeValueParser(name: "raw") { | ||
OptionalParser { | ||
Prefix() { | ||
$0 != ")" | ||
} | ||
} | ||
} | ||
", " | ||
AttributeValueParser(name: "title") { | ||
OptionalParser { | ||
"\"" | ||
Prefix { $0 != "\"" } | ||
"\"" | ||
} | ||
} | ||
", " | ||
AttributeValueParser(name: "type") { | ||
OptionalParser { | ||
PumpEventTypeParser() | ||
} | ||
} | ||
", " | ||
AttributeValueParser(name: "automatic") { | ||
OptionalParser { | ||
Bool.parser() | ||
} | ||
} | ||
", " | ||
AttributeValueParser(name: "alarmType") { | ||
OptionalParser { | ||
PumpAlarmTypeParser() | ||
} | ||
} | ||
")" | ||
} | ||
|
||
p.map { (value) -> PersistedPumpEvent in | ||
let objectIDURL = URL(string: String(value.4)) ?? URL(string: "x-coredata://" + UUID().uuidString)! | ||
|
||
return PersistedPumpEvent( | ||
date: value.0, | ||
persistedDate: value.1, | ||
dose: value.2, | ||
isUploaded: value.3, | ||
objectIDURL: objectIDURL, | ||
raw: nil, // Debug print loses this info; need to fix in Loop | ||
title: value.6.map(String.init), | ||
type: value.7, | ||
automatic: value.8, | ||
alarmType: value.9) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Sources/LoopIssueReportParser/Parsers/PumpAlarmTypeParser.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// PumpAlarmTypeParser.swift | ||
// | ||
// | ||
// Created by Pete Schwamb on 6/17/23. | ||
// | ||
|
||
import Parsing | ||
import LoopKit | ||
|
||
// LoopKit.PumpAlarmType.other(\"Custom Alarm\")) | ||
|
||
struct PumpAlarmTypeParser: Parser { | ||
var body: some Parser<Substring, PumpAlarmType> { | ||
"LoopKit.PumpAlarmType." | ||
OneOf { | ||
Parse { | ||
"other(\"" | ||
Prefix() { | ||
$0 != "\"" | ||
} | ||
"\")" | ||
}.map { PumpAlarmType.other(String($0)) } | ||
"autoOff".map { PumpAlarmType.autoOff } | ||
"lowInsulin".map { PumpAlarmType.lowInsulin } | ||
"lowPower".map { PumpAlarmType.lowPower } | ||
"noDelivery".map { PumpAlarmType.noDelivery } | ||
"noInsulin".map { PumpAlarmType.noInsulin } | ||
"noPower".map { PumpAlarmType.noPower } | ||
"occlusion".map { PumpAlarmType.occlusion } | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Sources/LoopIssueReportParser/Parsers/PumpEventTypeParser.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// PumpEventTypeParser.swift | ||
// | ||
// | ||
// Created by Pete Schwamb on 6/17/23. | ||
// | ||
|
||
import Parsing | ||
import LoopKit | ||
|
||
struct PumpEventTypeParser: Parser { | ||
var body: some Parser<Substring, PumpEventType> { | ||
"LoopKit.PumpEventType." | ||
OneOf { | ||
for type in PumpEventType.allCases { | ||
String(describing: type).map { type } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.