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
|
||||
|
||||
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.ignoreIfZero = ignoreIfZero
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
style.makeBody(
|
||||
configuration: FlaggedEquipmentMeasurementStyleConfiguration(
|
||||
measurement: measurement
|
||||
measurement: measurement,
|
||||
ignoreIfZero: ignoreIfZero
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -30,6 +36,7 @@ public protocol FlaggedEquipmentMeasurementStyle {
|
||||
|
||||
public struct FlaggedEquipmentMeasurementStyleConfiguration {
|
||||
public let measurement: EquipmentMeasurement.FlaggedMeasurement
|
||||
public let ignoreIfZero: [EquipmentMeasurement.FlaggedMeasurement.FieldKey]
|
||||
}
|
||||
|
||||
public struct AnyFlaggedEquipmentMeasurementStyle: FlaggedEquipmentMeasurementStyle {
|
||||
@@ -54,12 +61,18 @@ public struct GridFlaggedEquipmentMeasurementStyle: FlaggedEquipmentMeasurementS
|
||||
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
Grid(alignment: .leading, verticalSpacing: 20) {
|
||||
ForEach(EquipmentMeasurement.FlaggedMeasurement.Key.allCases) { field in
|
||||
FlaggedView(
|
||||
field.title,
|
||||
flagged: configuration.measurement[keyPath: field.flaggedKeyPath]
|
||||
)
|
||||
.flaggedViewStyle(.gridRow(fractionLength: field == .airflow ? 0 : 2))
|
||||
ForEach(EquipmentMeasurement.FlaggedMeasurement.FieldKey.allCases) { field in
|
||||
if configuration.measurement[keyPath: field.flaggedKeyPath].wrappedValue == 0,
|
||||
configuration.ignoreIfZero.contains(field)
|
||||
{
|
||||
EmptyView()
|
||||
} 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
|
||||
fileprivate extension EquipmentMeasurement.FlaggedMeasurement {
|
||||
// MARK: - FieldKey
|
||||
extension EquipmentMeasurement.FlaggedMeasurement {
|
||||
// NOTE: These need to be kept in display order.
|
||||
enum Key: Hashable, CaseIterable, Identifiable {
|
||||
public enum FieldKey: Hashable, CaseIterable, Identifiable {
|
||||
case returnPlenum
|
||||
case filterDrop
|
||||
case coilDrop
|
||||
@@ -103,7 +116,7 @@ fileprivate extension EquipmentMeasurement.FlaggedMeasurement {
|
||||
case staticPressure
|
||||
case airflow
|
||||
|
||||
var id: Self { self }
|
||||
public var id: Self { self }
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
|
||||
@@ -390,6 +390,7 @@ public struct EquipmentMeasurementFormView: View {
|
||||
prompt: Text(title)
|
||||
)
|
||||
.numberPad()
|
||||
.onSubmit { send(.submitField) }
|
||||
} else {
|
||||
TextField(
|
||||
title,
|
||||
@@ -398,6 +399,7 @@ public struct EquipmentMeasurementFormView: View {
|
||||
prompt: Text(title)
|
||||
)
|
||||
.decimalPad()
|
||||
.onSubmit { send(.submitField) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,13 @@ public struct FlaggedMeasurementsList {
|
||||
self._sharedSettings = sharedSettings
|
||||
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.")
|
||||
public struct FlaggedMeasurementContainer: Equatable, Identifiable {
|
||||
public let id: UUID
|
||||
@@ -222,7 +228,10 @@ public struct FlaggedMeasurementListView: View {
|
||||
List {
|
||||
if let existingMeasurement = store.sharedSettings.flaggedEquipmentMeasurement {
|
||||
Section {
|
||||
FlaggedEquipmentMeasurementView(existingMeasurement)
|
||||
FlaggedEquipmentMeasurementView(
|
||||
existingMeasurement,
|
||||
ignoreIfZero: store.ignoreIfZeroFields
|
||||
)
|
||||
} header: {
|
||||
HStack {
|
||||
Text("Existing Measurements")
|
||||
@@ -232,7 +241,8 @@ public struct FlaggedMeasurementListView: View {
|
||||
ForEach(store.estimatedMeasurements) { measurement in
|
||||
Section {
|
||||
FlaggedEquipmentMeasurementView(
|
||||
measurement.flaggedMeasurement
|
||||
measurement.flaggedMeasurement,
|
||||
ignoreIfZero: store.ignoreIfZeroFields
|
||||
)
|
||||
} header: {
|
||||
HStack {
|
||||
|
||||
@@ -177,11 +177,11 @@ public enum EquipmentMeasurement: Equatable {
|
||||
value: measurement.externalStaticPressure,
|
||||
ratedPressures: ratedPressures
|
||||
),
|
||||
filterPressureDrop: .init(
|
||||
value: measurement.$postFilterPressure.positiveValue - measurement.$returnPlenumPressure.positiveValue,
|
||||
budget: budgets.filterBudget,
|
||||
ratedPressures: ratedPressures,
|
||||
ignoreMinimum: true
|
||||
filterPressureDrop: calculateFilterPressureDrop(
|
||||
returnPlenumPressure: measurement.$returnPlenumPressure,
|
||||
postFilterPressure: measurement.$postFilterPressure,
|
||||
filterBudget: budgets.filterBudget,
|
||||
ratedPressures: ratedPressures
|
||||
),
|
||||
returnPlenumPressure: .init(
|
||||
value: measurement.$returnPlenumPressure.positiveValue,
|
||||
@@ -213,11 +213,11 @@ public enum EquipmentMeasurement: Equatable {
|
||||
value: measurement.externalStaticPressure,
|
||||
ratedPressures: ratedPressures
|
||||
),
|
||||
filterPressureDrop: .init(
|
||||
value: measurement.$postFilterPressure.positiveValue - measurement.$returnPlenumPressure.positiveValue,
|
||||
budget: budgets.filterBudget,
|
||||
ratedPressures: ratedPressures,
|
||||
ignoreMinimum: true
|
||||
filterPressureDrop: calculateFilterPressureDrop(
|
||||
returnPlenumPressure: measurement.$returnPlenumPressure,
|
||||
postFilterPressure: measurement.$postFilterPressure,
|
||||
filterBudget: budgets.filterBudget,
|
||||
ratedPressures: ratedPressures
|
||||
),
|
||||
returnPlenumPressure: .init(
|
||||
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(
|
||||
value: Positive<Double>,
|
||||
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() {
|
||||
self.init(buttonStyle: .borderedProminent, labelStyle: .reverse())
|
||||
self.init(buttonStyle: .borderedProminent, labelStyle: .nextLabel())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public struct ToolbarNextButtonStyle: PrimitiveButtonStyle {
|
||||
configuration.label
|
||||
.foregroundStyle(Color.accentColor)
|
||||
}
|
||||
.labelStyle(ReverseLabelStyle())
|
||||
.labelStyle(NextLabelStyle())
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ private struct InfoButtonStyleKey: EnvironmentKey {
|
||||
|
||||
private struct NextButtonStyleKey: EnvironmentKey {
|
||||
static var defaultValue = AnyPrimitiveButtonStyle<NextButtonType>(
|
||||
DefaultNextButtonStyle<BorderedProminentButtonStyle, ReverseLabelStyle>()
|
||||
DefaultNextButtonStyle<BorderedProminentButtonStyle, NextLabelStyle>()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import SwiftUI
|
||||
|
||||
/// A label style that puts the title first and icon second.
|
||||
public struct ReverseLabelStyle: LabelStyle {
|
||||
public struct NextLabelStyle: LabelStyle {
|
||||
let spacing: CGFloat
|
||||
|
||||
public init(spacing: CGFloat = 3) {
|
||||
@@ -12,13 +12,14 @@ public struct ReverseLabelStyle: LabelStyle {
|
||||
HStack(spacing: spacing) {
|
||||
configuration.title
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user