feat: Initial commit
This commit is contained in:
79
Sources/ManualS/Internal/SizingLimits.swift
Normal file
79
Sources/ManualS/Internal/SizingLimits.swift
Normal file
@@ -0,0 +1,79 @@
|
||||
import CoreFoundation
|
||||
import Models
|
||||
|
||||
extension SizingLimits.Request {
|
||||
func respond() async throws -> SizingLimits.Response {
|
||||
return try .init(
|
||||
oversizing: .oversizingLimit(systemType: systemType, houseLoad: houseLoad),
|
||||
undersizing: .undersizingLimits
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private extension SizingLimits.Limits {
|
||||
static let undersizingLimits = Self(
|
||||
heating: 90,
|
||||
coolingTotal: 90,
|
||||
coolingSensible: 90,
|
||||
coolingLatent: 90
|
||||
)
|
||||
|
||||
static func oversizingLimit(
|
||||
systemType: SystemType,
|
||||
houseLoad: HouseLoad?
|
||||
) throws -> Self {
|
||||
switch systemType {
|
||||
case let .heatingOnly(type: type):
|
||||
return .init(heating: type.oversizingLimit(), coolingTotal: 115)
|
||||
case let .airToAir(type: _, compressor: compressor, climate: climate):
|
||||
return try .init(
|
||||
heating: 140,
|
||||
coolingTotal: coolingTotalOversizingLimit(
|
||||
houseLoad: houseLoad,
|
||||
compressorType: compressor,
|
||||
climateType: climate
|
||||
),
|
||||
coolingSensible: nil,
|
||||
coolingLatent: 150
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension SystemType.HeatingOnlyType {
|
||||
|
||||
func oversizingLimit() -> Int {
|
||||
switch self {
|
||||
case .boiler, .furnace: return 140
|
||||
case .electric: return 175
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func coolingTotalOversizingLimit(
|
||||
houseLoad: HouseLoad?,
|
||||
compressorType: SystemType.CompressorType,
|
||||
climateType: SystemType.ClimateType
|
||||
) throws -> Int {
|
||||
switch (compressorType, climateType) {
|
||||
case (.singleSpeed, .mildWinterOrLatentLoad):
|
||||
return 115
|
||||
case (.multiSpeed, .mildWinterOrLatentLoad):
|
||||
return 120
|
||||
case (.variableSpeed, .mildWinterOrLatentLoad):
|
||||
return 130
|
||||
default:
|
||||
|
||||
guard let houseLoad else {
|
||||
throw HouseLoadError()
|
||||
}
|
||||
let decimal = Double(houseLoad.coolingTotal + 15000) / Double(houseLoad.coolingTotal)
|
||||
return Int(round(decimal * 100))
|
||||
}
|
||||
}
|
||||
|
||||
public struct HouseLoadError: Error, Equatable {
|
||||
public let message = "House load not supplied."
|
||||
|
||||
public init() {}
|
||||
}
|
||||
Reference in New Issue
Block a user