Compare commits
7 Commits
0.1.1
...
146baa7815
| Author | SHA1 | Date | |
|---|---|---|---|
|
146baa7815
|
|||
|
b5436c2073
|
|||
|
59c1c9ec4a
|
|||
|
65fc8565b6
|
|||
|
d14477e97a
|
|||
|
dbec7fb920
|
|||
|
6b8cb73434
|
@@ -8,6 +8,7 @@ let package = Package(
|
|||||||
.executable(name: "App", targets: ["App"]),
|
.executable(name: "App", targets: ["App"]),
|
||||||
.library(name: "ApiController", targets: ["ApiController"]),
|
.library(name: "ApiController", targets: ["ApiController"]),
|
||||||
.library(name: "DatabaseClient", targets: ["DatabaseClient"]),
|
.library(name: "DatabaseClient", targets: ["DatabaseClient"]),
|
||||||
|
.library(name: "ProjectClient", targets: ["ProjectClient"]),
|
||||||
.library(name: "ManualDCore", targets: ["ManualDCore"]),
|
.library(name: "ManualDCore", targets: ["ManualDCore"]),
|
||||||
.library(name: "ManualDClient", targets: ["ManualDClient"]),
|
.library(name: "ManualDClient", targets: ["ManualDClient"]),
|
||||||
.library(name: "Styleguide", targets: ["Styleguide"]),
|
.library(name: "Styleguide", targets: ["Styleguide"]),
|
||||||
@@ -63,6 +64,13 @@ let package = Package(
|
|||||||
.product(name: "Vapor", package: "vapor"),
|
.product(name: "Vapor", package: "vapor"),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
.target(
|
||||||
|
name: "ProjectClient",
|
||||||
|
dependencies: [
|
||||||
|
.target(name: "DatabaseClient"),
|
||||||
|
.target(name: "ManualDClient"),
|
||||||
|
]
|
||||||
|
),
|
||||||
.target(
|
.target(
|
||||||
name: "ManualDCore",
|
name: "ManualDCore",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
@@ -105,6 +113,7 @@ let package = Package(
|
|||||||
name: "ViewController",
|
name: "ViewController",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.target(name: "DatabaseClient"),
|
.target(name: "DatabaseClient"),
|
||||||
|
.target(name: "ProjectClient"),
|
||||||
.target(name: "ManualDClient"),
|
.target(name: "ManualDClient"),
|
||||||
.target(name: "ManualDCore"),
|
.target(name: "ManualDCore"),
|
||||||
.target(name: "Styleguide"),
|
.target(name: "Styleguide"),
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ extension DatabaseClient.Migrations: DependencyKey {
|
|||||||
EquipmentInfo.Migrate(),
|
EquipmentInfo.Migrate(),
|
||||||
Room.Migrate(),
|
Room.Migrate(),
|
||||||
EffectiveLength.Migrate(),
|
EffectiveLength.Migrate(),
|
||||||
DuctSizing.TrunkSize.Migrate(),
|
TrunkSize.Migrate(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,10 +73,16 @@ extension DatabaseClient.Projects: TestDependencyKey {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
getSensibleHeatRatio: { id in
|
getSensibleHeatRatio: { id in
|
||||||
guard let model = try await ProjectModel.find(id, on: database) else {
|
guard
|
||||||
|
let shr = try await ProjectModel.query(on: database)
|
||||||
|
.field(\.$id)
|
||||||
|
.field(\.$sensibleHeatRatio)
|
||||||
|
.filter(\.$id == id)
|
||||||
|
.first()
|
||||||
|
else {
|
||||||
throw NotFoundError()
|
throw NotFoundError()
|
||||||
}
|
}
|
||||||
return model.sensibleHeatRatio
|
return shr.sensibleHeatRatio
|
||||||
},
|
},
|
||||||
fetch: { userID, request in
|
fetch: { userID, request in
|
||||||
try await ProjectModel.query(on: database)
|
try await ProjectModel.query(on: database)
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ extension DatabaseClient {
|
|||||||
public var create: @Sendable (Room.Create) async throws -> Room
|
public var create: @Sendable (Room.Create) async throws -> Room
|
||||||
public var delete: @Sendable (Room.ID) async throws -> Void
|
public var delete: @Sendable (Room.ID) async throws -> Void
|
||||||
public var deleteRectangularSize:
|
public var deleteRectangularSize:
|
||||||
@Sendable (Room.ID, DuctSizing.RectangularDuct.ID) async throws -> Room
|
@Sendable (Room.ID, Room.RectangularSize.ID) async throws -> Room
|
||||||
public var get: @Sendable (Room.ID) async throws -> Room?
|
public var get: @Sendable (Room.ID) async throws -> Room?
|
||||||
public var fetch: @Sendable (Project.ID) async throws -> [Room]
|
public var fetch: @Sendable (Project.ID) async throws -> [Room]
|
||||||
public var update: @Sendable (Room.ID, Room.Update) async throws -> Room
|
public var update: @Sendable (Room.ID, Room.Update) async throws -> Room
|
||||||
public var updateRectangularSize:
|
public var updateRectangularSize: @Sendable (Room.ID, Room.RectangularSize) async throws -> Room
|
||||||
@Sendable (Room.ID, DuctSizing.RectangularDuct) async throws -> Room
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +203,7 @@ final class RoomModel: Model, @unchecked Sendable {
|
|||||||
var registerCount: Int
|
var registerCount: Int
|
||||||
|
|
||||||
@Field(key: "rectangularSizes")
|
@Field(key: "rectangularSizes")
|
||||||
var rectangularSizes: [DuctSizing.RectangularDuct]?
|
var rectangularSizes: [Room.RectangularSize]?
|
||||||
|
|
||||||
@Timestamp(key: "createdAt", on: .create, format: .iso8601)
|
@Timestamp(key: "createdAt", on: .create, format: .iso8601)
|
||||||
var createdAt: Date?
|
var createdAt: Date?
|
||||||
@@ -224,7 +223,7 @@ final class RoomModel: Model, @unchecked Sendable {
|
|||||||
coolingTotal: Double,
|
coolingTotal: Double,
|
||||||
coolingSensible: Double? = nil,
|
coolingSensible: Double? = nil,
|
||||||
registerCount: Int,
|
registerCount: Int,
|
||||||
rectangularSizes: [DuctSizing.RectangularDuct]? = nil,
|
rectangularSizes: [Room.RectangularSize]? = nil,
|
||||||
createdAt: Date? = nil,
|
createdAt: Date? = nil,
|
||||||
updatedAt: Date? = nil,
|
updatedAt: Date? = nil,
|
||||||
projectID: Project.ID
|
projectID: Project.ID
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import ManualDCore
|
|||||||
extension DatabaseClient {
|
extension DatabaseClient {
|
||||||
@DependencyClient
|
@DependencyClient
|
||||||
public struct TrunkSizes: Sendable {
|
public struct TrunkSizes: Sendable {
|
||||||
public var create: @Sendable (DuctSizing.TrunkSize.Create) async throws -> DuctSizing.TrunkSize
|
public var create: @Sendable (TrunkSize.Create) async throws -> TrunkSize
|
||||||
public var delete: @Sendable (DuctSizing.TrunkSize.ID) async throws -> Void
|
public var delete: @Sendable (TrunkSize.ID) async throws -> Void
|
||||||
public var fetch: @Sendable (Project.ID) async throws -> [DuctSizing.TrunkSize]
|
public var fetch: @Sendable (Project.ID) async throws -> [TrunkSize]
|
||||||
public var get: @Sendable (DuctSizing.TrunkSize.ID) async throws -> DuctSizing.TrunkSize?
|
public var get: @Sendable (TrunkSize.ID) async throws -> TrunkSize?
|
||||||
public var update:
|
public var update:
|
||||||
@Sendable (DuctSizing.TrunkSize.ID, DuctSizing.TrunkSize.Update) async throws ->
|
@Sendable (TrunkSize.ID, TrunkSize.Update) async throws ->
|
||||||
DuctSizing.TrunkSize
|
TrunkSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ extension DatabaseClient.TrunkSizes: TestDependencyKey {
|
|||||||
try request.validate()
|
try request.validate()
|
||||||
|
|
||||||
let trunk = request.toModel()
|
let trunk = request.toModel()
|
||||||
var roomProxies = [DuctSizing.TrunkSize.RoomProxy]()
|
var roomProxies = [TrunkSize.RoomProxy]()
|
||||||
|
|
||||||
try await trunk.save(on: database)
|
try await trunk.save(on: database)
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ extension DatabaseClient.TrunkSizes: TestDependencyKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DuctSizing.TrunkSize.Create {
|
extension TrunkSize.Create {
|
||||||
|
|
||||||
func validate() throws(ValidationError) {
|
func validate() throws(ValidationError) {
|
||||||
guard rooms.count > 0 else {
|
guard rooms.count > 0 else {
|
||||||
@@ -113,7 +113,7 @@ extension DuctSizing.TrunkSize.Create {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DuctSizing.TrunkSize.Update {
|
extension TrunkSize.Update {
|
||||||
func validate() throws(ValidationError) {
|
func validate() throws(ValidationError) {
|
||||||
if let rooms {
|
if let rooms {
|
||||||
guard rooms.count > 0 else {
|
guard rooms.count > 0 else {
|
||||||
@@ -128,7 +128,7 @@ extension DuctSizing.TrunkSize.Update {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DuctSizing.TrunkSize {
|
extension TrunkSize {
|
||||||
|
|
||||||
struct Migrate: AsyncMigration {
|
struct Migrate: AsyncMigration {
|
||||||
let name = "CreateTrunkSize"
|
let name = "CreateTrunkSize"
|
||||||
@@ -192,7 +192,7 @@ final class TrunkRoomModel: Model, @unchecked Sendable {
|
|||||||
trunkID: TrunkModel.IDValue,
|
trunkID: TrunkModel.IDValue,
|
||||||
roomID: RoomModel.IDValue,
|
roomID: RoomModel.IDValue,
|
||||||
registers: [Int],
|
registers: [Int],
|
||||||
type: DuctSizing.TrunkSize.TrunkType
|
type: TrunkSize.TrunkType
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
$trunk.id = trunkID
|
$trunk.id = trunkID
|
||||||
@@ -201,7 +201,7 @@ final class TrunkRoomModel: Model, @unchecked Sendable {
|
|||||||
self.type = type.rawValue
|
self.type = type.rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func toDTO(on database: any Database) async throws -> DuctSizing.TrunkSize.RoomProxy {
|
func toDTO(on database: any Database) async throws -> TrunkSize.RoomProxy {
|
||||||
guard let room = try await RoomModel.find($room.id, on: database) else {
|
guard let room = try await RoomModel.find($room.id, on: database) else {
|
||||||
throw NotFoundError()
|
throw NotFoundError()
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
init(
|
init(
|
||||||
id: UUID? = nil,
|
id: UUID? = nil,
|
||||||
projectID: Project.ID,
|
projectID: Project.ID,
|
||||||
type: DuctSizing.TrunkSize.TrunkType,
|
type: TrunkSize.TrunkType,
|
||||||
height: Int? = nil,
|
height: Int? = nil,
|
||||||
name: String? = nil
|
name: String? = nil
|
||||||
) {
|
) {
|
||||||
@@ -251,15 +251,15 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
self.name = name
|
self.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
func toDTO(on database: any Database) async throws -> DuctSizing.TrunkSize {
|
func toDTO(on database: any Database) async throws -> TrunkSize {
|
||||||
let rooms = try await withThrowingTaskGroup(of: DuctSizing.TrunkSize.RoomProxy.self) { group in
|
let rooms = try await withThrowingTaskGroup(of: TrunkSize.RoomProxy.self) { group in
|
||||||
for room in self.rooms {
|
for room in self.rooms {
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await room.toDTO(on: database)
|
try await room.toDTO(on: database)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return try await group.reduce(into: [DuctSizing.TrunkSize.RoomProxy]()) {
|
return try await group.reduce(into: [TrunkSize.RoomProxy]()) {
|
||||||
$0.append($1)
|
$0.append($1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyUpdates(
|
func applyUpdates(
|
||||||
_ updates: DuctSizing.TrunkSize.Update,
|
_ updates: TrunkSize.Update,
|
||||||
on database: any Database
|
on database: any Database
|
||||||
) async throws {
|
) async throws {
|
||||||
if let type = updates.type, type.rawValue != self.type {
|
if let type = updates.type, type.rawValue != self.type {
|
||||||
@@ -340,15 +340,15 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
|
|
||||||
extension Array where Element == TrunkModel {
|
extension Array where Element == TrunkModel {
|
||||||
|
|
||||||
func toDTO(on database: any Database) async throws -> [DuctSizing.TrunkSize] {
|
func toDTO(on database: any Database) async throws -> [TrunkSize] {
|
||||||
try await withThrowingTaskGroup(of: DuctSizing.TrunkSize.self) { group in
|
try await withThrowingTaskGroup(of: TrunkSize.self) { group in
|
||||||
for model in self {
|
for model in self {
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await model.toDTO(on: database)
|
try await model.toDTO(on: database)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return try await group.reduce(into: [DuctSizing.TrunkSize]()) {
|
return try await group.reduce(into: [TrunkSize]()) {
|
||||||
$0.append($1)
|
$0.append($1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ extension Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DuctSizing.TrunkSize.RoomProxy {
|
extension TrunkSize.RoomProxy {
|
||||||
|
|
||||||
// We need to make sure if registers got removed after a trunk
|
// We need to make sure if registers got removed after a trunk
|
||||||
// was already made / saved that we do not include registers that
|
// was already made / saved that we do not include registers that
|
||||||
@@ -35,7 +35,7 @@ extension DuctSizing.TrunkSize.RoomProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DuctSizing.TrunkSize {
|
extension TrunkSize {
|
||||||
|
|
||||||
var totalHeatingLoad: Double {
|
var totalHeatingLoad: Double {
|
||||||
rooms.reduce(into: 0) { $0 += $1.totalHeatingLoad }
|
rooms.reduce(into: 0) { $0 += $1.totalHeatingLoad }
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ import DependenciesMacros
|
|||||||
import Logging
|
import Logging
|
||||||
import ManualDCore
|
import ManualDCore
|
||||||
|
|
||||||
|
extension DependencyValues {
|
||||||
|
public var manualD: ManualDClient {
|
||||||
|
get { self[ManualDClient.self] }
|
||||||
|
set { self[ManualDClient.self] = newValue }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@DependencyClient
|
@DependencyClient
|
||||||
public struct ManualDClient: Sendable {
|
public struct ManualDClient: Sendable {
|
||||||
public var ductSize: @Sendable (DuctSizeRequest) async throws -> DuctSizeResponse
|
public var ductSize: @Sendable (DuctSizeRequest) async throws -> DuctSizeResponse
|
||||||
@@ -11,144 +18,155 @@ public struct ManualDClient: Sendable {
|
|||||||
public var equivalentRectangularDuct:
|
public var equivalentRectangularDuct:
|
||||||
@Sendable (EquivalentRectangularDuctRequest) async throws -> EquivalentRectangularDuctResponse
|
@Sendable (EquivalentRectangularDuctRequest) async throws -> EquivalentRectangularDuctResponse
|
||||||
|
|
||||||
public func calculateSizes(
|
// TODO: add (Project.ID) async throws -> ProjectResponse
|
||||||
rooms: [Room],
|
|
||||||
trunks: [DuctSizing.TrunkSize],
|
|
||||||
equipmentInfo: EquipmentInfo,
|
|
||||||
maxSupplyLength: EffectiveLength,
|
|
||||||
maxReturnLength: EffectiveLength,
|
|
||||||
designFrictionRate: Double,
|
|
||||||
projectSHR: Double,
|
|
||||||
logger: Logger? = nil
|
|
||||||
) async throws -> (rooms: [DuctSizing.RoomContainer], trunks: [DuctSizing.TrunkContainer]) {
|
|
||||||
try await (
|
|
||||||
calculateSizes(
|
|
||||||
rooms: rooms, equipmentInfo: equipmentInfo,
|
|
||||||
maxSupplyLength: maxSupplyLength, maxReturnLength: maxReturnLength,
|
|
||||||
designFrictionRate: designFrictionRate, projectSHR: projectSHR
|
|
||||||
),
|
|
||||||
calculateSizes(
|
|
||||||
rooms: rooms, trunks: trunks, equipmentInfo: equipmentInfo,
|
|
||||||
maxSupplyLength: maxSupplyLength, maxReturnLength: maxReturnLength,
|
|
||||||
designFrictionRate: designFrictionRate, projectSHR: projectSHR)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func calculateSizes(
|
// TODO: Move to helpers.
|
||||||
rooms: [Room],
|
// public func calculateSizes(
|
||||||
equipmentInfo: EquipmentInfo,
|
// rooms: [Room],
|
||||||
maxSupplyLength: EffectiveLength,
|
// trunks: [DuctSizing.TrunkSize],
|
||||||
maxReturnLength: EffectiveLength,
|
// equipmentInfo: EquipmentInfo,
|
||||||
designFrictionRate: Double,
|
// maxSupplyLength: EffectiveLength,
|
||||||
projectSHR: Double,
|
// maxReturnLength: EffectiveLength,
|
||||||
logger: Logger? = nil
|
// designFrictionRate: Double,
|
||||||
) async throws -> [DuctSizing.RoomContainer] {
|
// projectSHR: Double,
|
||||||
|
// logger: Logger? = nil
|
||||||
var retval: [DuctSizing.RoomContainer] = []
|
// ) async throws -> ProjectResponse {
|
||||||
let totalHeatingLoad = rooms.totalHeatingLoad
|
// try await .init(
|
||||||
let totalCoolingSensible = rooms.totalCoolingSensible(shr: projectSHR)
|
// rooms: calculateRoomSizes(
|
||||||
|
// rooms: rooms,
|
||||||
for room in rooms {
|
// equipmentInfo: equipmentInfo,
|
||||||
let heatingLoad = room.heatingLoadPerRegister
|
// maxSupplyLength: maxSupplyLength,
|
||||||
let coolingLoad = room.coolingSensiblePerRegister(projectSHR: projectSHR)
|
// maxReturnLength: maxReturnLength,
|
||||||
let heatingPercent = heatingLoad / totalHeatingLoad
|
// designFrictionRate: designFrictionRate,
|
||||||
let coolingPercent = coolingLoad / totalCoolingSensible
|
// projectSHR: projectSHR
|
||||||
let heatingCFM = heatingPercent * Double(equipmentInfo.heatingCFM)
|
// ),
|
||||||
let coolingCFM = coolingPercent * Double(equipmentInfo.coolingCFM)
|
// trunks: calculateTrunkSizes(
|
||||||
let designCFM = DuctSizing.DesignCFM(heating: heatingCFM, cooling: coolingCFM)
|
// rooms: rooms,
|
||||||
let sizes = try await self.ductSize(
|
// trunks: trunks,
|
||||||
.init(designCFM: Int(designCFM.value), frictionRate: designFrictionRate)
|
// equipmentInfo: equipmentInfo,
|
||||||
)
|
// maxSupplyLength: maxSupplyLength,
|
||||||
|
// maxReturnLength: maxReturnLength,
|
||||||
for n in 1...room.registerCount {
|
// designFrictionRate: designFrictionRate,
|
||||||
|
// projectSHR: projectSHR
|
||||||
var rectangularWidth: Int? = nil
|
// )
|
||||||
let rectangularSize = room.rectangularSizes?
|
// )
|
||||||
.first(where: { $0.register == nil || $0.register == n })
|
// }
|
||||||
|
//
|
||||||
if let rectangularSize {
|
// func calculateRoomSizes(
|
||||||
let response = try await self.equivalentRectangularDuct(
|
// rooms: [Room],
|
||||||
.init(round: sizes.finalSize, height: rectangularSize.height)
|
// equipmentInfo: EquipmentInfo,
|
||||||
)
|
// maxSupplyLength: EffectiveLength,
|
||||||
rectangularWidth = response.width
|
// maxReturnLength: EffectiveLength,
|
||||||
}
|
// designFrictionRate: Double,
|
||||||
|
// projectSHR: Double,
|
||||||
retval.append(
|
// logger: Logger? = nil
|
||||||
.init(
|
// ) async throws -> [DuctSizing.RoomContainer] {
|
||||||
roomID: room.id,
|
//
|
||||||
roomName: "\(room.name)-\(n)",
|
// var retval: [DuctSizing.RoomContainer] = []
|
||||||
roomRegister: n,
|
// let totalHeatingLoad = rooms.totalHeatingLoad
|
||||||
heatingLoad: heatingLoad,
|
// let totalCoolingSensible = rooms.totalCoolingSensible(shr: projectSHR)
|
||||||
coolingLoad: coolingLoad,
|
//
|
||||||
heatingCFM: heatingCFM,
|
// for room in rooms {
|
||||||
coolingCFM: coolingCFM,
|
// let heatingLoad = room.heatingLoadPerRegister
|
||||||
designCFM: designCFM,
|
// let coolingLoad = room.coolingSensiblePerRegister(projectSHR: projectSHR)
|
||||||
roundSize: sizes.ductulatorSize,
|
// let heatingPercent = heatingLoad / totalHeatingLoad
|
||||||
finalSize: sizes.finalSize,
|
// let coolingPercent = coolingLoad / totalCoolingSensible
|
||||||
velocity: sizes.velocity,
|
// let heatingCFM = heatingPercent * Double(equipmentInfo.heatingCFM)
|
||||||
flexSize: sizes.flexSize,
|
// let coolingCFM = coolingPercent * Double(equipmentInfo.coolingCFM)
|
||||||
rectangularSize: rectangularSize,
|
// let designCFM = DuctSizing.DesignCFM(heating: heatingCFM, cooling: coolingCFM)
|
||||||
rectangularWidth: rectangularWidth
|
// let sizes = try await self.ductSize(
|
||||||
)
|
// .init(designCFM: Int(designCFM.value), frictionRate: designFrictionRate)
|
||||||
)
|
// )
|
||||||
}
|
//
|
||||||
}
|
// for n in 1...room.registerCount {
|
||||||
|
//
|
||||||
return retval
|
// var rectangularWidth: Int? = nil
|
||||||
}
|
// let rectangularSize = room.rectangularSizes?
|
||||||
|
// .first(where: { $0.register == nil || $0.register == n })
|
||||||
func calculateSizes(
|
//
|
||||||
rooms: [Room],
|
// if let rectangularSize {
|
||||||
trunks: [DuctSizing.TrunkSize],
|
// let response = try await self.equivalentRectangularDuct(
|
||||||
equipmentInfo: EquipmentInfo,
|
// .init(round: sizes.finalSize, height: rectangularSize.height)
|
||||||
maxSupplyLength: EffectiveLength,
|
// )
|
||||||
maxReturnLength: EffectiveLength,
|
// rectangularWidth = response.width
|
||||||
designFrictionRate: Double,
|
// }
|
||||||
projectSHR: Double,
|
//
|
||||||
logger: Logger? = nil
|
// retval.append(
|
||||||
) async throws -> [DuctSizing.TrunkContainer] {
|
// .init(
|
||||||
|
// roomID: room.id,
|
||||||
var retval = [DuctSizing.TrunkContainer]()
|
// roomName: "\(room.name)-\(n)",
|
||||||
let totalHeatingLoad = rooms.totalHeatingLoad
|
// roomRegister: n,
|
||||||
let totalCoolingSensible = rooms.totalCoolingSensible(shr: projectSHR)
|
// heatingLoad: heatingLoad,
|
||||||
|
// coolingLoad: coolingLoad,
|
||||||
for trunk in trunks {
|
// heatingCFM: heatingCFM,
|
||||||
let heatingLoad = trunk.totalHeatingLoad
|
// coolingCFM: coolingCFM,
|
||||||
let coolingLoad = trunk.totalCoolingSensible(projectSHR: projectSHR)
|
// designCFM: designCFM,
|
||||||
let heatingPercent = heatingLoad / totalHeatingLoad
|
// roundSize: sizes.ductulatorSize,
|
||||||
let coolingPercent = coolingLoad / totalCoolingSensible
|
// finalSize: sizes.finalSize,
|
||||||
let heatingCFM = heatingPercent * Double(equipmentInfo.heatingCFM)
|
// velocity: sizes.velocity,
|
||||||
let coolingCFM = coolingPercent * Double(equipmentInfo.coolingCFM)
|
// flexSize: sizes.flexSize,
|
||||||
let designCFM = DuctSizing.DesignCFM(heating: heatingCFM, cooling: coolingCFM)
|
// rectangularSize: rectangularSize,
|
||||||
let sizes = try await self.ductSize(
|
// rectangularWidth: rectangularWidth
|
||||||
.init(designCFM: Int(designCFM.value), frictionRate: designFrictionRate)
|
// )
|
||||||
)
|
// )
|
||||||
var width: Int? = nil
|
// }
|
||||||
if let height = trunk.height {
|
// }
|
||||||
let rectangularSize = try await self.equivalentRectangularDuct(
|
//
|
||||||
.init(round: sizes.finalSize, height: height)
|
// return retval
|
||||||
)
|
// }
|
||||||
width = rectangularSize.width
|
//
|
||||||
}
|
// func calculateTrunkSizes(
|
||||||
|
// rooms: [Room],
|
||||||
retval.append(
|
// trunks: [DuctSizing.TrunkSize],
|
||||||
.init(
|
// equipmentInfo: EquipmentInfo,
|
||||||
trunk: trunk,
|
// maxSupplyLength: EffectiveLength,
|
||||||
ductSize: .init(
|
// maxReturnLength: EffectiveLength,
|
||||||
designCFM: designCFM,
|
// designFrictionRate: Double,
|
||||||
roundSize: sizes.ductulatorSize,
|
// projectSHR: Double,
|
||||||
finalSize: sizes.finalSize,
|
// logger: Logger? = nil
|
||||||
velocity: sizes.velocity,
|
// ) async throws -> [DuctSizing.TrunkContainer] {
|
||||||
flexSize: sizes.flexSize,
|
//
|
||||||
height: trunk.height,
|
// var retval = [DuctSizing.TrunkContainer]()
|
||||||
width: width
|
// let totalHeatingLoad = rooms.totalHeatingLoad
|
||||||
)
|
// let totalCoolingSensible = rooms.totalCoolingSensible(shr: projectSHR)
|
||||||
)
|
//
|
||||||
)
|
// for trunk in trunks {
|
||||||
}
|
// let heatingLoad = trunk.totalHeatingLoad
|
||||||
|
// let coolingLoad = trunk.totalCoolingSensible(projectSHR: projectSHR)
|
||||||
return retval
|
// let heatingPercent = heatingLoad / totalHeatingLoad
|
||||||
}
|
// let coolingPercent = coolingLoad / totalCoolingSensible
|
||||||
|
// let heatingCFM = heatingPercent * Double(equipmentInfo.heatingCFM)
|
||||||
|
// let coolingCFM = coolingPercent * Double(equipmentInfo.coolingCFM)
|
||||||
|
// let designCFM = DuctSizing.DesignCFM(heating: heatingCFM, cooling: coolingCFM)
|
||||||
|
// let sizes = try await self.ductSize(
|
||||||
|
// .init(designCFM: Int(designCFM.value), frictionRate: designFrictionRate)
|
||||||
|
// )
|
||||||
|
// var width: Int? = nil
|
||||||
|
// if let height = trunk.height {
|
||||||
|
// let rectangularSize = try await self.equivalentRectangularDuct(
|
||||||
|
// .init(round: sizes.finalSize, height: height)
|
||||||
|
// )
|
||||||
|
// width = rectangularSize.width
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// retval.append(
|
||||||
|
// .init(
|
||||||
|
// trunk: trunk,
|
||||||
|
// ductSize: .init(
|
||||||
|
// designCFM: designCFM,
|
||||||
|
// roundSize: sizes.ductulatorSize,
|
||||||
|
// finalSize: sizes.finalSize,
|
||||||
|
// velocity: sizes.velocity,
|
||||||
|
// flexSize: sizes.flexSize,
|
||||||
|
// height: trunk.height,
|
||||||
|
// width: width
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return retval
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,15 +174,27 @@ extension ManualDClient: TestDependencyKey {
|
|||||||
public static let testValue = Self()
|
public static let testValue = Self()
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DependencyValues {
|
// MARK: Project Response
|
||||||
public var manualD: ManualDClient {
|
// extension ManualDClient {
|
||||||
get { self[ManualDClient.self] }
|
//
|
||||||
set { self[ManualDClient.self] = newValue }
|
// public struct ProjectResponse: Codable, Equatable, Sendable {
|
||||||
}
|
// public let rooms: [DuctSizing.RoomContainer]
|
||||||
}
|
// public let trunks: [DuctSizing.TrunkContainer]
|
||||||
|
//
|
||||||
|
// public init(
|
||||||
|
// rooms: [DuctSizing.RoomContainer],
|
||||||
|
// trunks: [DuctSizing.TrunkContainer]
|
||||||
|
// ) {
|
||||||
|
// self.rooms = rooms
|
||||||
|
// self.trunks = trunks
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
// MARK: Duct Size
|
// MARK: Duct Size
|
||||||
extension ManualDClient {
|
extension ManualDClient {
|
||||||
|
|
||||||
public struct DuctSizeRequest: Codable, Equatable, Sendable {
|
public struct DuctSizeRequest: Codable, Equatable, Sendable {
|
||||||
public let designCFM: Int
|
public let designCFM: Int
|
||||||
public let frictionRate: Double
|
public let frictionRate: Double
|
||||||
|
|||||||
@@ -3,26 +3,9 @@ import Foundation
|
|||||||
|
|
||||||
public enum DuctSizing {
|
public enum DuctSizing {
|
||||||
|
|
||||||
public struct RectangularDuct: Codable, Equatable, Identifiable, Sendable {
|
|
||||||
|
|
||||||
public let id: UUID
|
|
||||||
public let register: Int?
|
|
||||||
public let height: Int
|
|
||||||
|
|
||||||
public init(
|
|
||||||
id: UUID = .init(),
|
|
||||||
register: Int? = nil,
|
|
||||||
height: Int,
|
|
||||||
) {
|
|
||||||
self.id = id
|
|
||||||
self.register = register
|
|
||||||
self.height = height
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct SizeContainer: Codable, Equatable, Sendable {
|
public struct SizeContainer: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
public let rectangularID: Room.RectangularSize.ID?
|
||||||
public let designCFM: DesignCFM
|
public let designCFM: DesignCFM
|
||||||
public let roundSize: Double
|
public let roundSize: Double
|
||||||
public let finalSize: Int
|
public let finalSize: Int
|
||||||
@@ -32,6 +15,7 @@ public enum DuctSizing {
|
|||||||
public let width: Int?
|
public let width: Int?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
|
rectangularID: Room.RectangularSize.ID? = nil,
|
||||||
designCFM: DuctSizing.DesignCFM,
|
designCFM: DuctSizing.DesignCFM,
|
||||||
roundSize: Double,
|
roundSize: Double,
|
||||||
finalSize: Int,
|
finalSize: Int,
|
||||||
@@ -40,6 +24,7 @@ public enum DuctSizing {
|
|||||||
height: Int? = nil,
|
height: Int? = nil,
|
||||||
width: Int? = nil
|
width: Int? = nil
|
||||||
) {
|
) {
|
||||||
|
self.rectangularID = rectangularID
|
||||||
self.designCFM = designCFM
|
self.designCFM = designCFM
|
||||||
self.roundSize = roundSize
|
self.roundSize = roundSize
|
||||||
self.finalSize = finalSize
|
self.finalSize = finalSize
|
||||||
@@ -52,6 +37,7 @@ public enum DuctSizing {
|
|||||||
|
|
||||||
// TODO: Uses SizeContainer
|
// TODO: Uses SizeContainer
|
||||||
|
|
||||||
|
@dynamicMemberLookup
|
||||||
public struct RoomContainer: Codable, Equatable, Sendable {
|
public struct RoomContainer: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
public let roomID: Room.ID
|
public let roomID: Room.ID
|
||||||
@@ -61,13 +47,7 @@ public enum DuctSizing {
|
|||||||
public let coolingLoad: Double
|
public let coolingLoad: Double
|
||||||
public let heatingCFM: Double
|
public let heatingCFM: Double
|
||||||
public let coolingCFM: Double
|
public let coolingCFM: Double
|
||||||
public let designCFM: DesignCFM
|
public let ductSize: SizeContainer
|
||||||
public let roundSize: Double
|
|
||||||
public let finalSize: Int
|
|
||||||
public let velocity: Int
|
|
||||||
public let flexSize: Int
|
|
||||||
public let rectangularSize: RectangularDuct?
|
|
||||||
public let rectangularWidth: Int?
|
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
roomID: Room.ID,
|
roomID: Room.ID,
|
||||||
@@ -77,13 +57,7 @@ public enum DuctSizing {
|
|||||||
coolingLoad: Double,
|
coolingLoad: Double,
|
||||||
heatingCFM: Double,
|
heatingCFM: Double,
|
||||||
coolingCFM: Double,
|
coolingCFM: Double,
|
||||||
designCFM: DesignCFM,
|
ductSize: SizeContainer
|
||||||
roundSize: Double,
|
|
||||||
finalSize: Int,
|
|
||||||
velocity: Int,
|
|
||||||
flexSize: Int,
|
|
||||||
rectangularSize: RectangularDuct? = nil,
|
|
||||||
rectangularWidth: Int? = nil
|
|
||||||
) {
|
) {
|
||||||
self.roomID = roomID
|
self.roomID = roomID
|
||||||
self.roomName = roomName
|
self.roomName = roomName
|
||||||
@@ -92,13 +66,11 @@ public enum DuctSizing {
|
|||||||
self.coolingLoad = coolingLoad
|
self.coolingLoad = coolingLoad
|
||||||
self.heatingCFM = heatingCFM
|
self.heatingCFM = heatingCFM
|
||||||
self.coolingCFM = coolingCFM
|
self.coolingCFM = coolingCFM
|
||||||
self.designCFM = designCFM
|
self.ductSize = ductSize
|
||||||
self.roundSize = roundSize
|
}
|
||||||
self.finalSize = finalSize
|
|
||||||
self.velocity = velocity
|
public subscript<T>(dynamicMember keyPath: KeyPath<DuctSizing.SizeContainer, T>) -> T {
|
||||||
self.flexSize = flexSize
|
ductSize[keyPath: keyPath]
|
||||||
self.rectangularSize = rectangularSize
|
|
||||||
self.rectangularWidth = rectangularWidth
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +114,7 @@ extension DuctSizing {
|
|||||||
self.ductSize = ductSize
|
self.ductSize = ductSize
|
||||||
}
|
}
|
||||||
|
|
||||||
public subscript<T>(dynamicMember keyPath: KeyPath<DuctSizing.TrunkSize, T>) -> T {
|
public subscript<T>(dynamicMember keyPath: KeyPath<TrunkSize, T>) -> T {
|
||||||
trunk[keyPath: keyPath]
|
trunk[keyPath: keyPath]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,99 +122,4 @@ extension DuctSizing {
|
|||||||
ductSize[keyPath: keyPath]
|
ductSize[keyPath: keyPath]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add an optional label that the user can set.
|
|
||||||
|
|
||||||
// Represents the database model.
|
|
||||||
public struct TrunkSize: Codable, Equatable, Identifiable, Sendable {
|
|
||||||
|
|
||||||
public let id: UUID
|
|
||||||
public let projectID: Project.ID
|
|
||||||
public let type: TrunkType
|
|
||||||
public let rooms: [RoomProxy]
|
|
||||||
public let height: Int?
|
|
||||||
public let name: String?
|
|
||||||
|
|
||||||
public init(
|
|
||||||
id: UUID,
|
|
||||||
projectID: Project.ID,
|
|
||||||
type: DuctSizing.TrunkSize.TrunkType,
|
|
||||||
rooms: [DuctSizing.TrunkSize.RoomProxy],
|
|
||||||
height: Int? = nil,
|
|
||||||
name: String? = nil
|
|
||||||
) {
|
|
||||||
self.id = id
|
|
||||||
self.projectID = projectID
|
|
||||||
self.type = type
|
|
||||||
self.rooms = rooms
|
|
||||||
self.height = height
|
|
||||||
self.name = name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension DuctSizing.TrunkSize {
|
|
||||||
public struct Create: Codable, Equatable, Sendable {
|
|
||||||
|
|
||||||
public let projectID: Project.ID
|
|
||||||
public let type: TrunkType
|
|
||||||
public let rooms: [Room.ID: [Int]]
|
|
||||||
public let height: Int?
|
|
||||||
public let name: String?
|
|
||||||
|
|
||||||
public init(
|
|
||||||
projectID: Project.ID,
|
|
||||||
type: DuctSizing.TrunkSize.TrunkType,
|
|
||||||
rooms: [Room.ID: [Int]],
|
|
||||||
height: Int? = nil,
|
|
||||||
name: String? = nil
|
|
||||||
) {
|
|
||||||
self.projectID = projectID
|
|
||||||
self.type = type
|
|
||||||
self.rooms = rooms
|
|
||||||
self.height = height
|
|
||||||
self.name = name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct Update: Codable, Equatable, Sendable {
|
|
||||||
|
|
||||||
public let type: TrunkType?
|
|
||||||
public let rooms: [Room.ID: [Int]]?
|
|
||||||
public let height: Int?
|
|
||||||
public let name: String?
|
|
||||||
|
|
||||||
public init(
|
|
||||||
type: DuctSizing.TrunkSize.TrunkType? = nil,
|
|
||||||
rooms: [Room.ID: [Int]]? = nil,
|
|
||||||
height: Int? = nil,
|
|
||||||
name: String? = nil
|
|
||||||
) {
|
|
||||||
self.type = type
|
|
||||||
self.rooms = rooms
|
|
||||||
self.height = height
|
|
||||||
self.name = name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Make registers non-optional
|
|
||||||
public struct RoomProxy: Codable, Equatable, Identifiable, Sendable {
|
|
||||||
|
|
||||||
public var id: Room.ID { room.id }
|
|
||||||
public let room: Room
|
|
||||||
public let registers: [Int]
|
|
||||||
|
|
||||||
public init(room: Room, registers: [Int]) {
|
|
||||||
self.room = room
|
|
||||||
self.registers = registers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TrunkType: String, CaseIterable, Codable, Equatable, Sendable {
|
|
||||||
case `return`
|
|
||||||
case supply
|
|
||||||
|
|
||||||
public static let allCases = [Self.supply, .return]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
Sources/ManualDCore/PageRequest+extensions.swift
Normal file
12
Sources/ManualDCore/PageRequest+extensions.swift
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import Fluent
|
||||||
|
|
||||||
|
extension PageRequest {
|
||||||
|
|
||||||
|
public static var first: Self {
|
||||||
|
.init(page: 1, per: 25)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func next<T>(_ currentPage: Page<T>) -> Self {
|
||||||
|
.init(page: currentPage.metadata.page + 1, per: currentPage.metadata.per)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
|
|||||||
public let coolingTotal: Double
|
public let coolingTotal: Double
|
||||||
public let coolingSensible: Double?
|
public let coolingSensible: Double?
|
||||||
public let registerCount: Int
|
public let registerCount: Int
|
||||||
public let rectangularSizes: [DuctSizing.RectangularDuct]?
|
public let rectangularSizes: [RectangularSize]?
|
||||||
public let createdAt: Date
|
public let createdAt: Date
|
||||||
public let updatedAt: Date
|
public let updatedAt: Date
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
|
|||||||
coolingTotal: Double,
|
coolingTotal: Double,
|
||||||
coolingSensible: Double? = nil,
|
coolingSensible: Double? = nil,
|
||||||
registerCount: Int = 1,
|
registerCount: Int = 1,
|
||||||
rectangularSizes: [DuctSizing.RectangularDuct]? = nil,
|
rectangularSizes: [RectangularSize]? = nil,
|
||||||
createdAt: Date,
|
createdAt: Date,
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
) {
|
) {
|
||||||
@@ -65,13 +65,30 @@ extension Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct RectangularSize: Codable, Equatable, Identifiable, Sendable {
|
||||||
|
|
||||||
|
public let id: UUID
|
||||||
|
public let register: Int?
|
||||||
|
public let height: Int
|
||||||
|
|
||||||
|
public init(
|
||||||
|
id: UUID = .init(),
|
||||||
|
register: Int? = nil,
|
||||||
|
height: Int,
|
||||||
|
) {
|
||||||
|
self.id = id
|
||||||
|
self.register = register
|
||||||
|
self.height = height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public struct Update: Codable, Equatable, Sendable {
|
public struct Update: Codable, Equatable, Sendable {
|
||||||
public let name: String?
|
public let name: String?
|
||||||
public let heatingLoad: Double?
|
public let heatingLoad: Double?
|
||||||
public let coolingTotal: Double?
|
public let coolingTotal: Double?
|
||||||
public let coolingSensible: Double?
|
public let coolingSensible: Double?
|
||||||
public let registerCount: Int?
|
public let registerCount: Int?
|
||||||
public let rectangularSizes: [DuctSizing.RectangularDuct]?
|
public let rectangularSizes: [RectangularSize]?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
name: String? = nil,
|
name: String? = nil,
|
||||||
@@ -89,7 +106,7 @@ extension Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
rectangularSizes: [DuctSizing.RectangularDuct]
|
rectangularSizes: [RectangularSize]
|
||||||
) {
|
) {
|
||||||
self.name = nil
|
self.name = nil
|
||||||
self.heatingLoad = nil
|
self.heatingLoad = nil
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
}
|
}
|
||||||
Method.delete
|
Method.delete
|
||||||
Query {
|
Query {
|
||||||
Field("rectangularSize") { DuctSizing.RectangularDuct.ID.parser() }
|
Field("rectangularSize") { Room.RectangularSize.ID.parser() }
|
||||||
Field("register") { Int.parser() }
|
Field("register") { Int.parser() }
|
||||||
}
|
}
|
||||||
.map(.memberwise(DeleteRectangularDuct.init))
|
.map(.memberwise(DeleteRectangularDuct.init))
|
||||||
@@ -642,7 +642,7 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
Body {
|
Body {
|
||||||
FormData {
|
FormData {
|
||||||
Optionally {
|
Optionally {
|
||||||
Field("id") { DuctSizing.RectangularDuct.ID.parser() }
|
Field("id") { Room.RectangularSize.ID.parser() }
|
||||||
}
|
}
|
||||||
Field("register") { Int.parser() }
|
Field("register") { Int.parser() }
|
||||||
Field("height") { Int.parser() }
|
Field("height") { Int.parser() }
|
||||||
@@ -658,19 +658,19 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
|
|
||||||
public struct DeleteRectangularDuct: Equatable, Sendable {
|
public struct DeleteRectangularDuct: Equatable, Sendable {
|
||||||
|
|
||||||
public let rectangularSizeID: DuctSizing.RectangularDuct.ID
|
public let rectangularSizeID: Room.RectangularSize.ID
|
||||||
public let register: Int
|
public let register: Int
|
||||||
|
|
||||||
public init(rectangularSizeID: DuctSizing.RectangularDuct.ID, register: Int) {
|
public init(rectangularSizeID: Room.RectangularSize.ID, register: Int) {
|
||||||
self.rectangularSizeID = rectangularSizeID
|
self.rectangularSizeID = rectangularSizeID
|
||||||
self.register = register
|
self.register = register
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TrunkRoute: Equatable, Sendable {
|
public enum TrunkRoute: Equatable, Sendable {
|
||||||
case delete(DuctSizing.TrunkSize.ID)
|
case delete(TrunkSize.ID)
|
||||||
case submit(TrunkSizeForm)
|
case submit(TrunkSizeForm)
|
||||||
case update(DuctSizing.TrunkSize.ID, TrunkSizeForm)
|
case update(TrunkSize.ID, TrunkSizeForm)
|
||||||
|
|
||||||
public static let rootPath = "trunk"
|
public static let rootPath = "trunk"
|
||||||
|
|
||||||
@@ -678,7 +678,7 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
Route(.case(Self.delete)) {
|
Route(.case(Self.delete)) {
|
||||||
Path {
|
Path {
|
||||||
rootPath
|
rootPath
|
||||||
DuctSizing.TrunkSize.ID.parser()
|
TrunkSize.ID.parser()
|
||||||
}
|
}
|
||||||
Method.delete
|
Method.delete
|
||||||
}
|
}
|
||||||
@@ -690,7 +690,7 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
Body {
|
Body {
|
||||||
FormData {
|
FormData {
|
||||||
Field("projectID") { Project.ID.parser() }
|
Field("projectID") { Project.ID.parser() }
|
||||||
Field("type") { DuctSizing.TrunkSize.TrunkType.parser() }
|
Field("type") { TrunkSize.TrunkType.parser() }
|
||||||
Optionally {
|
Optionally {
|
||||||
Field("height") { Int.parser() }
|
Field("height") { Int.parser() }
|
||||||
|
|
||||||
@@ -708,13 +708,13 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
Route(.case(Self.update)) {
|
Route(.case(Self.update)) {
|
||||||
Path {
|
Path {
|
||||||
rootPath
|
rootPath
|
||||||
DuctSizing.TrunkSize.ID.parser()
|
TrunkSize.ID.parser()
|
||||||
}
|
}
|
||||||
Method.patch
|
Method.patch
|
||||||
Body {
|
Body {
|
||||||
FormData {
|
FormData {
|
||||||
Field("projectID") { Project.ID.parser() }
|
Field("projectID") { Project.ID.parser() }
|
||||||
Field("type") { DuctSizing.TrunkSize.TrunkType.parser() }
|
Field("type") { TrunkSize.TrunkType.parser() }
|
||||||
Optionally {
|
Optionally {
|
||||||
Field("height") { Int.parser() }
|
Field("height") { Int.parser() }
|
||||||
}
|
}
|
||||||
@@ -732,17 +732,43 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct RoomRectangularForm: Equatable, Sendable {
|
public struct RoomRectangularForm: Equatable, Sendable {
|
||||||
public let id: DuctSizing.RectangularDuct.ID?
|
|
||||||
|
public let id: Room.RectangularSize.ID?
|
||||||
public let register: Int
|
public let register: Int
|
||||||
public let height: Int
|
public let height: Int
|
||||||
|
|
||||||
|
public init(
|
||||||
|
id: Room.RectangularSize.ID? = nil,
|
||||||
|
register: Int,
|
||||||
|
height: Int
|
||||||
|
) {
|
||||||
|
self.id = id
|
||||||
|
self.register = register
|
||||||
|
self.height = height
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct TrunkSizeForm: Equatable, Sendable {
|
public struct TrunkSizeForm: Equatable, Sendable {
|
||||||
|
|
||||||
public let projectID: Project.ID
|
public let projectID: Project.ID
|
||||||
public let type: DuctSizing.TrunkSize.TrunkType
|
public let type: TrunkSize.TrunkType
|
||||||
public let height: Int?
|
public let height: Int?
|
||||||
public let name: String?
|
public let name: String?
|
||||||
public let rooms: [String]
|
public let rooms: [String]
|
||||||
|
|
||||||
|
public init(
|
||||||
|
projectID: Project.ID,
|
||||||
|
type: TrunkSize.TrunkType,
|
||||||
|
height: Int? = nil,
|
||||||
|
name: String? = nil,
|
||||||
|
rooms: [String]
|
||||||
|
) {
|
||||||
|
self.projectID = projectID
|
||||||
|
self.type = type
|
||||||
|
self.height = height
|
||||||
|
self.name = name
|
||||||
|
self.rooms = rooms
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
93
Sources/ManualDCore/TrunkSize.swift
Normal file
93
Sources/ManualDCore/TrunkSize.swift
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
// Represents the database model.
|
||||||
|
public struct TrunkSize: Codable, Equatable, Identifiable, Sendable {
|
||||||
|
|
||||||
|
public let id: UUID
|
||||||
|
public let projectID: Project.ID
|
||||||
|
public let type: TrunkType
|
||||||
|
public let rooms: [RoomProxy]
|
||||||
|
public let height: Int?
|
||||||
|
public let name: String?
|
||||||
|
|
||||||
|
public init(
|
||||||
|
id: UUID,
|
||||||
|
projectID: Project.ID,
|
||||||
|
type: TrunkType,
|
||||||
|
rooms: [RoomProxy],
|
||||||
|
height: Int? = nil,
|
||||||
|
name: String? = nil
|
||||||
|
) {
|
||||||
|
self.id = id
|
||||||
|
self.projectID = projectID
|
||||||
|
self.type = type
|
||||||
|
self.rooms = rooms
|
||||||
|
self.height = height
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension TrunkSize {
|
||||||
|
public struct Create: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
public let projectID: Project.ID
|
||||||
|
public let type: TrunkType
|
||||||
|
public let rooms: [Room.ID: [Int]]
|
||||||
|
public let height: Int?
|
||||||
|
public let name: String?
|
||||||
|
|
||||||
|
public init(
|
||||||
|
projectID: Project.ID,
|
||||||
|
type: TrunkType,
|
||||||
|
rooms: [Room.ID: [Int]],
|
||||||
|
height: Int? = nil,
|
||||||
|
name: String? = nil
|
||||||
|
) {
|
||||||
|
self.projectID = projectID
|
||||||
|
self.type = type
|
||||||
|
self.rooms = rooms
|
||||||
|
self.height = height
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Update: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
public let type: TrunkType?
|
||||||
|
public let rooms: [Room.ID: [Int]]?
|
||||||
|
public let height: Int?
|
||||||
|
public let name: String?
|
||||||
|
|
||||||
|
public init(
|
||||||
|
type: TrunkType? = nil,
|
||||||
|
rooms: [Room.ID: [Int]]? = nil,
|
||||||
|
height: Int? = nil,
|
||||||
|
name: String? = nil
|
||||||
|
) {
|
||||||
|
self.type = type
|
||||||
|
self.rooms = rooms
|
||||||
|
self.height = height
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Make registers non-optional
|
||||||
|
public struct RoomProxy: Codable, Equatable, Identifiable, Sendable {
|
||||||
|
|
||||||
|
public var id: Room.ID { room.id }
|
||||||
|
public let room: Room
|
||||||
|
public let registers: [Int]
|
||||||
|
|
||||||
|
public init(room: Room, registers: [Int]) {
|
||||||
|
self.room = room
|
||||||
|
self.registers = registers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TrunkType: String, CaseIterable, Codable, Equatable, Sendable {
|
||||||
|
case `return`
|
||||||
|
case supply
|
||||||
|
|
||||||
|
public static let allCases = [Self.supply, .return]
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Sources/ProjectClient/DuctCalcClientError.swift
Normal file
9
Sources/ProjectClient/DuctCalcClientError.swift
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct ProjectClientError: Error {
|
||||||
|
public let reason: String
|
||||||
|
|
||||||
|
public init(_ reason: String) {
|
||||||
|
self.reason = reason
|
||||||
|
}
|
||||||
|
}
|
||||||
86
Sources/ProjectClient/Interface.swift
Normal file
86
Sources/ProjectClient/Interface.swift
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import Dependencies
|
||||||
|
import DependenciesMacros
|
||||||
|
import ManualDClient
|
||||||
|
import ManualDCore
|
||||||
|
|
||||||
|
extension DependencyValues {
|
||||||
|
public var projectClient: ProjectClient {
|
||||||
|
get { self[ProjectClient.self] }
|
||||||
|
set { self[ProjectClient.self] = newValue }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Useful helper utilities for project's.
|
||||||
|
///
|
||||||
|
/// This is primarily used for implementing logic required to get the needed data
|
||||||
|
/// for the view controller client to render views.
|
||||||
|
@DependencyClient
|
||||||
|
public struct ProjectClient: Sendable {
|
||||||
|
public var calculateDuctSizes: @Sendable (Project.ID) async throws -> DuctSizeResponse
|
||||||
|
public var calculateRoomDuctSizes:
|
||||||
|
@Sendable (Project.ID) async throws -> [DuctSizing.RoomContainer]
|
||||||
|
public var calculateTrunkDuctSizes:
|
||||||
|
@Sendable (Project.ID) async throws -> [DuctSizing.TrunkContainer]
|
||||||
|
|
||||||
|
public var createProject:
|
||||||
|
@Sendable (User.ID, Project.Create) async throws -> CreateProjectResponse
|
||||||
|
|
||||||
|
public var frictionRate: @Sendable (Project.ID) async throws -> FrictionRateResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ProjectClient: TestDependencyKey {
|
||||||
|
public static let testValue = Self()
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ProjectClient {
|
||||||
|
|
||||||
|
public struct CreateProjectResponse: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
public let projectID: Project.ID
|
||||||
|
public let rooms: [Room]
|
||||||
|
public let sensibleHeatRatio: Double?
|
||||||
|
public let completedSteps: Project.CompletedSteps
|
||||||
|
|
||||||
|
public init(
|
||||||
|
projectID: Project.ID,
|
||||||
|
rooms: [Room],
|
||||||
|
sensibleHeatRatio: Double? = nil,
|
||||||
|
completedSteps: Project.CompletedSteps
|
||||||
|
) {
|
||||||
|
self.projectID = projectID
|
||||||
|
self.rooms = rooms
|
||||||
|
self.sensibleHeatRatio = sensibleHeatRatio
|
||||||
|
self.completedSteps = completedSteps
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DuctSizeResponse: Codable, Equatable, Sendable {
|
||||||
|
public let rooms: [DuctSizing.RoomContainer]
|
||||||
|
public let trunks: [DuctSizing.TrunkContainer]
|
||||||
|
|
||||||
|
public init(
|
||||||
|
rooms: [DuctSizing.RoomContainer],
|
||||||
|
trunks: [DuctSizing.TrunkContainer]
|
||||||
|
) {
|
||||||
|
self.rooms = rooms
|
||||||
|
self.trunks = trunks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct FrictionRateResponse: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
public let componentLosses: [ComponentPressureLoss]
|
||||||
|
public let equivalentLengths: EffectiveLength.MaxContainer
|
||||||
|
public let frictionRate: ManualDClient.FrictionRateResponse?
|
||||||
|
|
||||||
|
public init(
|
||||||
|
componentLosses: [ComponentPressureLoss],
|
||||||
|
equivalentLengths: EffectiveLength.MaxContainer,
|
||||||
|
frictionRate: ManualDClient.FrictionRateResponse? = nil
|
||||||
|
) {
|
||||||
|
self.componentLosses = componentLosses
|
||||||
|
self.equivalentLengths = equivalentLengths
|
||||||
|
self.frictionRate = frictionRate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import ManualDCore
|
||||||
|
|
||||||
|
extension DatabaseClient.ComponentLoss {
|
||||||
|
|
||||||
|
func createDefaults(projectID: Project.ID) async throws {
|
||||||
|
let defaults = ComponentPressureLoss.Create.default(projectID: projectID)
|
||||||
|
for loss in defaults {
|
||||||
|
_ = try await create(loss)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import Dependencies
|
||||||
|
import ManualDClient
|
||||||
|
import ManualDCore
|
||||||
|
|
||||||
|
extension DatabaseClient {
|
||||||
|
|
||||||
|
func calculateDuctSizes(
|
||||||
|
projectID: Project.ID
|
||||||
|
) async throws -> ProjectClient.DuctSizeResponse {
|
||||||
|
@Dependency(\.manualD) var manualD
|
||||||
|
|
||||||
|
return try await manualD.calculateDuctSizes(
|
||||||
|
rooms: rooms.fetch(projectID),
|
||||||
|
trunks: trunkSizes.fetch(projectID),
|
||||||
|
sharedRequest: sharedDuctRequest(projectID)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateRoomDuctSizes(
|
||||||
|
projectID: Project.ID
|
||||||
|
) async throws -> [DuctSizing.RoomContainer] {
|
||||||
|
@Dependency(\.manualD) var manualD
|
||||||
|
|
||||||
|
return try await manualD.calculateRoomSizes(
|
||||||
|
rooms: rooms.fetch(projectID),
|
||||||
|
sharedRequest: sharedDuctRequest(projectID)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateTrunkDuctSizes(
|
||||||
|
projectID: Project.ID
|
||||||
|
) async throws -> [DuctSizing.TrunkContainer] {
|
||||||
|
@Dependency(\.manualD) var manualD
|
||||||
|
|
||||||
|
return try await manualD.calculateTrunkSizes(
|
||||||
|
rooms: rooms.fetch(projectID),
|
||||||
|
trunks: trunkSizes.fetch(projectID),
|
||||||
|
sharedRequest: sharedDuctRequest(projectID)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sharedDuctRequest(_ projectID: Project.ID) async throws -> DuctSizeSharedRequest {
|
||||||
|
|
||||||
|
guard let dfrResponse = try await designFrictionRate(projectID: projectID) else {
|
||||||
|
throw ProjectClientError("Project not complete.")
|
||||||
|
}
|
||||||
|
|
||||||
|
let ensuredTEL = try dfrResponse.ensureMaxContainer()
|
||||||
|
|
||||||
|
return try await .init(
|
||||||
|
equipmentInfo: dfrResponse.equipmentInfo,
|
||||||
|
maxSupplyLength: ensuredTEL.supply,
|
||||||
|
maxReturnLenght: ensuredTEL.return,
|
||||||
|
designFrictionRate: dfrResponse.designFrictionRate,
|
||||||
|
projectSHR: ensuredSHR(projectID)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetches the project sensible heat ratio or throws an error if it's nil.
|
||||||
|
func ensuredSHR(_ projectID: Project.ID) async throws -> Double {
|
||||||
|
guard let projectSHR = try await projects.getSensibleHeatRatio(projectID) else {
|
||||||
|
throw ProjectClientError("Project sensible heat ratio not set.")
|
||||||
|
}
|
||||||
|
return projectSHR
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal container.
|
||||||
|
struct DesignFrictionRateResponse: Equatable, Sendable {
|
||||||
|
|
||||||
|
typealias EnsuredTEL = (supply: EffectiveLength, return: EffectiveLength)
|
||||||
|
|
||||||
|
let designFrictionRate: Double
|
||||||
|
let equipmentInfo: EquipmentInfo
|
||||||
|
let telMaxContainer: EffectiveLength.MaxContainer
|
||||||
|
|
||||||
|
func ensureMaxContainer() throws -> EnsuredTEL {
|
||||||
|
|
||||||
|
guard let maxSupplyLength = telMaxContainer.supply else {
|
||||||
|
throw ProjectClientError("Max supply TEL not found")
|
||||||
|
}
|
||||||
|
guard let maxReturnLength = telMaxContainer.return else {
|
||||||
|
throw ProjectClientError("Max supply TEL not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return (maxSupplyLength, maxReturnLength)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func designFrictionRate(
|
||||||
|
projectID: Project.ID
|
||||||
|
) async throws -> DesignFrictionRateResponse? {
|
||||||
|
guard let equipmentInfo = try await equipment.fetch(projectID) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let equivalentLengths = try await effectiveLength.fetchMax(projectID)
|
||||||
|
guard let tel = equivalentLengths.total else { return nil }
|
||||||
|
|
||||||
|
let componentLosses = try await componentLoss.fetch(projectID)
|
||||||
|
guard componentLosses.count > 0 else { return nil }
|
||||||
|
|
||||||
|
let availableStaticPressure =
|
||||||
|
equipmentInfo.staticPressure - componentLosses.total
|
||||||
|
|
||||||
|
return .init(
|
||||||
|
designFrictionRate: (availableStaticPressure * 100) / tel,
|
||||||
|
equipmentInfo: equipmentInfo,
|
||||||
|
telMaxContainer: equivalentLengths
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,223 @@
|
|||||||
|
import Logging
|
||||||
|
import ManualDClient
|
||||||
|
import ManualDCore
|
||||||
|
|
||||||
|
struct DuctSizeSharedRequest {
|
||||||
|
let equipmentInfo: EquipmentInfo
|
||||||
|
let maxSupplyLength: EffectiveLength
|
||||||
|
let maxReturnLenght: EffectiveLength
|
||||||
|
let designFrictionRate: Double
|
||||||
|
let projectSHR: Double
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove Logger and use depedency logger.
|
||||||
|
|
||||||
|
extension ManualDClient {
|
||||||
|
|
||||||
|
func calculateDuctSizes(
|
||||||
|
rooms: [Room],
|
||||||
|
trunks: [TrunkSize],
|
||||||
|
sharedRequest: DuctSizeSharedRequest,
|
||||||
|
logger: Logger? = nil
|
||||||
|
) async throws -> ProjectClient.DuctSizeResponse {
|
||||||
|
try await .init(
|
||||||
|
rooms: calculateRoomSizes(
|
||||||
|
rooms: rooms,
|
||||||
|
sharedRequest: sharedRequest
|
||||||
|
),
|
||||||
|
trunks: calculateTrunkSizes(
|
||||||
|
rooms: rooms,
|
||||||
|
trunks: trunks,
|
||||||
|
sharedRequest: sharedRequest
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateRoomSizes(
|
||||||
|
rooms: [Room],
|
||||||
|
sharedRequest: DuctSizeSharedRequest,
|
||||||
|
logger: Logger? = nil
|
||||||
|
) async throws -> [DuctSizing.RoomContainer] {
|
||||||
|
|
||||||
|
var retval: [DuctSizing.RoomContainer] = []
|
||||||
|
let totalHeatingLoad = rooms.totalHeatingLoad
|
||||||
|
let totalCoolingSensible = rooms.totalCoolingSensible(shr: sharedRequest.projectSHR)
|
||||||
|
|
||||||
|
for room in rooms {
|
||||||
|
let heatingLoad = room.heatingLoadPerRegister
|
||||||
|
let coolingLoad = room.coolingSensiblePerRegister(projectSHR: sharedRequest.projectSHR)
|
||||||
|
let heatingPercent = heatingLoad / totalHeatingLoad
|
||||||
|
let coolingPercent = coolingLoad / totalCoolingSensible
|
||||||
|
let heatingCFM = heatingPercent * Double(sharedRequest.equipmentInfo.heatingCFM)
|
||||||
|
let coolingCFM = coolingPercent * Double(sharedRequest.equipmentInfo.coolingCFM)
|
||||||
|
let designCFM = DuctSizing.DesignCFM(heating: heatingCFM, cooling: coolingCFM)
|
||||||
|
let sizes = try await self.ductSize(
|
||||||
|
.init(designCFM: Int(designCFM.value), frictionRate: sharedRequest.designFrictionRate)
|
||||||
|
)
|
||||||
|
|
||||||
|
for n in 1...room.registerCount {
|
||||||
|
|
||||||
|
var rectangularWidth: Int? = nil
|
||||||
|
let rectangularSize = room.rectangularSizes?
|
||||||
|
.first(where: { $0.register == nil || $0.register == n })
|
||||||
|
|
||||||
|
if let rectangularSize {
|
||||||
|
let response = try await self.equivalentRectangularDuct(
|
||||||
|
.init(round: sizes.finalSize, height: rectangularSize.height)
|
||||||
|
)
|
||||||
|
rectangularWidth = response.width
|
||||||
|
}
|
||||||
|
|
||||||
|
retval.append(
|
||||||
|
.init(
|
||||||
|
roomID: room.id,
|
||||||
|
roomName: "\(room.name)-\(n)",
|
||||||
|
roomRegister: n,
|
||||||
|
heatingLoad: heatingLoad,
|
||||||
|
coolingLoad: coolingLoad,
|
||||||
|
heatingCFM: heatingCFM,
|
||||||
|
coolingCFM: coolingCFM,
|
||||||
|
ductSize: .init(
|
||||||
|
designCFM: designCFM,
|
||||||
|
sizes: sizes,
|
||||||
|
rectangularSize: rectangularSize,
|
||||||
|
width: rectangularWidth
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateTrunkSizes(
|
||||||
|
rooms: [Room],
|
||||||
|
trunks: [TrunkSize],
|
||||||
|
sharedRequest: DuctSizeSharedRequest,
|
||||||
|
logger: Logger? = nil
|
||||||
|
) async throws -> [DuctSizing.TrunkContainer] {
|
||||||
|
|
||||||
|
var retval = [DuctSizing.TrunkContainer]()
|
||||||
|
let totalHeatingLoad = rooms.totalHeatingLoad
|
||||||
|
let totalCoolingSensible = rooms.totalCoolingSensible(shr: sharedRequest.projectSHR)
|
||||||
|
|
||||||
|
for trunk in trunks {
|
||||||
|
let heatingLoad = trunk.totalHeatingLoad
|
||||||
|
let coolingLoad = trunk.totalCoolingSensible(projectSHR: sharedRequest.projectSHR)
|
||||||
|
let heatingPercent = heatingLoad / totalHeatingLoad
|
||||||
|
let coolingPercent = coolingLoad / totalCoolingSensible
|
||||||
|
let heatingCFM = heatingPercent * Double(sharedRequest.equipmentInfo.heatingCFM)
|
||||||
|
let coolingCFM = coolingPercent * Double(sharedRequest.equipmentInfo.coolingCFM)
|
||||||
|
let designCFM = DuctSizing.DesignCFM(heating: heatingCFM, cooling: coolingCFM)
|
||||||
|
let sizes = try await self.ductSize(
|
||||||
|
.init(designCFM: Int(designCFM.value), frictionRate: sharedRequest.designFrictionRate)
|
||||||
|
)
|
||||||
|
var width: Int? = nil
|
||||||
|
if let height = trunk.height {
|
||||||
|
let rectangularSize = try await self.equivalentRectangularDuct(
|
||||||
|
.init(round: sizes.finalSize, height: height)
|
||||||
|
)
|
||||||
|
width = rectangularSize.width
|
||||||
|
}
|
||||||
|
|
||||||
|
retval.append(
|
||||||
|
.init(
|
||||||
|
trunk: trunk,
|
||||||
|
ductSize: .init(
|
||||||
|
designCFM: designCFM,
|
||||||
|
sizes: sizes,
|
||||||
|
height: trunk.height,
|
||||||
|
width: width
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension DuctSizing.SizeContainer {
|
||||||
|
init(
|
||||||
|
designCFM: DuctSizing.DesignCFM,
|
||||||
|
sizes: ManualDClient.DuctSizeResponse,
|
||||||
|
height: Int?,
|
||||||
|
width: Int?
|
||||||
|
) {
|
||||||
|
self.init(
|
||||||
|
rectangularID: nil,
|
||||||
|
designCFM: designCFM,
|
||||||
|
roundSize: sizes.ductulatorSize,
|
||||||
|
finalSize: sizes.finalSize,
|
||||||
|
velocity: sizes.velocity,
|
||||||
|
flexSize: sizes.flexSize,
|
||||||
|
height: height,
|
||||||
|
width: width
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
init(
|
||||||
|
designCFM: DuctSizing.DesignCFM,
|
||||||
|
sizes: ManualDClient.DuctSizeResponse,
|
||||||
|
rectangularSize: Room.RectangularSize?,
|
||||||
|
width: Int?
|
||||||
|
) {
|
||||||
|
self.init(
|
||||||
|
rectangularID: rectangularSize?.id,
|
||||||
|
designCFM: designCFM,
|
||||||
|
roundSize: sizes.ductulatorSize,
|
||||||
|
finalSize: sizes.finalSize,
|
||||||
|
velocity: sizes.velocity,
|
||||||
|
flexSize: sizes.flexSize,
|
||||||
|
height: rectangularSize?.height,
|
||||||
|
width: width
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Room {
|
||||||
|
|
||||||
|
var heatingLoadPerRegister: Double {
|
||||||
|
|
||||||
|
heatingLoad / Double(registerCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func coolingSensiblePerRegister(projectSHR: Double) -> Double {
|
||||||
|
let sensible = coolingSensible ?? (coolingTotal * projectSHR)
|
||||||
|
return sensible / Double(registerCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension TrunkSize.RoomProxy {
|
||||||
|
|
||||||
|
// We need to make sure if registers got removed after a trunk
|
||||||
|
// was already made / saved that we do not include registers that
|
||||||
|
// no longer exist.
|
||||||
|
private var actualRegisterCount: Int {
|
||||||
|
guard registers.count <= room.registerCount else {
|
||||||
|
return room.registerCount
|
||||||
|
}
|
||||||
|
return registers.count
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalHeatingLoad: Double {
|
||||||
|
room.heatingLoadPerRegister * Double(actualRegisterCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func totalCoolingSensible(projectSHR: Double) -> Double {
|
||||||
|
room.coolingSensiblePerRegister(projectSHR: projectSHR) * Double(actualRegisterCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension TrunkSize {
|
||||||
|
|
||||||
|
var totalHeatingLoad: Double {
|
||||||
|
rooms.reduce(into: 0) { $0 += $1.totalHeatingLoad }
|
||||||
|
}
|
||||||
|
|
||||||
|
func totalCoolingSensible(projectSHR: Double) -> Double {
|
||||||
|
rooms.reduce(into: 0) { $0 += $1.totalCoolingSensible(projectSHR: projectSHR) }
|
||||||
|
}
|
||||||
|
}
|
||||||
62
Sources/ProjectClient/Live.swift
Normal file
62
Sources/ProjectClient/Live.swift
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import Dependencies
|
||||||
|
import Logging
|
||||||
|
import ManualDClient
|
||||||
|
import ManualDCore
|
||||||
|
|
||||||
|
extension ProjectClient: DependencyKey {
|
||||||
|
|
||||||
|
public static var liveValue: Self {
|
||||||
|
@Dependency(\.database) var database
|
||||||
|
@Dependency(\.manualD) var manualD
|
||||||
|
|
||||||
|
return .init(
|
||||||
|
calculateDuctSizes: { projectID in
|
||||||
|
try await database.calculateDuctSizes(projectID: projectID)
|
||||||
|
},
|
||||||
|
calculateRoomDuctSizes: { projectID in
|
||||||
|
try await database.calculateRoomDuctSizes(projectID: projectID)
|
||||||
|
},
|
||||||
|
calculateTrunkDuctSizes: { projectID in
|
||||||
|
try await database.calculateTrunkDuctSizes(projectID: projectID)
|
||||||
|
},
|
||||||
|
createProject: { userID, request in
|
||||||
|
let project = try await database.projects.create(userID, request)
|
||||||
|
try await database.componentLoss.createDefaults(projectID: project.id)
|
||||||
|
return try await .init(
|
||||||
|
projectID: project.id,
|
||||||
|
rooms: database.rooms.fetch(project.id),
|
||||||
|
sensibleHeatRatio: database.projects.getSensibleHeatRatio(project.id),
|
||||||
|
completedSteps: database.projects.getCompletedSteps(project.id)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
frictionRate: { projectID in
|
||||||
|
|
||||||
|
let componentLosses = try await database.componentLoss.fetch(projectID)
|
||||||
|
let lengths = try await database.effectiveLength.fetchMax(projectID)
|
||||||
|
|
||||||
|
let equipmentInfo = try await database.equipment.fetch(projectID)
|
||||||
|
guard let staticPressure = equipmentInfo?.staticPressure else {
|
||||||
|
return .init(componentLosses: componentLosses, equivalentLengths: lengths)
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let totalEquivalentLength = lengths.total else {
|
||||||
|
return .init(componentLosses: componentLosses, equivalentLengths: lengths)
|
||||||
|
}
|
||||||
|
|
||||||
|
return try await .init(
|
||||||
|
componentLosses: componentLosses,
|
||||||
|
equivalentLengths: lengths,
|
||||||
|
frictionRate: manualD.frictionRate(
|
||||||
|
.init(
|
||||||
|
externalStaticPressure: staticPressure,
|
||||||
|
componentPressureLosses: database.componentLoss.fetch(projectID),
|
||||||
|
totalEffectiveLength: Int(totalEquivalentLength)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
import DatabaseClient
|
|
||||||
import Dependencies
|
|
||||||
import Fluent
|
|
||||||
import ManualDClient
|
|
||||||
import ManualDCore
|
|
||||||
import Vapor
|
|
||||||
|
|
||||||
// FIX: Remove these, not used currently.
|
|
||||||
extension DatabaseClient.Projects {
|
|
||||||
|
|
||||||
func fetchPage(
|
|
||||||
userID: User.ID,
|
|
||||||
page: Int = 1,
|
|
||||||
limit: Int = 25
|
|
||||||
) async throws -> Page<Project> {
|
|
||||||
try await fetch(userID, .init(page: page, per: limit))
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchPage(
|
|
||||||
userID: User.ID,
|
|
||||||
page: PageRequest
|
|
||||||
) async throws -> Page<Project> {
|
|
||||||
try await fetch(userID, page)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension DatabaseClient {
|
|
||||||
|
|
||||||
func calculateDuctSizes(
|
|
||||||
projectID: Project.ID
|
|
||||||
) async throws -> (rooms: [DuctSizing.RoomContainer], trunks: [DuctSizing.TrunkContainer]) {
|
|
||||||
@Dependency(\.manualD) var manualD
|
|
||||||
|
|
||||||
return try await manualD.calculate(
|
|
||||||
rooms: rooms.fetch(projectID),
|
|
||||||
trunks: trunkSizes.fetch(projectID),
|
|
||||||
designFrictionRateResult: designFrictionRate(projectID: projectID),
|
|
||||||
projectSHR: projects.getSensibleHeatRatio(projectID)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func designFrictionRate(
|
|
||||||
projectID: Project.ID
|
|
||||||
) async throws -> (EquipmentInfo, EffectiveLength.MaxContainer, Double)? {
|
|
||||||
guard let equipmentInfo = try await equipment.fetch(projectID) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let equivalentLengths = try await effectiveLength.fetchMax(projectID)
|
|
||||||
guard let tel = equivalentLengths.total else { return nil }
|
|
||||||
|
|
||||||
let componentLosses = try await componentLoss.fetch(projectID)
|
|
||||||
guard componentLosses.count > 0 else { return nil }
|
|
||||||
|
|
||||||
let availableStaticPressure =
|
|
||||||
equipmentInfo.staticPressure - componentLosses.total
|
|
||||||
|
|
||||||
let designFrictionRate = (availableStaticPressure * 100) / tel
|
|
||||||
|
|
||||||
return (equipmentInfo, equivalentLengths, designFrictionRate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension DatabaseClient.ComponentLoss {
|
|
||||||
|
|
||||||
func createDefaults(projectID: Project.ID) async throws {
|
|
||||||
let defaults = ComponentPressureLoss.Create.default(projectID: projectID)
|
|
||||||
for loss in defaults {
|
|
||||||
_ = try await create(loss)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension PageRequest {
|
|
||||||
static func next<T>(_ currentPage: Page<T>) -> Self {
|
|
||||||
.init(page: currentPage.metadata.page + 1, per: currentPage.metadata.per)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import Logging
|
|
||||||
import ManualDClient
|
|
||||||
import ManualDCore
|
|
||||||
|
|
||||||
extension ManualDClient {
|
|
||||||
|
|
||||||
func calculate(
|
|
||||||
rooms: [Room],
|
|
||||||
trunks: [DuctSizing.TrunkSize],
|
|
||||||
designFrictionRateResult: (EquipmentInfo, EffectiveLength.MaxContainer, Double)?,
|
|
||||||
projectSHR: Double?,
|
|
||||||
logger: Logger? = nil
|
|
||||||
) async throws -> (rooms: [DuctSizing.RoomContainer], trunks: [DuctSizing.TrunkContainer]) {
|
|
||||||
guard let designFrictionRateResult else { return ([], []) }
|
|
||||||
let equipmentInfo = designFrictionRateResult.0
|
|
||||||
let effectiveLengths = designFrictionRateResult.1
|
|
||||||
let designFrictionRate = designFrictionRateResult.2
|
|
||||||
|
|
||||||
guard let maxSupply = effectiveLengths.supply else { return ([], []) }
|
|
||||||
guard let maxReturn = effectiveLengths.return else { return ([], []) }
|
|
||||||
|
|
||||||
let ductRooms = try await self.calculateSizes(
|
|
||||||
rooms: rooms,
|
|
||||||
trunks: trunks,
|
|
||||||
equipmentInfo: equipmentInfo,
|
|
||||||
maxSupplyLength: maxSupply,
|
|
||||||
maxReturnLength: maxReturn,
|
|
||||||
designFrictionRate: designFrictionRate,
|
|
||||||
projectSHR: projectSHR ?? 1.0,
|
|
||||||
logger: logger
|
|
||||||
)
|
|
||||||
|
|
||||||
// logger?.debug("Rooms: \(ductRooms)")
|
|
||||||
|
|
||||||
return ductRooms
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ import ManualDCore
|
|||||||
|
|
||||||
extension SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkSizeForm {
|
extension SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkSizeForm {
|
||||||
|
|
||||||
func toCreate(logger: Logger? = nil) throws -> DuctSizing.TrunkSize.Create {
|
func toCreate(logger: Logger? = nil) throws -> TrunkSize.Create {
|
||||||
try .init(
|
try .init(
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
type: type,
|
type: type,
|
||||||
@@ -14,7 +14,7 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkSizeForm {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toUpdate(logger: Logger? = nil) throws -> DuctSizing.TrunkSize.Update {
|
func toUpdate(logger: Logger? = nil) throws -> TrunkSize.Update {
|
||||||
try .init(
|
try .init(
|
||||||
type: type,
|
type: type,
|
||||||
rooms: makeRooms(logger: logger),
|
rooms: makeRooms(logger: logger),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import Dependencies
|
|||||||
import Elementary
|
import Elementary
|
||||||
import Foundation
|
import Foundation
|
||||||
import ManualDCore
|
import ManualDCore
|
||||||
|
import ProjectClient
|
||||||
import Styleguide
|
import Styleguide
|
||||||
|
|
||||||
extension ViewController.Request {
|
extension ViewController.Request {
|
||||||
@@ -10,6 +11,7 @@ extension ViewController.Request {
|
|||||||
func render() async -> AnySendableHTML {
|
func render() async -> AnySendableHTML {
|
||||||
|
|
||||||
@Dependency(\.database) var database
|
@Dependency(\.database) var database
|
||||||
|
@Dependency(\.projectClient) var projectClient
|
||||||
|
|
||||||
switch route {
|
switch route {
|
||||||
case .test:
|
case .test:
|
||||||
@@ -18,7 +20,7 @@ extension ViewController.Request {
|
|||||||
await ResultView {
|
await ResultView {
|
||||||
return (
|
return (
|
||||||
try await database.projects.getCompletedSteps(projectID),
|
try await database.projects.getCompletedSteps(projectID),
|
||||||
try await database.calculateDuctSizes(projectID: projectID)
|
try await projectClient.calculateDuctSizes(projectID)
|
||||||
)
|
)
|
||||||
} onSuccess: { (_, result) in
|
} onSuccess: { (_, result) in
|
||||||
TestPage(trunks: result.trunks, rooms: result.rooms)
|
TestPage(trunks: result.trunks, rooms: result.rooms)
|
||||||
@@ -116,6 +118,7 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
|
|
||||||
func renderView(on request: ViewController.Request) async -> AnySendableHTML {
|
func renderView(on request: ViewController.Request) async -> AnySendableHTML {
|
||||||
@Dependency(\.database) var database
|
@Dependency(\.database) var database
|
||||||
|
@Dependency(\.projectClient) var projectClient
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
case .index:
|
case .index:
|
||||||
@@ -124,7 +127,7 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
let user = try request.currentUser()
|
let user = try request.currentUser()
|
||||||
return try await (
|
return try await (
|
||||||
user.id,
|
user.id,
|
||||||
database.projects.fetchPage(userID: user.id)
|
database.projects.fetch(user.id, .first)
|
||||||
)
|
)
|
||||||
|
|
||||||
} onSuccess: { (userID, projects) in
|
} onSuccess: { (userID, projects) in
|
||||||
@@ -146,19 +149,14 @@ extension SiteRoute.View.ProjectRoute {
|
|||||||
return await request.view {
|
return await request.view {
|
||||||
await ResultView {
|
await ResultView {
|
||||||
let user = try request.currentUser()
|
let user = try request.currentUser()
|
||||||
let project = try await database.projects.create(user.id, form)
|
return try await projectClient.createProject(user.id, form)
|
||||||
try await database.componentLoss.createDefaults(projectID: project.id)
|
} onSuccess: { response in
|
||||||
let rooms = try await database.rooms.fetch(project.id)
|
|
||||||
let shr = try await database.projects.getSensibleHeatRatio(project.id)
|
|
||||||
let completedSteps = try await database.projects.getCompletedSteps(project.id)
|
|
||||||
return (project.id, rooms, shr, completedSteps)
|
|
||||||
} onSuccess: { (projectID, rooms, shr, completedSteps) in
|
|
||||||
ProjectView(
|
ProjectView(
|
||||||
projectID: projectID,
|
projectID: response.projectID,
|
||||||
activeTab: .rooms,
|
activeTab: .rooms,
|
||||||
completedSteps: completedSteps
|
completedSteps: response.completedSteps
|
||||||
) {
|
) {
|
||||||
RoomsView(rooms: rooms, sensibleHeatRatio: shr)
|
RoomsView(rooms: response.rooms, sensibleHeatRatio: response.sensibleHeatRatio)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,32 +414,21 @@ extension SiteRoute.View.ProjectRoute.ComponentLossRoute {
|
|||||||
) async -> AnySendableHTML {
|
) async -> AnySendableHTML {
|
||||||
|
|
||||||
@Dependency(\.database) var database
|
@Dependency(\.database) var database
|
||||||
@Dependency(\.manualD) var manualD
|
@Dependency(\.projectClient) var projectClient
|
||||||
|
|
||||||
return await request.view {
|
return await request.view {
|
||||||
await ResultView {
|
await ResultView {
|
||||||
try await catching()
|
try await catching()
|
||||||
|
|
||||||
let equipment = try await database.equipment.fetch(projectID)
|
|
||||||
let componentLosses = try await database.componentLoss.fetch(projectID)
|
|
||||||
let lengths = try await database.effectiveLength.fetchMax(projectID)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
try await database.projects.getCompletedSteps(projectID),
|
try await database.projects.getCompletedSteps(projectID),
|
||||||
componentLosses,
|
try await projectClient.frictionRate(projectID)
|
||||||
lengths,
|
|
||||||
try await manualD.frictionRate(
|
|
||||||
equipmentInfo: equipment,
|
|
||||||
componentLosses: componentLosses,
|
|
||||||
effectiveLength: lengths
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
} onSuccess: { (steps, losses, lengths, frictionRate) in
|
} onSuccess: { (steps, response) in
|
||||||
ProjectView(projectID: projectID, activeTab: .frictionRate, completedSteps: steps) {
|
ProjectView(projectID: projectID, activeTab: .frictionRate, completedSteps: steps) {
|
||||||
FrictionRateView(
|
FrictionRateView(
|
||||||
componentLosses: losses,
|
componentLosses: response.componentLosses,
|
||||||
equivalentLengths: lengths,
|
equivalentLengths: response.equivalentLengths,
|
||||||
frictionRateResponse: frictionRate
|
frictionRateResponse: response.frictionRate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,6 +542,7 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
|
|||||||
) async -> AnySendableHTML {
|
) async -> AnySendableHTML {
|
||||||
@Dependency(\.database) var database
|
@Dependency(\.database) var database
|
||||||
@Dependency(\.manualD) var manualD
|
@Dependency(\.manualD) var manualD
|
||||||
|
@Dependency(\.projectClient) var projectClient
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
case .index:
|
case .index:
|
||||||
@@ -563,8 +551,7 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
|
|||||||
case .deleteRectangularSize(let roomID, let request):
|
case .deleteRectangularSize(let roomID, let request):
|
||||||
return await ResultView {
|
return await ResultView {
|
||||||
let room = try await database.rooms.deleteRectangularSize(roomID, request.rectangularSizeID)
|
let room = try await database.rooms.deleteRectangularSize(roomID, request.rectangularSizeID)
|
||||||
return try await database.calculateDuctSizes(projectID: projectID)
|
return try await projectClient.calculateRoomDuctSizes(projectID)
|
||||||
.rooms
|
|
||||||
.filter({ $0.roomID == room.id && $0.roomRegister == request.register })
|
.filter({ $0.roomID == room.id && $0.roomRegister == request.register })
|
||||||
.first!
|
.first!
|
||||||
} onSuccess: { room in
|
} onSuccess: { room in
|
||||||
@@ -577,8 +564,7 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
|
|||||||
roomID,
|
roomID,
|
||||||
.init(id: form.id ?? .init(), register: form.register, height: form.height)
|
.init(id: form.id ?? .init(), register: form.register, height: form.height)
|
||||||
)
|
)
|
||||||
return try await database.calculateDuctSizes(projectID: projectID)
|
return try await projectClient.calculateRoomDuctSizes(projectID)
|
||||||
.rooms
|
|
||||||
.filter({ $0.roomID == room.id && $0.roomRegister == form.register })
|
.filter({ $0.roomID == room.id && $0.roomRegister == form.register })
|
||||||
.first!
|
.first!
|
||||||
} onSuccess: { room in
|
} onSuccess: { room in
|
||||||
@@ -612,13 +598,14 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
|
|||||||
catching: @escaping @Sendable () async throws -> Void = {}
|
catching: @escaping @Sendable () async throws -> Void = {}
|
||||||
) async -> AnySendableHTML {
|
) async -> AnySendableHTML {
|
||||||
@Dependency(\.database) var database
|
@Dependency(\.database) var database
|
||||||
|
@Dependency(\.projectClient) var project
|
||||||
|
|
||||||
return await request.view {
|
return await request.view {
|
||||||
await ResultView {
|
await ResultView {
|
||||||
try await catching()
|
try await catching()
|
||||||
return (
|
return (
|
||||||
try await database.projects.getCompletedSteps(projectID),
|
try await database.projects.getCompletedSteps(projectID),
|
||||||
try await database.calculateDuctSizes(projectID: projectID)
|
try await project.calculateDuctSizes(projectID)
|
||||||
)
|
)
|
||||||
} onSuccess: { (steps, ducts) in
|
} onSuccess: { (steps, ducts) in
|
||||||
ProjectView(projectID: projectID, activeTab: .ductSizing, completedSteps: steps) {
|
ProjectView(projectID: projectID, activeTab: .ductSizing, completedSteps: steps) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct RectangularSizeForm: HTML, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var height: Int? {
|
var height: Int? {
|
||||||
room.rectangularSize?.height
|
room.ductSize.height
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some HTML<HTMLTag.dialog> {
|
var body: some HTML<HTMLTag.dialog> {
|
||||||
@@ -54,7 +54,7 @@ struct RectangularSizeForm: HTML, Sendable {
|
|||||||
.hx.swap(.outerHTML)
|
.hx.swap(.outerHTML)
|
||||||
) {
|
) {
|
||||||
input(.class("hidden"), .name("register"), .value(room.roomRegister))
|
input(.class("hidden"), .name("register"), .value(room.roomRegister))
|
||||||
input(.class("hidden"), .name("id"), .value(room.rectangularSize?.id))
|
input(.class("hidden"), .name("id"), .value(room.ductSize.rectangularID))
|
||||||
|
|
||||||
LabeledInput(
|
LabeledInput(
|
||||||
"Height",
|
"Height",
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ extension DuctSizingView {
|
|||||||
let formID = UUID().idString
|
let formID = UUID().idString
|
||||||
|
|
||||||
var deleteRoute: String {
|
var deleteRoute: String {
|
||||||
guard let id = room.rectangularSize?.id else { return "" }
|
guard let id = room.rectangularID else { return "" }
|
||||||
|
|
||||||
return SiteRoute.View.router.path(
|
return SiteRoute.View.router.path(
|
||||||
for: .project(
|
for: .project(
|
||||||
@@ -80,7 +80,7 @@ extension DuctSizingView {
|
|||||||
|
|
||||||
span(.class("label")) { "Design" }
|
span(.class("label")) { "Design" }
|
||||||
div(.class("flex justify-center")) {
|
div(.class("flex justify-center")) {
|
||||||
Badge(number: room.designCFM.value, digits: 0)
|
Badge(number: room.ductSize.designCFM.value, digits: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
span(.class("label")) { "Heating" }
|
span(.class("label")) { "Heating" }
|
||||||
@@ -103,28 +103,28 @@ extension DuctSizingView {
|
|||||||
|
|
||||||
div(.class("label")) { "Calculated" }
|
div(.class("label")) { "Calculated" }
|
||||||
div(.class("flex justify-center")) {
|
div(.class("flex justify-center")) {
|
||||||
Badge(number: room.roundSize, digits: 2)
|
Badge(number: room.ductSize.roundSize, digits: 2)
|
||||||
}
|
}
|
||||||
div {}
|
div {}
|
||||||
|
|
||||||
div(.class("label")) { "Final" }
|
div(.class("label")) { "Final" }
|
||||||
div(.class("flex justify-center")) {
|
div(.class("flex justify-center")) {
|
||||||
Badge(number: room.finalSize)
|
Badge(number: room.ductSize.finalSize)
|
||||||
.attributes(.class("badge-secondary"))
|
.attributes(.class("badge-secondary"))
|
||||||
}
|
}
|
||||||
div {}
|
div {}
|
||||||
|
|
||||||
div(.class("label")) { "Flex" }
|
div(.class("label")) { "Flex" }
|
||||||
div(.class("flex justify-center")) {
|
div(.class("flex justify-center")) {
|
||||||
Badge(number: room.flexSize)
|
Badge(number: room.ductSize.flexSize)
|
||||||
.attributes(.class("badge-primary"))
|
.attributes(.class("badge-primary"))
|
||||||
}
|
}
|
||||||
div {}
|
div {}
|
||||||
|
|
||||||
div(.class("label")) { "Rectangular" }
|
div(.class("label")) { "Rectangular" }
|
||||||
div(.class("flex justify-center")) {
|
div(.class("flex justify-center")) {
|
||||||
if let width = room.rectangularWidth,
|
if let width = room.ductSize.width,
|
||||||
let height = room.rectangularSize?.height
|
let height = room.ductSize.height
|
||||||
{
|
{
|
||||||
Badge {
|
Badge {
|
||||||
span { "\(width) x \(height)" }
|
span { "\(width) x \(height)" }
|
||||||
@@ -134,7 +134,7 @@ extension DuctSizingView {
|
|||||||
}
|
}
|
||||||
div(.class("flex justify-end")) {
|
div(.class("flex justify-end")) {
|
||||||
div(.class("join")) {
|
div(.class("join")) {
|
||||||
if room.rectangularSize != nil {
|
if room.ductSize.width != nil {
|
||||||
Tooltip("Delete Size", position: .bottom) {
|
Tooltip("Delete Size", position: .bottom) {
|
||||||
TrashButton()
|
TrashButton()
|
||||||
.attributes(.class("join-item btn-ghost"))
|
.attributes(.class("join-item btn-ghost"))
|
||||||
@@ -142,7 +142,7 @@ extension DuctSizingView {
|
|||||||
.hx.delete(deleteRoute),
|
.hx.delete(deleteRoute),
|
||||||
.hx.target("#\(rowID)"),
|
.hx.target("#\(rowID)"),
|
||||||
.hx.swap(.outerHTML),
|
.hx.swap(.outerHTML),
|
||||||
when: room.rectangularSize != nil
|
when: room.ductSize.width != nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ struct TrunkSizeForm: HTML, Sendable {
|
|||||||
let rooms: [DuctSizing.RoomContainer]
|
let rooms: [DuctSizing.RoomContainer]
|
||||||
let dismiss: Bool
|
let dismiss: Bool
|
||||||
|
|
||||||
var trunk: DuctSizing.TrunkSize? {
|
var trunk: TrunkSize? {
|
||||||
container?.trunk
|
container?.trunk
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ struct TrunkSizeForm: HTML, Sendable {
|
|||||||
label(.class("select w-full")) {
|
label(.class("select w-full")) {
|
||||||
span(.class("label")) { "Type" }
|
span(.class("label")) { "Type" }
|
||||||
select(.name("type")) {
|
select(.name("type")) {
|
||||||
for type in DuctSizing.TrunkSize.TrunkType.allCases {
|
for type in TrunkSize.TrunkType.allCases {
|
||||||
option(.value(type.rawValue)) { type.rawValue.capitalized }
|
option(.value(type.rawValue)) { type.rawValue.capitalized }
|
||||||
.attributes(.selected, when: trunk?.type == type)
|
.attributes(.selected, when: trunk?.type == type)
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ struct TrunkSizeForm: HTML, Sendable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Array where Element == DuctSizing.TrunkSize.RoomProxy {
|
extension Array where Element == TrunkSize.RoomProxy {
|
||||||
func hasRoom(_ room: DuctSizing.RoomContainer) -> Bool {
|
func hasRoom(_ room: DuctSizing.RoomContainer) -> Bool {
|
||||||
first {
|
first {
|
||||||
$0.id == room.roomID
|
$0.id == room.roomID
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct RoomsView: HTML, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div(.class("flex justify-end grow")) {
|
div(.class("flex justify-end grow")) {
|
||||||
Tooltip("Project wide sensible heat ratio", position: .left) {
|
Tooltip("Set sensible heat ratio", position: .left) {
|
||||||
button(
|
button(
|
||||||
.class(
|
.class(
|
||||||
"""
|
"""
|
||||||
@@ -43,6 +43,7 @@ struct RoomsView: HTML, Sendable {
|
|||||||
}
|
}
|
||||||
.attributes(.class("border border-error"), when: sensibleHeatRatio == nil)
|
.attributes(.class("border border-error"), when: sensibleHeatRatio == nil)
|
||||||
}
|
}
|
||||||
|
.attributes(.class("tooltip-open"), when: sensibleHeatRatio == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
div(.class("flex items-end space-x-4 font-bold")) {
|
div(.class("flex items-end space-x-4 font-bold")) {
|
||||||
@@ -67,7 +68,7 @@ struct RoomsView: HTML, Sendable {
|
|||||||
|
|
||||||
SHRForm(
|
SHRForm(
|
||||||
sensibleHeatRatio: sensibleHeatRatio,
|
sensibleHeatRatio: sensibleHeatRatio,
|
||||||
dismiss: sensibleHeatRatio != nil
|
dismiss: true
|
||||||
)
|
)
|
||||||
|
|
||||||
table(.class("table table-zebra text-lg"), .id("roomsTable")) {
|
table(.class("table table-zebra text-lg"), .id("roomsTable")) {
|
||||||
|
|||||||
9
TODO.md
Normal file
9
TODO.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# TODO's
|
||||||
|
|
||||||
|
- [x] Fix theme not working when selected upon signup.
|
||||||
|
- [ ] Pdf generation
|
||||||
|
- [ ] Add postgres / mysql support
|
||||||
|
- [ ] Opensource / license ??
|
||||||
|
- [ ] Figure out domain to host (currently thinking ductcalc.pro)
|
||||||
|
- [ ] Logo / navbar name may have to change if it's not duct-calc.
|
||||||
|
- [ ] MainPage meta items will have to change also
|
||||||
Reference in New Issue
Block a user