feat: Adds psychrometrics calculator.

This commit is contained in:
2025-03-06 13:41:38 -05:00
parent e0e5b10a34
commit ee577003d5
13 changed files with 1386 additions and 7 deletions

View File

@@ -0,0 +1,36 @@
import Dependencies
import Logging
import PsychrometricClient
import Routes
public extension Routes.Psychrometrics.Request {
func respond(logger: Logger) async throws -> Psychrometrics.Response {
@Dependency(\.psychrometricClient) var psychrometricClient
try validate()
let properties = try await psychrometricClient.psychrometricProperties(
.dryBulb(.fahrenheit(temperature), relativeHumidity: humidity%, altitude: .feet(altitude ?? 0))
)
var warnings = [String]()
if altitude == nil || altitude == 0 {
warnings.append(
"Calculations based on altitude of sea level - set project altitude for higher accuracy."
)
}
return .init(properties: properties, warnings: warnings)
}
private func validate() throws {
guard temperature > 0 else {
throw ValidationError(message: "Temperature should be greater than 0.")
}
guard humidity > 0, humidity <= 100 else {
throw ValidationError(message: "Relative humidity should be greater than 0 and less than or equal to 100.")
}
if let altitude, altitude < 0 {
throw ValidationError(message: "Altitude should be greater than 0.")
}
}
}