feat: Adding improvements to pressure estimations feature.

This commit is contained in:
2024-06-12 16:51:33 -04:00
parent 9a145b3290
commit 81494c1e9a
3 changed files with 44 additions and 16 deletions

View File

@@ -51,7 +51,7 @@ public struct FlaggedMeasurementsList: Sendable {
@CasePathable
public enum ReceiveAction: Sendable {
case existingFlaggedMeasurement(EquipmentMeasurement.FlaggedMeasurement)
case estimatedFlaggedMeasurement(name: String, measurement: EquipmentMeasurement.FlaggedMeasurement)
case estimatedFlaggedMeasurement(SharedPressureEstimationState.FlaggedEstimationContainer)
}
@CasePathable
@@ -81,14 +81,8 @@ public struct FlaggedMeasurementsList: Sendable {
state.sharedSettings.flaggedEquipmentMeasurement = measurement
return .none
case let .estimatedFlaggedMeasurement(name: name, measurement: measurement):
state.flaggedEstimations.append(
.init(
id: uuid(),
name: name,
flaggedMeasurement: measurement
)
)
case let .estimatedFlaggedMeasurement(container):
state.flaggedEstimations[id: container.id] = container
return .none
}
}
@@ -203,7 +197,11 @@ public struct FlaggedMeasurementsList: Sendable {
tons: form.coolingCapacity
)
return .estimatedFlaggedMeasurement(name: form.name, measurement: flaggedMeasurement)
return .estimatedFlaggedMeasurement(.init(
id: form.id ?? uuid(),
estimationState: .init(state: form),
flaggedMeasurement: flaggedMeasurement
))
}
}
@@ -241,7 +239,7 @@ public struct FlaggedMeasurementListView: View {
)
} header: {
HStack {
Text(measurement.name)
Text(measurement.displayName)
Spacer()
Menu {
EditButton { send(.editButtonTapped(id: measurement.id)) }
@@ -301,7 +299,10 @@ private let flaggedMeasurements = IdentifiedArrayOf<SharedPressureEstimationStat
uniqueElements: [
.init(
id: UUID(0),
name: "Existing",
estimationState: .init(
cfm: .cfmPerTon(400, .three),
filterPressureDrop: 0.1
),
flaggedMeasurement: .init(
budgets: budgets,
measurement: .mock(type: .airHandler),

View File

@@ -37,21 +37,31 @@ public struct SharedPressureEstimationState: Equatable, Sendable {
}
#warning("Needs to hold onto estimation state, so it can be editable")
@dynamicMemberLookup
public struct FlaggedEstimationContainer: Equatable, Identifiable, Sendable {
public let id: UUID
public var estimationState: EstimationState
public var flaggedMeasurement: EquipmentMeasurement.FlaggedMeasurement
public var name: String
public init(
id: UUID,
name: String,
estimationState: EstimationState,
flaggedMeasurement: EquipmentMeasurement.FlaggedMeasurement
) {
self.id = id
self.name = name
self.estimationState = estimationState
self.flaggedMeasurement = flaggedMeasurement
}
public subscript<T>(dynamicMember keyPath: WritableKeyPath<EstimationState, T>) -> T {
get { estimationState[keyPath: keyPath] }
set { estimationState[keyPath: keyPath] = newValue }
}
public subscript<T>(dynamicMember keyPath: KeyPath<EstimationState, T>) -> T {
get { estimationState[keyPath: keyPath] }
}
public struct EstimationState: Equatable, Sendable {
public var cfm: CFMContainer
public var filterPressureDrop: Double?
@@ -67,6 +77,14 @@ public struct SharedPressureEstimationState: Equatable, Sendable {
self.name = name
}
internal init(state: EstimationForm.State) {
self.init(
cfm: .init(state: state),
filterPressureDrop: state.filterPressureDrop,
name: state.name.isEmpty ? nil : state.name
)
}
var displayName: String {
guard let name else {
return "@\(Int(cfm.airflow)) CFM"
@@ -78,6 +96,15 @@ public struct SharedPressureEstimationState: Equatable, Sendable {
case cfm(Int)
case cfmPerTon(Int, EquipmentMetadata.CoolingCapacity)
init(state: EstimationForm.State) {
switch state.airflowSelection {
case .cfmPerTon:
self = .cfmPerTon(state.cfmTextField ?? 0, state.coolingCapacity)
case .cfm:
self = .cfm(state.cfmTextField ?? 0)
}
}
var airflow: Double {
switch self {
case let .cfm(cfm):