From 1727e9a905af2753e686069e72e69b2c9f00003d Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Mon, 3 Mar 2025 15:52:34 -0500 Subject: [PATCH] feat: Refactoring climate zone. --- Sources/Routes/Models/ClimateZone.swift | 84 +++++++++++++------ .../Routes/Models/FilterPressureDrop.swift | 4 +- Sources/Routes/SiteRoutes.swift | 2 +- Sources/ViewController/MainPage.swift | 8 ++ .../Views/FilterPressureDrop.swift | 2 +- justfile | 3 +- 6 files changed, 73 insertions(+), 30 deletions(-) diff --git a/Sources/Routes/Models/ClimateZone.swift b/Sources/Routes/Models/ClimateZone.swift index c9a2228..fc60a9f 100644 --- a/Sources/Routes/Models/ClimateZone.swift +++ b/Sources/Routes/Models/ClimateZone.swift @@ -1,33 +1,67 @@ -public enum ClimateZone: String, CaseIterable, Codable, Equatable, Sendable { - // NOTE: Keep in this order. +// TODO: This should be renamed to ClimateZoneType. - case hotHumid - case moist - case dry - case marine +public enum ClimateZone { - public var zoneIdentifiers: [String] { - switch self { - case .dry: - return ["2B", "3B", "4B", "5B", "6B", "7B"] - case .hotHumid: - return ["1A", "2A"] - case .marine: - return ["3C", "4C"] - case .moist: - return ["3A", "4A", "5A", "6A", "7A"] + public enum ZoneType: String, CaseIterable, Codable, Equatable, Sendable { + // NOTE: Keep in this order. + + case hotHumid + case moist + case dry + case marine + + // FIX: Return ZoneIdentifiers. + public var zoneIdentifiers: [String] { + switch self { + case .dry: + return ["2B", "3B", "4B", "5B", "6B", "7B"] + case .hotHumid: + return ["1A", "2A"] + case .marine: + return ["3C", "4C"] + case .moist: + return ["3A", "4A", "5A", "6A", "7A"] + } } - } - public var cfmPerTon: Int { - switch self { - case .dry: return 450 - case .hotHumid: return 350 - case .marine, .moist: return 400 + public var cfmPerTon: Int { + switch self { + case .dry: return 450 + case .hotHumid: return 350 + case .marine, .moist: return 400 + } } - } - public var label: String { - return "\(self == .hotHumid ? "Hot Humid" : rawValue.capitalized) (\(zoneIdentifiers.joined(separator: ", ")))" + public var label: String { + return "\(self == .hotHumid ? "Hot Humid" : rawValue.capitalized) (\(zoneIdentifiers.joined(separator: ", ")))" + } + + /// Represents climate zone identifiers. + public enum ZoneIdentifier: String, CaseIterable, Codable, Equatable, Sendable { + // A zones (hotHumid) + case oneA = "1A" + case twoA = "2A" + // A zones (moist) + case threeA = "3A" + case fourA = "4A" + case fiveA = "5A" + case sixA = "6A" + case sevenA = "7A" + + // B zones (dry) + case twoB = "2B" + case threeB = "3B" + case fourB = "4B" + case fiveB = "5B" + case sixB = "6B" + case sevenB = "7B" + + // C zones (marine) + case threeC = "3C" + case fourC = "4C" + + public var label: String { rawValue } + + } } } diff --git a/Sources/Routes/Models/FilterPressureDrop.swift b/Sources/Routes/Models/FilterPressureDrop.swift index 786a2a1..cdcf4f7 100644 --- a/Sources/Routes/Models/FilterPressureDrop.swift +++ b/Sources/Routes/Models/FilterPressureDrop.swift @@ -16,14 +16,14 @@ public enum FilterPressureDrop { public struct Basic: Codable, Equatable, Sendable { public let systemSize: Double - public let climateZone: ClimateZone + public let climateZone: ClimateZone.ZoneType public let filterType: FilterType public let filterWidth: Double public let filterHeight: Double public init( systemSize: Double, - climateZone: ClimateZone, + climateZone: ClimateZone.ZoneType, filterType: FilterPressureDrop.FilterType, filterWidth: Double, filterHeight: Double diff --git a/Sources/Routes/SiteRoutes.swift b/Sources/Routes/SiteRoutes.swift index 5b70d4b..cb0aaae 100644 --- a/Sources/Routes/SiteRoutes.swift +++ b/Sources/Routes/SiteRoutes.swift @@ -255,7 +255,7 @@ public extension SiteRoute { OneOf { FormData { Field("systemSize") { Double.parser() } - Field("climateZone") { ClimateZone.parser() } + Field("climateZone") { ClimateZone.ZoneType.parser() } Field("filterType") { Routes.FilterPressureDrop.FilterType.parser() } Field("filterWidth") { Double.parser() } Field("filterHeight") { Double.parser() } diff --git a/Sources/ViewController/MainPage.swift b/Sources/ViewController/MainPage.swift index bd9bab2..23612d0 100644 --- a/Sources/ViewController/MainPage.swift +++ b/Sources/ViewController/MainPage.swift @@ -11,6 +11,14 @@ struct MainPage: SendableHTMLDocument where Inner: Sendable { var head: some HTML { meta(.charset(.utf8)) meta(.name("viewport"), .content("width=device-width, initial-scale=1.0")) + meta(.name("author"), .content("Michael Housh and Dustin Cole")) + meta(.name("og:site-name"), .content("HVAC-Toolbox")) + meta(.name("apple-mobile-web-app-title"), .content("HVAC-Toolbox")) + meta(.name("format-detection"), .content("telephone=no")) + meta(.name("HandheldFriendly"), .content("True")) + meta(.name("MobileOptimized"), .content("320")) + meta(.name("keywords"), .content("hvac, HVAC, design, system-design, calculators")) + Elementary.title { self.title } link(.rel(.stylesheet), .href("/output.css")) link( .rel(.icon), diff --git a/Sources/ViewController/Views/FilterPressureDrop.swift b/Sources/ViewController/Views/FilterPressureDrop.swift index 73ab03b..b019307 100644 --- a/Sources/ViewController/Views/FilterPressureDrop.swift +++ b/Sources/ViewController/Views/FilterPressureDrop.swift @@ -62,7 +62,7 @@ struct FilterPressureDropForm: HTML, Sendable { } div { InputLabel(for: "climateZone") { "Climate Zone" } - Select(for: ClimateZone.self, id: "climateZone") { + Select(for: ClimateZone.ZoneType.self, id: "climateZone") { $0.label } } diff --git a/justfile b/justfile index 4e82204..fd902e6 100644 --- a/justfile +++ b/justfile @@ -21,4 +21,5 @@ clean: push-image: @docker push {{docker_registiry}}/{{docker_image}}:{{docker_tag}} -build-and-push: (build-docker "linux/amd64") push-image +build-docker-production: + @docker build --platform "linux/amd64" -t {{docker_registiry}}/{{docker_image}}:{{docker_tag}} .