WIP: Adds more tagged types for rectangular size calculations.
This commit is contained in:
@@ -103,7 +103,7 @@ extension TrunkSize.Create {
|
|||||||
.init(
|
.init(
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
type: type,
|
type: type,
|
||||||
height: height,
|
height: height?.rawValue,
|
||||||
name: name
|
name: name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
projectID: $project.id,
|
projectID: $project.id,
|
||||||
type: .init(rawValue: type)!,
|
type: .init(rawValue: type)!,
|
||||||
rooms: rooms,
|
rooms: rooms,
|
||||||
height: height,
|
height: height.map { .init(rawValue: $0) },
|
||||||
name: name
|
name: name
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
if let type = updates.type, type.rawValue != self.type {
|
if let type = updates.type, type.rawValue != self.type {
|
||||||
self.type = type.rawValue
|
self.type = type.rawValue
|
||||||
}
|
}
|
||||||
if let height = updates.height, height != self.height {
|
if let height = updates.height?.rawValue, height != self.height {
|
||||||
self.height = height
|
self.height = height
|
||||||
}
|
}
|
||||||
if let name = updates.name, name != self.name {
|
if let name = updates.name, name != self.name {
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ extension DependencyValues {
|
|||||||
public struct ManualDClient: Sendable {
|
public struct ManualDClient: Sendable {
|
||||||
public var ductSize: @Sendable (CFM, DesignFrictionRate) async throws -> DuctSizeResponse
|
public var ductSize: @Sendable (CFM, DesignFrictionRate) async throws -> DuctSizeResponse
|
||||||
public var frictionRate: @Sendable (FrictionRateRequest) async throws -> FrictionRate
|
public var frictionRate: @Sendable (FrictionRateRequest) async throws -> FrictionRate
|
||||||
public var rectangularSize:
|
public var rectangularSize: @Sendable (RoundSize, Height) async throws -> RectangularSizeResponse
|
||||||
@Sendable (RectangularSizeRequest) async throws -> RectangularSizeResponse
|
|
||||||
|
|
||||||
public func ductSize(
|
public func ductSize(
|
||||||
cfm designCFM: Int,
|
cfm designCFM: Int,
|
||||||
@@ -34,6 +33,21 @@ public struct ManualDClient: Sendable {
|
|||||||
) async throws -> DuctSizeResponse {
|
) async throws -> DuctSizeResponse {
|
||||||
try await ductSize(.init(rawValue: Int(designCFM)), .init(rawValue: designFrictionRate))
|
try await ductSize(.init(rawValue: Int(designCFM)), .init(rawValue: designFrictionRate))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func rectangularSize(
|
||||||
|
round roundSize: RoundSize,
|
||||||
|
height: Height
|
||||||
|
) async throws -> RectangularSizeResponse {
|
||||||
|
try await rectangularSize(roundSize, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func rectangularSize(
|
||||||
|
round roundSize: Int,
|
||||||
|
height: Int
|
||||||
|
) async throws -> RectangularSizeResponse {
|
||||||
|
try await rectangularSize(.init(rawValue: roundSize), .init(rawValue: height))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ManualDClient: TestDependencyKey {
|
extension ManualDClient: TestDependencyKey {
|
||||||
@@ -90,23 +104,31 @@ extension ManualDClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct RectangularSizeRequest: Codable, Equatable, Sendable {
|
// public struct RectangularSizeRequest: Codable, Equatable, Sendable {
|
||||||
public let roundSize: Int
|
// public let roundSize: RoundSize
|
||||||
public let height: Int
|
// public let height: Height
|
||||||
|
//
|
||||||
public init(round roundSize: Int, height: Int) {
|
// public init(round roundSize: RoundSize, height: Height) {
|
||||||
self.roundSize = roundSize
|
// self.roundSize = roundSize
|
||||||
self.height = height
|
// self.height = height
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// public init(round roundSize: Int, height: Int) {
|
||||||
|
// self.init(round: .init(rawValue: roundSize), height: .init(rawValue: height))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public struct RectangularSizeResponse: Codable, Equatable, Sendable {
|
public struct RectangularSizeResponse: Codable, Equatable, Sendable {
|
||||||
public let height: Int
|
public let height: Height
|
||||||
public let width: Int
|
public let width: Width
|
||||||
|
|
||||||
public init(height: Int, width: Int) {
|
public init(height: Height, width: Width) {
|
||||||
self.height = height
|
self.height = height
|
||||||
self.width = width
|
self.width = width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public init(height: Int, width: Int) {
|
||||||
|
self.init(height: .init(rawValue: height), width: .init(rawValue: width))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,12 @@ extension ManualDClient: DependencyKey {
|
|||||||
// let groupLengths = request.effectiveLengthGroups.totalEffectiveLength
|
// let groupLengths = request.effectiveLengthGroups.totalEffectiveLength
|
||||||
// return trunkLengths + runoutLengths + groupLengths
|
// return trunkLengths + runoutLengths + groupLengths
|
||||||
// },
|
// },
|
||||||
rectangularSize: { request in
|
rectangularSize: { round, height in
|
||||||
let width = (Double.pi * (pow(Double(request.roundSize) / 2.0, 2.0))) / Double(request.height)
|
let width = (Double.pi * (pow(Double(round.rawValue) / 2.0, 2.0))) / Double(height.rawValue)
|
||||||
return .init(height: request.height, width: Int(width.rounded(.toNearestOrEven)))
|
return .init(
|
||||||
|
height: height,
|
||||||
|
width: .init(rawValue: Int(width.rounded(.toNearestOrEven)))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import Tagged
|
import Tagged
|
||||||
|
|
||||||
public enum CFMTag {}
|
/// A name space for general tag types.
|
||||||
public typealias CFM = Tagged<CFMTag, Int>
|
public enum Tag {
|
||||||
|
public enum CFM {}
|
||||||
|
public enum DesignFrictionRate {}
|
||||||
|
public enum Height {}
|
||||||
|
public enum Round {}
|
||||||
|
public enum Width {}
|
||||||
|
}
|
||||||
|
|
||||||
public enum DesignFrictionRateTag {}
|
public typealias CFM = Tagged<Tag.CFM, Int>
|
||||||
public typealias DesignFrictionRate = Tagged<DesignFrictionRateTag, Double>
|
public typealias DesignFrictionRate = Tagged<Tag.DesignFrictionRate, Double>
|
||||||
|
public typealias Height = Tagged<Tag.Height, Int>
|
||||||
|
public typealias RoundSize = Tagged<Tag.Round, Int>
|
||||||
|
public typealias Width = Tagged<Tag.Width, Int>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public struct TrunkSize: Codable, Equatable, Identifiable, Sendable {
|
|||||||
public let rooms: [RoomProxy]
|
public let rooms: [RoomProxy]
|
||||||
/// An optional rectangular height used to calculate the equivalent
|
/// An optional rectangular height used to calculate the equivalent
|
||||||
/// rectangular size of the trunk.
|
/// rectangular size of the trunk.
|
||||||
public let height: Int?
|
public let height: Height?
|
||||||
/// An optional name / label used for identifying the trunk.
|
/// An optional name / label used for identifying the trunk.
|
||||||
public let name: String?
|
public let name: String?
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ public struct TrunkSize: Codable, Equatable, Identifiable, Sendable {
|
|||||||
projectID: Project.ID,
|
projectID: Project.ID,
|
||||||
type: TrunkType,
|
type: TrunkType,
|
||||||
rooms: [RoomProxy],
|
rooms: [RoomProxy],
|
||||||
height: Int? = nil,
|
height: Height? = nil,
|
||||||
name: String? = nil
|
name: String? = nil
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
@@ -49,7 +49,7 @@ extension TrunkSize {
|
|||||||
public let rooms: [Room.ID: [Int]]
|
public let rooms: [Room.ID: [Int]]
|
||||||
/// An optional rectangular height used to calculate the equivalent
|
/// An optional rectangular height used to calculate the equivalent
|
||||||
/// rectangular size of the trunk.
|
/// rectangular size of the trunk.
|
||||||
public let height: Int?
|
public let height: Height?
|
||||||
/// An optional name / label used for identifying the trunk.
|
/// An optional name / label used for identifying the trunk.
|
||||||
public let name: String?
|
public let name: String?
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ extension TrunkSize {
|
|||||||
projectID: Project.ID,
|
projectID: Project.ID,
|
||||||
type: TrunkType,
|
type: TrunkType,
|
||||||
rooms: [Room.ID: [Int]],
|
rooms: [Room.ID: [Int]],
|
||||||
height: Int? = nil,
|
height: Height? = nil,
|
||||||
name: String? = nil
|
name: String? = nil
|
||||||
) {
|
) {
|
||||||
self.projectID = projectID
|
self.projectID = projectID
|
||||||
@@ -79,14 +79,14 @@ extension TrunkSize {
|
|||||||
public let rooms: [Room.ID: [Int]]?
|
public let rooms: [Room.ID: [Int]]?
|
||||||
/// An optional rectangular height used to calculate the equivalent
|
/// An optional rectangular height used to calculate the equivalent
|
||||||
/// rectangular size of the trunk.
|
/// rectangular size of the trunk.
|
||||||
public let height: Int?
|
public let height: Height?
|
||||||
/// An optional name / label used for identifying the trunk.
|
/// An optional name / label used for identifying the trunk.
|
||||||
public let name: String?
|
public let name: String?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
type: TrunkType? = nil,
|
type: TrunkType? = nil,
|
||||||
rooms: [Room.ID: [Int]]? = nil,
|
rooms: [Room.ID: [Int]]? = nil,
|
||||||
height: Int? = nil,
|
height: Height? = nil,
|
||||||
name: String? = nil
|
name: String? = nil
|
||||||
) {
|
) {
|
||||||
self.type = type
|
self.type = type
|
||||||
|
|||||||
@@ -64,9 +64,10 @@ extension ManualDClient {
|
|||||||
|
|
||||||
if let rectangularSize {
|
if let rectangularSize {
|
||||||
let response = try await self.rectangularSize(
|
let response = try await self.rectangularSize(
|
||||||
.init(round: sizes.finalSize, height: rectangularSize.height)
|
round: sizes.finalSize,
|
||||||
|
height: rectangularSize.height
|
||||||
)
|
)
|
||||||
rectangularWidth = response.width
|
rectangularWidth = response.width.rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
retval.append(
|
retval.append(
|
||||||
@@ -118,9 +119,10 @@ extension ManualDClient {
|
|||||||
var width: Int? = nil
|
var width: Int? = nil
|
||||||
if let height = trunk.height {
|
if let height = trunk.height {
|
||||||
let rectangularSize = try await self.rectangularSize(
|
let rectangularSize = try await self.rectangularSize(
|
||||||
.init(round: sizes.finalSize, height: height)
|
round: .init(rawValue: sizes.finalSize),
|
||||||
|
height: height
|
||||||
)
|
)
|
||||||
width = rectangularSize.width
|
width = rectangularSize.width.rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
retval.append(
|
retval.append(
|
||||||
@@ -129,7 +131,7 @@ extension ManualDClient {
|
|||||||
ductSize: .init(
|
ductSize: .init(
|
||||||
designCFM: designCFM,
|
designCFM: designCFM,
|
||||||
sizes: sizes,
|
sizes: sizes,
|
||||||
height: trunk.height,
|
height: trunk.height?.rawValue,
|
||||||
width: width
|
width: width
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkSizeForm {
|
|||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
type: type,
|
type: type,
|
||||||
rooms: makeRooms(logger: logger),
|
rooms: makeRooms(logger: logger),
|
||||||
height: height,
|
height: height.map { .init(rawValue: $0) },
|
||||||
name: name
|
name: name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkSizeForm {
|
|||||||
try .init(
|
try .init(
|
||||||
type: type,
|
type: type,
|
||||||
rooms: makeRooms(logger: logger),
|
rooms: makeRooms(logger: logger),
|
||||||
height: height,
|
height: height.map { .init(rawValue: $0) },
|
||||||
name: name
|
name: name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ struct TrunkSizeForm: HTML, Sendable {
|
|||||||
"Height",
|
"Height",
|
||||||
.type(.text),
|
.type(.text),
|
||||||
.name("height"),
|
.name("height"),
|
||||||
.value(trunk?.height),
|
.value(trunk?.height?.rawValue),
|
||||||
.placeholder("8 (Optional)"),
|
.placeholder("8 (Optional)"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ struct ManualDClientTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
func equivalentRectangularDuct() async throws {
|
func equivalentRectangularDuct() async throws {
|
||||||
let response = try await manualD.rectangularSize(.init(round: 7, height: 8))
|
let response = try await manualD.rectangularSize(round: 7, height: 8)
|
||||||
#expect(response.height == 8)
|
#expect(response.height == 8)
|
||||||
#expect(response.width == 5)
|
#expect(response.width == 5)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user