feat: Initial commit
This commit is contained in:
39
Sources/ManualS/Internal/BalancePoint.swift
Normal file
39
Sources/ManualS/Internal/BalancePoint.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
import CoreFoundation
|
||||
import Models
|
||||
import Validations
|
||||
|
||||
extension BalancePoint.Request {
|
||||
|
||||
func respond() async throws -> BalancePoint.Response {
|
||||
try await validate()
|
||||
let balancePoint = await thermalBalancePoint(
|
||||
heatLoss: Double(heatLoss),
|
||||
at47: Double(heatPumpCapacity.at47),
|
||||
at17: Double(heatPumpCapacity.at17),
|
||||
designTemperature: Double(winterDesignTemperature)
|
||||
)
|
||||
return .init(balancePointTemperature: balancePoint)
|
||||
}
|
||||
}
|
||||
|
||||
extension BalancePoint.Request: AsyncValidatable {
|
||||
|
||||
@inlinable
|
||||
public var body: some AsyncValidation<Self> {
|
||||
AsyncValidator.accumulating {
|
||||
AsyncValidator.greaterThan(\.heatLoss, 0)
|
||||
AsyncValidator.validate(\.heatPumpCapacity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func thermalBalancePoint(
|
||||
heatLoss: Double,
|
||||
at47: Double,
|
||||
at17: Double,
|
||||
designTemperature: Double
|
||||
) async -> Double {
|
||||
(30.0 * (((designTemperature - 65.0) * at47) + (65.0 * heatLoss))
|
||||
- ((designTemperature - 65.0) * (at47 - at17) * 47.0))
|
||||
/ ((30.0 * heatLoss) - ((designTemperature - 65.0) * (at47 - at17)))
|
||||
}
|
||||
Reference in New Issue
Block a user