Meshtastic-Apple/Meshtastic/Enums/TelemetryEnums.swift
Blake McAnally 4d547e48db This change fixes several lint errors throughout the project, and moves the SwiftLint build phase to before compilation.
After this change, a developer can now clone the project and run without the build failing due to lint errors! 😃

* I ran `swiftlint --fix` to resolve many auto-correctable issues (mostly whitespace)
* Excluded the `Meshtastic/Protobufs` directory from lint, since that code is automatically generated.
* Converted some single letter method parameters to lowercase.
* Converted several instances `force_cast` to instead use `guard` or `if let` to unwrap optional values. During this change, some of the SwiftUI views became "too complex to be solved in a reasonable time", so I broke up the views into distinct sub-expressions.

I was able to build and run the app on an iOS simulator.
2024-05-31 21:48:50 -05:00

178 lines
3.3 KiB
Swift

//
// TelemetryEnums.swift
// Meshtastic
//
// Created by Garth Vander Houwen on 4/9/24.
//
import Foundation
import SwiftUI
enum Aqi: Int, CaseIterable, Identifiable {
case good = 0
case moderate = 1
case sensitive = 2
case unhealthy = 3
case veryUnhealthy = 4
case hazardous = 5
var id: Int { self.rawValue }
var description: String {
switch self {
case .good:
return "Good"
case .moderate:
return "Moderate"
case .sensitive:
return "Unhealthy for Sensitive Groups"
case .unhealthy:
return "Unhealthy"
case .veryUnhealthy:
return "Very Unhealthy"
case .hazardous:
return "Hazardous"
}
}
var color: Color {
switch self {
case .good:
return .green
case .moderate:
return .yellow
case .sensitive:
return .orange
case .unhealthy:
return .red
case .veryUnhealthy:
return .purple
case .hazardous:
return .magenta
}
}
var range: Range<Int> {
switch self {
case .good:
return Range(0...50)
case .moderate:
return Range(51...100)
case .sensitive:
return Range(101...150)
case .unhealthy:
return Range(151...200)
case .veryUnhealthy:
return Range(201...300)
case .hazardous:
return Range(301...500)
}
}
static func getAqi(for value: Int) -> Aqi {
let aqi: Aqi
switch value {
case 0...50:
aqi = .good
case 51...100:
aqi = .moderate
case 101...150:
aqi = .sensitive
case 151...200:
aqi = .unhealthy
case 201...300:
aqi = .veryUnhealthy
case 301...500:
aqi = .hazardous
default:
fatalError("Invalid int value")
}
return aqi
}
}
enum Iaq: Int, CaseIterable, Identifiable {
case excellent = 0
case good = 1
case lightlyPolluted = 2
case moderatelyPolluted = 3
case heavilyPolluted = 4
case severelyPolluted = 5
case extremelyPolluted = 6
var id: Int { self.rawValue }
var description: String {
switch self {
case .excellent:
return "Excellent"
case .good:
return "Good"
case .lightlyPolluted:
return "Lightly Polluted"
case .moderatelyPolluted:
return "Moderately Polluted"
case .heavilyPolluted:
return "Heavily Polluted"
case .severelyPolluted:
return "Severely Polluted"
case .extremelyPolluted:
return "Extremely Polluted"
}
}
var color: Color {
switch self {
case .excellent:
return .green
case .good:
return .mint
case .lightlyPolluted:
return .yellow
case .moderatelyPolluted:
return .orange
case .heavilyPolluted:
return .red
case .severelyPolluted:
return .magenta
case .extremelyPolluted:
return .brown
}
}
var range: Range<Int> {
switch self {
case .excellent:
return Range(0...50)
case .good:
return Range(51...100)
case .lightlyPolluted:
return Range(101...150)
case .moderatelyPolluted:
return Range(151...200)
case .heavilyPolluted:
return Range(201...250)
case .severelyPolluted:
return Range(251...350)
case .extremelyPolluted:
return Range(351...500)
}
}
static func getIaq(for value: Int) -> Iaq {
let iaq: Iaq
switch value {
case 0...50:
iaq = .excellent
case 51...100:
iaq = .good
case 101...150:
iaq = .lightlyPolluted
case 151...200:
iaq = .moderatelyPolluted
case 201...250:
iaq = .heavilyPolluted
case 251...350:
iaq = .severelyPolluted
case 351...:
iaq = .extremelyPolluted
default:
fatalError("Invalid int value")
}
return iaq
}
}