Skip to content

Commit d1333f3

Browse files
committed
TabularData: filter out nil values and previous devices
1 parent d1eb115 commit d1333f3

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

DiaBLE Playground.swiftpm/ConsoleTools.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,25 @@ struct ShellView: View {
6767
app.main.log("TabularData: column names: \(dataFrame.columns.map(\.name))")
6868
app.main.log("TabularData:\n\(dataFrame)")
6969
let lastRow = dataFrame.rows.last!
70-
let lastDeviceSerial = lastRow["Serial Number"]!
70+
let lastDeviceSerial = lastRow["Serial Number"] as! String
7171
app.main.log("TabularData: last device serial: \(lastDeviceSerial)")
7272
var history = try DataFrame(csvData: csvData,
73-
columns: ["Device Timestamp", "Record Type", "Historic Glucose mg/dL"],
74-
types: ["Device Timestamp": .date, "Record Type": .integer, "Historic Glucose mg/dL": .integer],
73+
columns: ["Serial Number", "Device Timestamp", "Record Type", "Historic Glucose mg/dL"],
74+
types: ["Serial Number": .string, "Device Timestamp": .date, "Record Type": .integer, "Historic Glucose mg/dL": .integer],
7575
options: options)
7676
.sorted(on: "Device Timestamp", order: .descending)
7777
history.renameColumn("Device Timestamp", to: "Date")
7878
history.renameColumn("Record Type", to: "Type")
7979
history.renameColumn("Historic Glucose mg/dL", to: "Glucose")
80-
var formattingOptions = FormattingOptions(maximumLineWidth: 40, includesColumnTypes: false)
80+
var formattingOptions = FormattingOptions(maximumLineWidth: 80, includesColumnTypes: false)
8181
formattingOptions.includesRowIndices = false
8282
app.main.log("TabularData: history:\n\(history.description(options: formattingOptions))")
83+
let filteredHistory = history
84+
.filter(on: "Serial Number", String.self) { $0! == lastDeviceSerial }
85+
.filter(on: "Glucose", Int.self) { $0 != nil }
86+
.selecting(columnNames: ["Date", "Glucose"])
87+
formattingOptions.maximumLineWidth = 32
88+
app.main.log("TabularData: filtered history:\n\(filteredHistory.description(options: formattingOptions))")
8389
} catch {
8490
app.main.log("TabularData: error: \(error.localizedDescription)")
8591
}

DiaBLE.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@
659659
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
660660
CODE_SIGN_ENTITLEMENTS = DiaBLE/Widgets/DiaBLEWidgetExtension.entitlements;
661661
CODE_SIGN_STYLE = Automatic;
662-
CURRENT_PROJECT_VERSION = 87;
662+
CURRENT_PROJECT_VERSION = 88;
663663
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
664664
GCC_C_LANGUAGE_STANDARD = gnu17;
665665
GENERATE_INFOPLIST_FILE = YES;
@@ -696,7 +696,7 @@
696696
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
697697
CODE_SIGN_ENTITLEMENTS = DiaBLE/Widgets/DiaBLEWidgetExtension.entitlements;
698698
CODE_SIGN_STYLE = Automatic;
699-
CURRENT_PROJECT_VERSION = 87;
699+
CURRENT_PROJECT_VERSION = 88;
700700
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
701701
GCC_C_LANGUAGE_STANDARD = gnu17;
702702
GENERATE_INFOPLIST_FILE = YES;
@@ -733,7 +733,7 @@
733733
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
734734
CODE_SIGN_ENTITLEMENTS = "DiaBLE Watch/DiaBLE Watch.entitlements";
735735
CODE_SIGN_STYLE = Automatic;
736-
CURRENT_PROJECT_VERSION = 87;
736+
CURRENT_PROJECT_VERSION = 88;
737737
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
738738
ENABLE_PREVIEWS = YES;
739739
GENERATE_INFOPLIST_FILE = YES;
@@ -773,7 +773,7 @@
773773
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
774774
CODE_SIGN_ENTITLEMENTS = "DiaBLE Watch/DiaBLE Watch.entitlements";
775775
CODE_SIGN_STYLE = Automatic;
776-
CURRENT_PROJECT_VERSION = 87;
776+
CURRENT_PROJECT_VERSION = 88;
777777
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
778778
ENABLE_PREVIEWS = YES;
779779
GENERATE_INFOPLIST_FILE = YES;
@@ -936,7 +936,7 @@
936936
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
937937
CODE_SIGN_ENTITLEMENTS = DiaBLE/DiaBLE.entitlements;
938938
CODE_SIGN_STYLE = Automatic;
939-
CURRENT_PROJECT_VERSION = 87;
939+
CURRENT_PROJECT_VERSION = 88;
940940
DEAD_CODE_STRIPPING = YES;
941941
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
942942
ENABLE_HARDENED_RUNTIME = YES;
@@ -987,7 +987,7 @@
987987
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
988988
CODE_SIGN_ENTITLEMENTS = DiaBLE/DiaBLE.entitlements;
989989
CODE_SIGN_STYLE = Automatic;
990-
CURRENT_PROJECT_VERSION = 87;
990+
CURRENT_PROJECT_VERSION = 88;
991991
DEAD_CODE_STRIPPING = YES;
992992
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
993993
ENABLE_HARDENED_RUNTIME = YES;

DiaBLE/ConsoleTools.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,25 @@ struct ShellView: View {
6363
app.main.log("TabularData: column names: \(dataFrame.columns.map(\.name))")
6464
app.main.log("TabularData:\n\(dataFrame)")
6565
let lastRow = dataFrame.rows.last!
66-
let lastDeviceSerial = lastRow["Serial Number"]!
66+
let lastDeviceSerial = lastRow["Serial Number"] as! String
6767
app.main.log("TabularData: last device serial: \(lastDeviceSerial)")
6868
var history = try DataFrame(csvData: csvData,
69-
columns: ["Device Timestamp", "Record Type", "Historic Glucose mg/dL"],
70-
types: ["Device Timestamp": .date, "Record Type": .integer, "Historic Glucose mg/dL": .integer],
69+
columns: ["Serial Number", "Device Timestamp", "Record Type", "Historic Glucose mg/dL"],
70+
types: ["Serial Number": .string, "Device Timestamp": .date, "Record Type": .integer, "Historic Glucose mg/dL": .integer],
7171
options: options)
7272
.sorted(on: "Device Timestamp", order: .descending)
7373
history.renameColumn("Device Timestamp", to: "Date")
7474
history.renameColumn("Record Type", to: "Type")
7575
history.renameColumn("Historic Glucose mg/dL", to: "Glucose")
76-
var formattingOptions = FormattingOptions(maximumLineWidth: 40, includesColumnTypes: false)
76+
var formattingOptions = FormattingOptions(maximumLineWidth: 80, includesColumnTypes: false)
7777
formattingOptions.includesRowIndices = false
7878
app.main.log("TabularData: history:\n\(history.description(options: formattingOptions))")
79+
let filteredHistory = history
80+
.filter(on: "Serial Number", String.self) { $0! == lastDeviceSerial }
81+
.filter(on: "Glucose", Int.self) { $0 != nil }
82+
.selecting(columnNames: ["Date", "Glucose"])
83+
formattingOptions.maximumLineWidth = 32
84+
app.main.log("TabularData: filtered history:\n\(filteredHistory.description(options: formattingOptions))")
7985
} catch {
8086
app.main.log("TabularData: error: \(error.localizedDescription)")
8187
}

0 commit comments

Comments
 (0)