feat: Working on ignoring flagged measurements that are zero for optional values.
This commit is contained in:
@@ -6,15 +6,21 @@ public struct FlaggedEquipmentMeasurementView: View {
|
|||||||
@Environment(\.flaggedEquipmentMeasurementStyle) private var style
|
@Environment(\.flaggedEquipmentMeasurementStyle) private var style
|
||||||
|
|
||||||
let measurement: EquipmentMeasurement.FlaggedMeasurement
|
let measurement: EquipmentMeasurement.FlaggedMeasurement
|
||||||
|
let ignoreIfZero: [EquipmentMeasurement.FlaggedMeasurement.FieldKey]
|
||||||
|
|
||||||
public init(_ measurement: EquipmentMeasurement.FlaggedMeasurement) {
|
public init(
|
||||||
|
_ measurement: EquipmentMeasurement.FlaggedMeasurement,
|
||||||
|
ignoreIfZero: [EquipmentMeasurement.FlaggedMeasurement.FieldKey] = []
|
||||||
|
) {
|
||||||
self.measurement = measurement
|
self.measurement = measurement
|
||||||
|
self.ignoreIfZero = ignoreIfZero
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
style.makeBody(
|
style.makeBody(
|
||||||
configuration: FlaggedEquipmentMeasurementStyleConfiguration(
|
configuration: FlaggedEquipmentMeasurementStyleConfiguration(
|
||||||
measurement: measurement
|
measurement: measurement,
|
||||||
|
ignoreIfZero: ignoreIfZero
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -30,6 +36,7 @@ public protocol FlaggedEquipmentMeasurementStyle {
|
|||||||
|
|
||||||
public struct FlaggedEquipmentMeasurementStyleConfiguration {
|
public struct FlaggedEquipmentMeasurementStyleConfiguration {
|
||||||
public let measurement: EquipmentMeasurement.FlaggedMeasurement
|
public let measurement: EquipmentMeasurement.FlaggedMeasurement
|
||||||
|
public let ignoreIfZero: [EquipmentMeasurement.FlaggedMeasurement.FieldKey]
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct AnyFlaggedEquipmentMeasurementStyle: FlaggedEquipmentMeasurementStyle {
|
public struct AnyFlaggedEquipmentMeasurementStyle: FlaggedEquipmentMeasurementStyle {
|
||||||
@@ -54,12 +61,18 @@ public struct GridFlaggedEquipmentMeasurementStyle: FlaggedEquipmentMeasurementS
|
|||||||
|
|
||||||
public func makeBody(configuration: Configuration) -> some View {
|
public func makeBody(configuration: Configuration) -> some View {
|
||||||
Grid(alignment: .leading, verticalSpacing: 20) {
|
Grid(alignment: .leading, verticalSpacing: 20) {
|
||||||
ForEach(EquipmentMeasurement.FlaggedMeasurement.Key.allCases) { field in
|
ForEach(EquipmentMeasurement.FlaggedMeasurement.FieldKey.allCases) { field in
|
||||||
FlaggedView(
|
if configuration.measurement[keyPath: field.flaggedKeyPath].wrappedValue == 0,
|
||||||
field.title,
|
configuration.ignoreIfZero.contains(field)
|
||||||
flagged: configuration.measurement[keyPath: field.flaggedKeyPath]
|
{
|
||||||
)
|
EmptyView()
|
||||||
.flaggedViewStyle(.gridRow(fractionLength: field == .airflow ? 0 : 2))
|
} else {
|
||||||
|
FlaggedView(
|
||||||
|
field.title,
|
||||||
|
flagged: configuration.measurement[keyPath: field.flaggedKeyPath]
|
||||||
|
)
|
||||||
|
.flaggedViewStyle(.gridRow(fractionLength: field == .airflow ? 0 : 2))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,10 +105,10 @@ extension View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Key
|
// MARK: - FieldKey
|
||||||
fileprivate extension EquipmentMeasurement.FlaggedMeasurement {
|
extension EquipmentMeasurement.FlaggedMeasurement {
|
||||||
// NOTE: These need to be kept in display order.
|
// NOTE: These need to be kept in display order.
|
||||||
enum Key: Hashable, CaseIterable, Identifiable {
|
public enum FieldKey: Hashable, CaseIterable, Identifiable {
|
||||||
case returnPlenum
|
case returnPlenum
|
||||||
case filterDrop
|
case filterDrop
|
||||||
case coilDrop
|
case coilDrop
|
||||||
@@ -103,7 +116,7 @@ fileprivate extension EquipmentMeasurement.FlaggedMeasurement {
|
|||||||
case staticPressure
|
case staticPressure
|
||||||
case airflow
|
case airflow
|
||||||
|
|
||||||
var id: Self { self }
|
public var id: Self { self }
|
||||||
|
|
||||||
var title: String {
|
var title: String {
|
||||||
switch self {
|
switch self {
|
||||||
|
|||||||
@@ -390,6 +390,7 @@ public struct EquipmentMeasurementFormView: View {
|
|||||||
prompt: Text(title)
|
prompt: Text(title)
|
||||||
)
|
)
|
||||||
.numberPad()
|
.numberPad()
|
||||||
|
.onSubmit { send(.submitField) }
|
||||||
} else {
|
} else {
|
||||||
TextField(
|
TextField(
|
||||||
title,
|
title,
|
||||||
@@ -398,6 +399,7 @@ public struct EquipmentMeasurementFormView: View {
|
|||||||
prompt: Text(title)
|
prompt: Text(title)
|
||||||
)
|
)
|
||||||
.decimalPad()
|
.decimalPad()
|
||||||
|
.onSubmit { send(.submitField) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ public struct FlaggedMeasurementsList {
|
|||||||
self.estimatedMeasurements = estimatedMeasurements
|
self.estimatedMeasurements = estimatedMeasurements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignoreIfZeroFields: [EquipmentMeasurement.FlaggedMeasurement.FieldKey] {
|
||||||
|
guard let measurement = sharedSettings.equipmentMeasurement else { return [] }
|
||||||
|
guard measurement.equipmentType == .airHandler else { return [] }
|
||||||
|
return [.coilDrop, .filterDrop]
|
||||||
|
}
|
||||||
|
|
||||||
#warning("Move to shared settings.")
|
#warning("Move to shared settings.")
|
||||||
public struct FlaggedMeasurementContainer: Equatable, Identifiable {
|
public struct FlaggedMeasurementContainer: Equatable, Identifiable {
|
||||||
public let id: UUID
|
public let id: UUID
|
||||||
@@ -222,7 +228,10 @@ public struct FlaggedMeasurementListView: View {
|
|||||||
List {
|
List {
|
||||||
if let existingMeasurement = store.sharedSettings.flaggedEquipmentMeasurement {
|
if let existingMeasurement = store.sharedSettings.flaggedEquipmentMeasurement {
|
||||||
Section {
|
Section {
|
||||||
FlaggedEquipmentMeasurementView(existingMeasurement)
|
FlaggedEquipmentMeasurementView(
|
||||||
|
existingMeasurement,
|
||||||
|
ignoreIfZero: store.ignoreIfZeroFields
|
||||||
|
)
|
||||||
} header: {
|
} header: {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Existing Measurements")
|
Text("Existing Measurements")
|
||||||
@@ -232,7 +241,8 @@ public struct FlaggedMeasurementListView: View {
|
|||||||
ForEach(store.estimatedMeasurements) { measurement in
|
ForEach(store.estimatedMeasurements) { measurement in
|
||||||
Section {
|
Section {
|
||||||
FlaggedEquipmentMeasurementView(
|
FlaggedEquipmentMeasurementView(
|
||||||
measurement.flaggedMeasurement
|
measurement.flaggedMeasurement,
|
||||||
|
ignoreIfZero: store.ignoreIfZeroFields
|
||||||
)
|
)
|
||||||
} header: {
|
} header: {
|
||||||
HStack {
|
HStack {
|
||||||
|
|||||||
@@ -177,11 +177,11 @@ public enum EquipmentMeasurement: Equatable {
|
|||||||
value: measurement.externalStaticPressure,
|
value: measurement.externalStaticPressure,
|
||||||
ratedPressures: ratedPressures
|
ratedPressures: ratedPressures
|
||||||
),
|
),
|
||||||
filterPressureDrop: .init(
|
filterPressureDrop: calculateFilterPressureDrop(
|
||||||
value: measurement.$postFilterPressure.positiveValue - measurement.$returnPlenumPressure.positiveValue,
|
returnPlenumPressure: measurement.$returnPlenumPressure,
|
||||||
budget: budgets.filterBudget,
|
postFilterPressure: measurement.$postFilterPressure,
|
||||||
ratedPressures: ratedPressures,
|
filterBudget: budgets.filterBudget,
|
||||||
ignoreMinimum: true
|
ratedPressures: ratedPressures
|
||||||
),
|
),
|
||||||
returnPlenumPressure: .init(
|
returnPlenumPressure: .init(
|
||||||
value: measurement.$returnPlenumPressure.positiveValue,
|
value: measurement.$returnPlenumPressure.positiveValue,
|
||||||
@@ -213,11 +213,11 @@ public enum EquipmentMeasurement: Equatable {
|
|||||||
value: measurement.externalStaticPressure,
|
value: measurement.externalStaticPressure,
|
||||||
ratedPressures: ratedPressures
|
ratedPressures: ratedPressures
|
||||||
),
|
),
|
||||||
filterPressureDrop: .init(
|
filterPressureDrop: calculateFilterPressureDrop(
|
||||||
value: measurement.$postFilterPressure.positiveValue - measurement.$returnPlenumPressure.positiveValue,
|
returnPlenumPressure: measurement.$returnPlenumPressure,
|
||||||
budget: budgets.filterBudget,
|
postFilterPressure: measurement.$postFilterPressure,
|
||||||
ratedPressures: ratedPressures,
|
filterBudget: budgets.filterBudget,
|
||||||
ignoreMinimum: true
|
ratedPressures: ratedPressures
|
||||||
),
|
),
|
||||||
returnPlenumPressure: .init(
|
returnPlenumPressure: .init(
|
||||||
value: measurement.$returnPlenumPressure.positiveValue,
|
value: measurement.$returnPlenumPressure.positiveValue,
|
||||||
@@ -328,6 +328,23 @@ fileprivate extension Flagged {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate func calculateFilterPressureDrop(
|
||||||
|
returnPlenumPressure: Positive<Double>,
|
||||||
|
postFilterPressure: Positive<Double>,
|
||||||
|
filterBudget: Percentage,
|
||||||
|
ratedPressures: RatedStaticPressures
|
||||||
|
) -> Flagged {
|
||||||
|
guard postFilterPressure > 0 else {
|
||||||
|
return .init(wrappedValue: 0, .result(.good()))
|
||||||
|
}
|
||||||
|
return .init(
|
||||||
|
value: postFilterPressure.positiveValue - returnPlenumPressure.positiveValue,
|
||||||
|
budget: filterBudget,
|
||||||
|
ratedPressures: ratedPressures,
|
||||||
|
ignoreMinimum: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func checkExternalStaticPressure(
|
fileprivate func checkExternalStaticPressure(
|
||||||
value: Positive<Double>,
|
value: Positive<Double>,
|
||||||
ratedPressures: RatedStaticPressures
|
ratedPressures: RatedStaticPressures
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ public struct DefaultNextButtonStyle<ButtonStyle: PrimitiveButtonStyle, Label: L
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DefaultNextButtonStyle where ButtonStyle == BorderedProminentButtonStyle, Label == ReverseLabelStyle {
|
extension DefaultNextButtonStyle where ButtonStyle == BorderedProminentButtonStyle, Label == NextLabelStyle {
|
||||||
init() {
|
init() {
|
||||||
self.init(buttonStyle: .borderedProminent, labelStyle: .reverse())
|
self.init(buttonStyle: .borderedProminent, labelStyle: .nextLabel())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public struct ToolbarNextButtonStyle: PrimitiveButtonStyle {
|
|||||||
configuration.label
|
configuration.label
|
||||||
.foregroundStyle(Color.accentColor)
|
.foregroundStyle(Color.accentColor)
|
||||||
}
|
}
|
||||||
.labelStyle(ReverseLabelStyle())
|
.labelStyle(NextLabelStyle())
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ private struct InfoButtonStyleKey: EnvironmentKey {
|
|||||||
|
|
||||||
private struct NextButtonStyleKey: EnvironmentKey {
|
private struct NextButtonStyleKey: EnvironmentKey {
|
||||||
static var defaultValue = AnyPrimitiveButtonStyle<NextButtonType>(
|
static var defaultValue = AnyPrimitiveButtonStyle<NextButtonType>(
|
||||||
DefaultNextButtonStyle<BorderedProminentButtonStyle, ReverseLabelStyle>()
|
DefaultNextButtonStyle<BorderedProminentButtonStyle, NextLabelStyle>()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
/// A label style that puts the title first and icon second.
|
/// A label style that puts the title first and icon second.
|
||||||
public struct ReverseLabelStyle: LabelStyle {
|
public struct NextLabelStyle: LabelStyle {
|
||||||
let spacing: CGFloat
|
let spacing: CGFloat
|
||||||
|
|
||||||
public init(spacing: CGFloat = 3) {
|
public init(spacing: CGFloat = 3) {
|
||||||
@@ -12,13 +12,14 @@ public struct ReverseLabelStyle: LabelStyle {
|
|||||||
HStack(spacing: spacing) {
|
HStack(spacing: spacing) {
|
||||||
configuration.title
|
configuration.title
|
||||||
configuration.icon
|
configuration.icon
|
||||||
|
.fontWeight(.semibold)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LabelStyle where Self == ReverseLabelStyle {
|
extension LabelStyle where Self == NextLabelStyle {
|
||||||
|
|
||||||
public static func reverse(spacing: CGFloat = 3) -> Self {
|
public static func nextLabel(spacing: CGFloat = 3) -> Self {
|
||||||
.init(spacing: spacing)
|
.init(spacing: spacing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user