feat: Fixes errors with estimating pressures that include a filter pressure drop.
This commit is contained in:
@@ -216,49 +216,6 @@ public struct FlaggedMeasurementsList: Sendable {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning("This is making it hard to test, perhaps don't return an effect here.")
|
|
||||||
private func handleEstimationForm(form: EstimationForm.State, state: State) -> Effect<Action> {
|
|
||||||
guard let equipmentMeasurement = state.sharedSettings.equipmentMeasurement,
|
|
||||||
let budgets = state.sharedSettings.budgets
|
|
||||||
else {
|
|
||||||
return .fail(
|
|
||||||
"""
|
|
||||||
Received estimation form done button tapped action, original
|
|
||||||
equipment measurement or budgets are not set on the shared state.
|
|
||||||
|
|
||||||
This is considered an application logic error.
|
|
||||||
""",
|
|
||||||
logger: logger
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let estimationState = ensureHasChanges(
|
|
||||||
formState: form,
|
|
||||||
flaggedEstimations: state.sharedSettings.flaggedEstimations
|
|
||||||
) else {
|
|
||||||
logger.debug("No changes found, not generating a new flagged estimation measurement.")
|
|
||||||
return .none
|
|
||||||
}
|
|
||||||
|
|
||||||
return .receive(action: \.receive) { [sharedSettings = state.sharedSettings] in
|
|
||||||
|
|
||||||
let flaggedMeasurement = try await flaggedMeasurement(
|
|
||||||
airflow: estimationState.cfm.airflow,
|
|
||||||
budgets: budgets,
|
|
||||||
equipmentMeasurement: equipmentMeasurement,
|
|
||||||
filterPressureDrop: parseFilterPressureDrop(formState: form, sharedSettings: sharedSettings),
|
|
||||||
ratedStaticPresures: sharedSettings.ratedStaticPressures,
|
|
||||||
tons: form.coolingCapacity
|
|
||||||
)
|
|
||||||
|
|
||||||
return .estimatedFlaggedMeasurement(.init(
|
|
||||||
id: form.id ?? uuid(),
|
|
||||||
estimationState: estimationState,
|
|
||||||
flaggedMeasurement: flaggedMeasurement
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureHasChanges(
|
func ensureHasChanges(
|
||||||
formState: EstimationForm.State,
|
formState: EstimationForm.State,
|
||||||
flaggedEstimations: IdentifiedArrayOf<SharedPressureEstimationState.FlaggedEstimationContainer>
|
flaggedEstimations: IdentifiedArrayOf<SharedPressureEstimationState.FlaggedEstimationContainer>
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ struct FlaggedMeasurementListStateTests {
|
|||||||
name: "Test"
|
name: "Test"
|
||||||
))
|
))
|
||||||
|
|
||||||
#expect(result?.flaggedMeasurement == .init(
|
#expect(result?.flaggedMeasurement == .init(
|
||||||
budgets: .init(equipmentType: .airHandler, fanType: .constantSpeed),
|
budgets: .init(equipmentType: .airHandler, fanType: .constantSpeed),
|
||||||
measurement: measurement,
|
measurement: measurement,
|
||||||
ratedPressures: .init(),
|
ratedPressures: .init(),
|
||||||
@@ -176,7 +176,6 @@ final class FlaggedMeasurementListReducerTests: XCTestCase {
|
|||||||
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.name, "Test"))))))
|
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.name, "Test"))))))
|
||||||
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.filterPressureDrop, 0.1))))))
|
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.filterPressureDrop, 0.1))))))
|
||||||
|
|
||||||
// store.exhaustivity = .on
|
|
||||||
let pressureResult = try await estimatedPressuresClient.estimatedPressure(
|
let pressureResult = try await estimatedPressuresClient.estimatedPressure(
|
||||||
equipmentMeasurement: .mock(type: .airHandler),
|
equipmentMeasurement: .mock(type: .airHandler),
|
||||||
airflow: 1050,
|
airflow: 1050,
|
||||||
@@ -189,25 +188,23 @@ final class FlaggedMeasurementListReducerTests: XCTestCase {
|
|||||||
tons: .three
|
tons: .three
|
||||||
)
|
)
|
||||||
|
|
||||||
store.exhaustivity = .off(showSkippedAssertions: true)
|
store.exhaustivity = .on
|
||||||
// store.exhaustivity = .on
|
|
||||||
|
|
||||||
await store.send(.view(.destination(.doneButtonTapped))) {
|
await store.send(.view(.destination(.doneButtonTapped))) {
|
||||||
$0.destination = nil
|
$0.destination = nil
|
||||||
}
|
}
|
||||||
// await store.receive(\.receive.failure, timeout: 10)
|
await store.receive(\.receive.success.estimatedFlaggedMeasurement, timeout: 10) {
|
||||||
// await store.receive(\.receive.success.estimatedFlaggedMeasurement, timeout: 10) {
|
$0.sharedSettings.flaggedEstimations[id: UUID(0)] = .init(
|
||||||
// $0.sharedSettings.flaggedEstimations[id: UUID(0)] = .init(
|
id: UUID(0),
|
||||||
// id: UUID(0),
|
estimationState: .init(
|
||||||
// estimationState: .init(
|
cfm: .cfmPerTon(350, .three),
|
||||||
// cfm: .cfmPerTon(350, .three),
|
filterPressureDrop: 0.1,
|
||||||
// filterPressureDrop: 0.1,
|
name: "Test"
|
||||||
// name: "Test"
|
),
|
||||||
// ),
|
flaggedMeasurement: flaggedResult
|
||||||
// flaggedMeasurement: flaggedResult
|
)
|
||||||
// )
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
await store.finish()
|
await store.finish()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -245,56 +242,6 @@ final class FlaggedMeasurementListReducerTests: XCTestCase {
|
|||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
func testPressureEstimation() async throws {
|
|
||||||
_ = try await pressureEstimation(
|
|
||||||
equipmentType: .airHandler,
|
|
||||||
filterPressureDrop: 0.1
|
|
||||||
)
|
|
||||||
// XCTFail()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private func pressureEstimation(
|
|
||||||
equipmentType: EquipmentMeasurement.EquipmentType,
|
|
||||||
filterPressureDrop: Double?
|
|
||||||
) async throws -> EquipmentMeasurement {
|
|
||||||
try await withDependencies {
|
|
||||||
$0.estimatedPressuresClient = .liveValue
|
|
||||||
} operation: {
|
|
||||||
@Dependency(\.estimatedPressuresClient) var client
|
|
||||||
let equipmentMeasurement = EquipmentMeasurement.mock(type: equipmentType)
|
|
||||||
|
|
||||||
var estimate = try await client.estimatedPressure(
|
|
||||||
equipmentMeasurement: equipmentMeasurement,
|
|
||||||
airflow: 1050
|
|
||||||
)
|
|
||||||
|
|
||||||
guard let filterPressureDrop else { return estimate }
|
|
||||||
setFilterPressureDrop(Positive(filterPressureDrop), measurement: &estimate)
|
|
||||||
return estimate
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func setFilterPressureDrop(
|
|
||||||
_ filterDrop: Positive<Double>,
|
|
||||||
measurement: inout EquipmentMeasurement
|
|
||||||
) {
|
|
||||||
switch measurement {
|
|
||||||
case var .airHandler(airHandler):
|
|
||||||
// let newPressure = airHandler.$returnPlenumPressure + filterDrop
|
|
||||||
// print("newPressure: \(newPressure)")
|
|
||||||
airHandler.postFilterPressure = airHandler.returnPlenumPressure +
|
|
||||||
filterDrop.positiveValue
|
|
||||||
measurement = .airHandler(airHandler)
|
|
||||||
case var .furnaceAndCoil(furnace):
|
|
||||||
furnace.postFilterPressure = furnace.returnPlenumPressure + filterDrop.positiveValue
|
|
||||||
measurement = .furnaceAndCoil(furnace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Tag {
|
extension Tag {
|
||||||
|
|||||||
Reference in New Issue
Block a user