Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several EnvironmentMetrics enhancements #1037

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
}
}
}
},
"--" : {

},
": %@" : {
"localizations" : {
Expand All @@ -63,6 +66,9 @@
}
}
}
},
"?" : {

},
"(Re)define PIN_GPS_EN for your board." : {
"localizations" : {
Expand Down Expand Up @@ -544,6 +550,9 @@
}
}
}
},
"☢" : {

},
"🦕 End of life Version 🦖 ☄️" : {
"localizations" : {
Expand Down Expand Up @@ -1337,8 +1346,12 @@
}
}
}
},
"Airtime %@" : {

},
"Airtime %@%%" : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
Expand Down Expand Up @@ -4176,8 +4189,15 @@
}
}
}
},
"Channel Utilization --" : {

},
"Channel Utilization %@" : {

},
"Channel Utilization %@%% " : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
Expand Down Expand Up @@ -9243,6 +9263,9 @@
}
}
}
},
"DISTANCE" : {

},
"Documentation" : {
"localizations" : {
Expand Down Expand Up @@ -22450,6 +22473,9 @@
}
}
}
},
"RADIATION" : {

},
"Radio Disconnected" : {
"extractionState" : "manual",
Expand Down Expand Up @@ -31044,6 +31070,9 @@
}
}
}
},
"WEIGHT" : {

},
"What does the lock mean?" : {
"localizations" : {
Expand Down
32 changes: 27 additions & 5 deletions Meshtastic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
231B3F222D087A4C0069A07D /* MetricsColumnList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231B3F1F2D087A4C0069A07D /* MetricsColumnList.swift */; };
231B3F252D087C3C0069A07D /* EnvironmentDefaultColumns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231B3F242D087C3C0069A07D /* EnvironmentDefaultColumns.swift */; };
231B3F272D0885240069A07D /* MetricsColumnDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231B3F262D0885240069A07D /* MetricsColumnDetail.swift */; };
235FFC3A2D1D8CF0003C95E5 /* TelemetryEntity+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 235FFC392D1D8CF0003C95E5 /* TelemetryEntity+CoreDataProperties.swift */; };
235FFC3B2D1D8CF0003C95E5 /* TelemetryEntity+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 235FFC382D1D8CF0003C95E5 /* TelemetryEntity+CoreDataClass.swift */; };
235FFC3D2D1D8DC9003C95E5 /* ManagedAttributePropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 235FFC3C2D1D8DC8003C95E5 /* ManagedAttributePropertyWrapper.swift */; };
2373AE132D0A216C0086C749 /* MetricsChartSeries.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2373AE122D0A216C0086C749 /* MetricsChartSeries.swift */; };
2373AE152D0A24930086C749 /* MetricsSeriesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2373AE142D0A24930086C749 /* MetricsSeriesList.swift */; };
2373AE172D0A26620086C749 /* EnviornmentDefaultSeries.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2373AE162D0A26620086C749 /* EnviornmentDefaultSeries.swift */; };
2373AE172D0A26620086C749 /* EnvironmentDefaultSeries.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2373AE162D0A26620086C749 /* EnvironmentDefaultSeries.swift */; };
251926852C3BA97800249DF5 /* FavoriteNodeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251926842C3BA97800249DF5 /* FavoriteNodeButton.swift */; };
251926872C3BAE2200249DF5 /* NodeAlertsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251926862C3BAE2200249DF5 /* NodeAlertsButton.swift */; };
2519268A2C3BB1B200249DF5 /* ExchangePositionsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251926892C3BB1B200249DF5 /* ExchangePositionsButton.swift */; };
Expand Down Expand Up @@ -270,9 +273,13 @@
231B3F202D087A4C0069A07D /* MetricTableColumn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricTableColumn.swift; sourceTree = "<group>"; };
231B3F242D087C3C0069A07D /* EnvironmentDefaultColumns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentDefaultColumns.swift; sourceTree = "<group>"; };
231B3F262D0885240069A07D /* MetricsColumnDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricsColumnDetail.swift; sourceTree = "<group>"; };
235FFC382D1D8CF0003C95E5 /* TelemetryEntity+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TelemetryEntity+CoreDataClass.swift"; sourceTree = "<group>"; };
235FFC392D1D8CF0003C95E5 /* TelemetryEntity+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TelemetryEntity+CoreDataProperties.swift"; sourceTree = "<group>"; };
235FFC3C2D1D8DC8003C95E5 /* ManagedAttributePropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedAttributePropertyWrapper.swift; sourceTree = "<group>"; };
237013332D1A0D4F007DBE7F /* MeshtasticDataModelV 48.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 48.xcdatamodel"; sourceTree = "<group>"; };
2373AE122D0A216C0086C749 /* MetricsChartSeries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricsChartSeries.swift; sourceTree = "<group>"; };
2373AE142D0A24930086C749 /* MetricsSeriesList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricsSeriesList.swift; sourceTree = "<group>"; };
2373AE162D0A26620086C749 /* EnviornmentDefaultSeries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnviornmentDefaultSeries.swift; sourceTree = "<group>"; };
2373AE162D0A26620086C749 /* EnvironmentDefaultSeries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentDefaultSeries.swift; sourceTree = "<group>"; };
251926842C3BA97800249DF5 /* FavoriteNodeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteNodeButton.swift; sourceTree = "<group>"; };
251926862C3BAE2200249DF5 /* NodeAlertsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeAlertsButton.swift; sourceTree = "<group>"; };
251926892C3BB1B200249DF5 /* ExchangePositionsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangePositionsButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -584,12 +591,21 @@
isa = PBXGroup;
children = (
231B3F242D087C3C0069A07D /* EnvironmentDefaultColumns.swift */,
2373AE162D0A26620086C749 /* EnviornmentDefaultSeries.swift */,
2373AE162D0A26620086C749 /* EnvironmentDefaultSeries.swift */,
231B3F262D0885240069A07D /* MetricsColumnDetail.swift */,
);
path = "Metrics Columns";
sourceTree = "<group>";
};
235FFC372D1D8CCF003C95E5 /* Core Data */ = {
isa = PBXGroup;
children = (
235FFC382D1D8CF0003C95E5 /* TelemetryEntity+CoreDataClass.swift */,
235FFC392D1D8CF0003C95E5 /* TelemetryEntity+CoreDataProperties.swift */,
);
path = "Core Data";
sourceTree = "<group>";
};
251926882C3BAF2E00249DF5 /* Actions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -671,6 +687,7 @@
DD007BB12AA59B9A00F5FA12 /* CoreData */ = {
isa = PBXGroup;
children = (
235FFC3C2D1D8DC8003C95E5 /* ManagedAttributePropertyWrapper.swift */,
DD58C5F12919AD3C00D5BEFB /* ChannelEntityExtension.swift */,
6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */,
DD007BAD2AA4E91200F5FA12 /* MyInfoEntityExtension.swift */,
Expand Down Expand Up @@ -970,6 +987,7 @@
DDC2E18826CE24EE0042C5E4 /* Model */ = {
isa = PBXGroup;
children = (
235FFC372D1D8CCF003C95E5 /* Core Data */,
231B3F1E2D0879BC0069A07D /* Metrics Visualization */,
DD23A50E26FD1B4400D9B90C /* PeripheralModel.swift */,
);
Expand Down Expand Up @@ -1365,7 +1383,7 @@
DDB6ABD628AE742000384BA1 /* BluetoothConfig.swift in Sources */,
251926902C3CB44900249DF5 /* ClientHistoryButton.swift in Sources */,
DDD5BB102C285FB3007E03CA /* AppLogFilter.swift in Sources */,
2373AE172D0A26620086C749 /* EnviornmentDefaultSeries.swift in Sources */,
2373AE172D0A26620086C749 /* EnvironmentDefaultSeries.swift in Sources */,
DD4640202AFF10F4002A5ECB /* WaypointForm.swift in Sources */,
DD769E0328D18BF1001A3F05 /* DeviceMetricsLog.swift in Sources */,
DDAF8C5326EB1DF10058C060 /* BLEManager.swift in Sources */,
Expand All @@ -1388,6 +1406,8 @@
DDDB445429F8AD1600EE2349 /* Data.swift in Sources */,
DDDB26462AACC0B7003AFCB7 /* NodeInfoItem.swift in Sources */,
DD2AD8A8296D2DF9001FF0E7 /* MapViewSwiftUI.swift in Sources */,
235FFC3A2D1D8CF0003C95E5 /* TelemetryEntity+CoreDataProperties.swift in Sources */,
235FFC3B2D1D8CF0003C95E5 /* TelemetryEntity+CoreDataClass.swift in Sources */,
DDE5B4042B2279A700FCDD05 /* TraceRouteLog.swift in Sources */,
DD6193792863875F00E59241 /* SerialConfig.swift in Sources */,
DDDB263F2AABEE20003AFCB7 /* NodeList.swift in Sources */,
Expand Down Expand Up @@ -1438,6 +1458,7 @@
6DA39D8E2A92DC52007E311C /* MeshtasticAppDelegate.swift in Sources */,
D93068DB2B81C85E0066FBC8 /* PowerConfig.swift in Sources */,
D93068D32B8129510066FBC8 /* MessageContextMenuItems.swift in Sources */,
235FFC3D2D1D8DC9003C95E5 /* ManagedAttributePropertyWrapper.swift in Sources */,
DD8EBF43285058FA00426DCA /* DisplayConfig.swift in Sources */,
DD964FC42974767D007C176F /* MapViewFitExtension.swift in Sources */,
BCE2D3C72C7B0D0A008E6199 /* ShortcutsProvider.swift in Sources */,
Expand Down Expand Up @@ -1965,6 +1986,7 @@
DD3CC6BA28E366DF00FA9159 /* Meshtastic.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
237013332D1A0D4F007DBE7F /* MeshtasticDataModelV 48.xcdatamodel */,
DDDFE7402D0D4A070044463C /* MeshtasticDataModelV 47.xcdatamodel */,
DD0BE30C2CB785D8000BA445 /* MeshtasticDataModelV 46.xcdatamodel */,
DD6D5A342CA13BA600ED3032 /* MeshtasticDataModelV 45.xcdatamodel */,
Expand Down Expand Up @@ -2013,7 +2035,7 @@
DD5D0A9A2931AD6B00F7EA61 /* MeshtasticDataModelV2.xcdatamodel */,
DD3CC6BB28E366DF00FA9159 /* MeshtasticDataModel.xcdatamodel */,
);
currentVersion = DDDFE7402D0D4A070044463C /* MeshtasticDataModelV 47.xcdatamodel */;
currentVersion = 237013332D1A0D4F007DBE7F /* MeshtasticDataModelV 48.xcdatamodel */;
name = Meshtastic.xcdatamodeld;
path = Meshtastic/Meshtastic.xcdatamodeld;
sourceTree = "<group>";
Expand Down
38 changes: 27 additions & 11 deletions Meshtastic/Export/WriteCsvFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,48 @@ func telemetryToCsvFile(telemetry: [TelemetryEntity], metricsType: Int) -> Strin
csvString = "\("battery.level".localized), \("voltage".localized), \("channel.utilization".localized), \("airtime".localized), \("uptime".localized), \("timestamp".localized)"
for dm in telemetry where dm.metricsType == 0 {
csvString += "\n"
csvString += String(dm.batteryLevel)
csvString += dm.batteryLevel.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.voltage)
csvString += dm.voltage.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.channelUtilization)
csvString += dm.channelUtilization.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.airUtilTx)
csvString += dm.airUtilTx.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.uptimeSeconds)
csvString += dm.uptimeSeconds.map { String($0) } ?? ""
csvString += ", "
csvString += dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized
}
} else if metricsType == 1 {
// Create Environment Telemetry Header
csvString = "Temperature, Relative Humidity, Barometric Pressure, Indoor Air Quality, Gas Resistance, \("timestamp".localized)"
csvString = "Temperature, Relative Humidity, Barometric Pressure, Indoor Air Quality, Gas Resistance, Wind Direction, Wind Speed, Distance, Lux, White Lux, UV Lux, IR Lux, Radiation, \("timestamp".localized)"
for dm in telemetry where dm.metricsType == 1 {
csvString += "\n"
csvString += String(dm.temperature.localeTemperature())
csvString += dm.temperature.map { String($0.localeTemperature()) } ?? ""
csvString += ", "
csvString += String(dm.relativeHumidity)
csvString += dm.relativeHumidity.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.barometricPressure)
csvString += dm.barometricPressure.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.iaq)
csvString += dm.iaq.map { String($0) } ?? ""
csvString += ", "
csvString += String(dm.gasResistance)
csvString += dm.gasResistance.map { String($0) } ?? ""
csvString += ", "
csvString += dm.windDirection.map { String($0) } ?? ""
csvString += ", "
csvString += dm.windSpeed.map { String($0) } ?? ""
csvString += ", "
csvString += dm.distance.map { String($0) } ?? ""
csvString += ", "
csvString += dm.lux.map { String($0) } ?? ""
csvString += ", "
csvString += dm.whiteLux.map { String($0) } ?? ""
csvString += ", "
csvString += dm.uvLux.map { String($0) } ?? ""
csvString += ", "
csvString += dm.irLux.map { String($0) } ?? ""
csvString += ", "
csvString += dm.radiation.map { String($0) } ?? ""
csvString += ", "
csvString += dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// ManagedAttributePropertyWrapper.swift
// Meshtastic
//
// Created by Jake Bordens on 12/26/24.
//
import CoreData

