feat: Adding improvements to pressure estimations feature.
This commit is contained in:
@@ -35,7 +35,7 @@ public struct EstimationForm {
|
|||||||
self.coolingCapacity = coolingCapacity
|
self.coolingCapacity = coolingCapacity
|
||||||
self.name = name
|
self.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
public var airflow: Double {
|
public var airflow: Double {
|
||||||
let cfmTextField = Double(self.cfmTextField ?? 0)
|
let cfmTextField = Double(self.cfmTextField ?? 0)
|
||||||
switch airflowSelection {
|
switch airflowSelection {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public struct FlaggedMeasurementsList: Sendable {
|
|||||||
@CasePathable
|
@CasePathable
|
||||||
public enum ReceiveAction: Sendable {
|
public enum ReceiveAction: Sendable {
|
||||||
case existingFlaggedMeasurement(EquipmentMeasurement.FlaggedMeasurement)
|
case existingFlaggedMeasurement(EquipmentMeasurement.FlaggedMeasurement)
|
||||||
case estimatedFlaggedMeasurement(name: String, measurement: EquipmentMeasurement.FlaggedMeasurement)
|
case estimatedFlaggedMeasurement(SharedPressureEstimationState.FlaggedEstimationContainer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CasePathable
|
@CasePathable
|
||||||
@@ -81,14 +81,8 @@ public struct FlaggedMeasurementsList: Sendable {
|
|||||||
state.sharedSettings.flaggedEquipmentMeasurement = measurement
|
state.sharedSettings.flaggedEquipmentMeasurement = measurement
|
||||||
return .none
|
return .none
|
||||||
|
|
||||||
case let .estimatedFlaggedMeasurement(name: name, measurement: measurement):
|
case let .estimatedFlaggedMeasurement(container):
|
||||||
state.flaggedEstimations.append(
|
state.flaggedEstimations[id: container.id] = container
|
||||||
.init(
|
|
||||||
id: uuid(),
|
|
||||||
name: name,
|
|
||||||
flaggedMeasurement: measurement
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +197,11 @@ public struct FlaggedMeasurementsList: Sendable {
|
|||||||
tons: form.coolingCapacity
|
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: {
|
} header: {
|
||||||
HStack {
|
HStack {
|
||||||
Text(measurement.name)
|
Text(measurement.displayName)
|
||||||
Spacer()
|
Spacer()
|
||||||
Menu {
|
Menu {
|
||||||
EditButton { send(.editButtonTapped(id: measurement.id)) }
|
EditButton { send(.editButtonTapped(id: measurement.id)) }
|
||||||
@@ -301,7 +299,10 @@ private let flaggedMeasurements = IdentifiedArrayOf<SharedPressureEstimationStat
|
|||||||
uniqueElements: [
|
uniqueElements: [
|
||||||
.init(
|
.init(
|
||||||
id: UUID(0),
|
id: UUID(0),
|
||||||
name: "Existing",
|
estimationState: .init(
|
||||||
|
cfm: .cfmPerTon(400, .three),
|
||||||
|
filterPressureDrop: 0.1
|
||||||
|
),
|
||||||
flaggedMeasurement: .init(
|
flaggedMeasurement: .init(
|
||||||
budgets: budgets,
|
budgets: budgets,
|
||||||
measurement: .mock(type: .airHandler),
|
measurement: .mock(type: .airHandler),
|
||||||
|
|||||||
@@ -37,21 +37,31 @@ public struct SharedPressureEstimationState: Equatable, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#warning("Needs to hold onto estimation state, so it can be editable")
|
#warning("Needs to hold onto estimation state, so it can be editable")
|
||||||
|
@dynamicMemberLookup
|
||||||
public struct FlaggedEstimationContainer: Equatable, Identifiable, Sendable {
|
public struct FlaggedEstimationContainer: Equatable, Identifiable, Sendable {
|
||||||
public let id: UUID
|
public let id: UUID
|
||||||
|
public var estimationState: EstimationState
|
||||||
public var flaggedMeasurement: EquipmentMeasurement.FlaggedMeasurement
|
public var flaggedMeasurement: EquipmentMeasurement.FlaggedMeasurement
|
||||||
public var name: String
|
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
id: UUID,
|
id: UUID,
|
||||||
name: String,
|
estimationState: EstimationState,
|
||||||
flaggedMeasurement: EquipmentMeasurement.FlaggedMeasurement
|
flaggedMeasurement: EquipmentMeasurement.FlaggedMeasurement
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.estimationState = estimationState
|
||||||
self.flaggedMeasurement = flaggedMeasurement
|
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 struct EstimationState: Equatable, Sendable {
|
||||||
public var cfm: CFMContainer
|
public var cfm: CFMContainer
|
||||||
public var filterPressureDrop: Double?
|
public var filterPressureDrop: Double?
|
||||||
@@ -67,6 +77,14 @@ public struct SharedPressureEstimationState: Equatable, Sendable {
|
|||||||
self.name = name
|
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 {
|
var displayName: String {
|
||||||
guard let name else {
|
guard let name else {
|
||||||
return "@\(Int(cfm.airflow)) CFM"
|
return "@\(Int(cfm.airflow)) CFM"
|
||||||
@@ -78,6 +96,15 @@ public struct SharedPressureEstimationState: Equatable, Sendable {
|
|||||||
case cfm(Int)
|
case cfm(Int)
|
||||||
case cfmPerTon(Int, EquipmentMetadata.CoolingCapacity)
|
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 {
|
var airflow: Double {
|
||||||
switch self {
|
switch self {
|
||||||
case let .cfm(cfm):
|
case let .cfm(cfm):
|
||||||
|
|||||||
Reference in New Issue
Block a user