@propertyWrapper
public struct ManagedAttribute<Value: Numeric> {
private let attributeName: String
private let converter: (NSNumber) -> Value?

public init(attributeName: String) {
self.attributeName = attributeName

// Define the converter closure based on the generic type Value
if Value.self == Float.self {
converter = { $0.floatValue as? Value }
} else if Value.self == Double.self {
converter = { $0.doubleValue as? Value }
} else if Value.self == Int.self {
converter = { $0.intValue as? Value }
} else if Value.self == Int8.self {
converter = { $0.int8Value as? Value }
} else if Value.self == Int16.self {
converter = { $0.int16Value as? Value }
} else if Value.self == Int32.self {
converter = { $0.int32Value as? Value }
} else if Value.self == Int64.self {
converter = { $0.int64Value as? Value }
} else {
fatalError("Unsupported type: \(Value.self)")
}
}

public var wrappedValue: Value? {
get { fatalError("Access via enclosing instance required.") }
set { fatalError("Access via enclosing instance required.") }
}

public static subscript<EnclosingSelf: NSManagedObject>(
_enclosingInstance observed: EnclosingSelf,
wrapped wrappedKeyPath: KeyPath<EnclosingSelf, Value?>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, ManagedAttribute<Value>>
) -> Value? {
get {
let wrapper = observed[keyPath: storageKeyPath]
let number = observed.primitiveValue(forKey: wrapper.attributeName) as? NSNumber
return number.flatMap { wrapper.converter($0) }
}
set {
let wrapper = observed[keyPath: storageKeyPath]
if let newValue = newValue {
observed.setPrimitiveValue(NSNumber(value: Double("\(newValue)")!), forKey: wrapper.attributeName)
} else {
observed.setPrimitiveValue(nil, forKey: wrapper.attributeName)
}
}
}
}
Loading
Loading