-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcost-calculator.py
More file actions
227 lines (187 loc) · 8.26 KB
/
Copy pathcost-calculator.py
File metadata and controls
227 lines (187 loc) · 8.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python3
"""
AC Filter Cost Calculator
Estimates annual filter costs based on your home setup, filter preference,
and climate conditions. Helps compare different filter strategies.
Usage:
python3 cost-calculator.py --size 20x25x1 --merv 11 --pets true --climate hot-humid
python3 cost-calculator.py --interactive
"""
import argparse
import sys
# Average retail prices (USD) as of 2026
# Format: (merv_min, merv_max, thickness, price_per_filter)
FILTER_PRICES = {
"fiberglass_1in": {"merv": (1, 4), "thickness": 1, "price": 2.50, "label": "Fiberglass 1\""},
"pleated_1in_m8": {"merv": (5, 8), "thickness": 1, "price": 8.00, "label": "Pleated 1\" MERV 8"},
"pleated_1in_m11": {"merv": (9, 11), "thickness": 1, "price": 14.00, "label": "Pleated 1\" MERV 11"},
"pleated_1in_m13": {"merv": (12, 13), "thickness": 1, "price": 22.00, "label": "Pleated 1\" MERV 13"},
"pleated_4in_m8": {"merv": (5, 8), "thickness": 4, "price": 18.00, "label": "Deep Pleated 4\" MERV 8"},
"pleated_4in_m11": {"merv": (9, 11), "thickness": 4, "price": 28.00, "label": "Deep Pleated 4\" MERV 11"},
"pleated_4in_m13": {"merv": (12, 13), "thickness": 4, "price": 38.00, "label": "Deep Pleated 4\" MERV 13"},
}
# Base replacement intervals in days
BASE_INTERVALS = {
"fiberglass_1in": 30,
"pleated_1in_m8": 90,
"pleated_1in_m11": 90,
"pleated_1in_m13": 60,
"pleated_4in_m8": 180,
"pleated_4in_m11": 180,
"pleated_4in_m13": 120,
}
# Climate multipliers (1.0 = baseline, lower = replace more often)
CLIMATE_FACTORS = {
"temperate": 1.0,
"hot-dry": 0.85,
"hot-humid": 0.60, # South Florida, Gulf Coast
"cold-dry": 0.90,
"cold-humid": 0.80,
}
# Adjustment factors
PET_FACTOR = 0.70 # 30% faster clogging with pets
SMOKER_FACTOR = 0.60 # 40% faster with indoor smokers
CONSTRUCTION_FACTOR = 0.40 # 60% faster near construction
def calculate_annual_cost(filter_key, climate="temperate", pets=False,
smoker=False, construction=False):
"""Calculate annual filter cost for a given configuration."""
base_days = BASE_INTERVALS[filter_key]
price = FILTER_PRICES[filter_key]["price"]
# Apply factors
effective_days = base_days * CLIMATE_FACTORS.get(climate, 1.0)
if pets:
effective_days *= PET_FACTOR
if smoker:
effective_days *= SMOKER_FACTOR
if construction:
effective_days *= CONSTRUCTION_FACTOR
effective_days = max(effective_days, 14) # minimum 2 weeks
replacements_per_year = 365 / effective_days
annual_cost = replacements_per_year * price
return {
"filter": FILTER_PRICES[filter_key]["label"],
"price_each": price,
"interval_days": round(effective_days),
"replacements_per_year": round(replacements_per_year, 1),
"annual_cost": round(annual_cost, 2),
}
def find_matching_filters(merv, thickness=None):
"""Find filter keys matching the given MERV and optional thickness."""
matches = []
for key, info in FILTER_PRICES.items():
merv_min, merv_max = info["merv"]
if merv_min <= merv <= merv_max:
if thickness is None or info["thickness"] == thickness:
matches.append(key)
return matches
def parse_size(size_str):
"""Parse filter size string like '20x25x1' into dimensions."""
parts = size_str.lower().replace("\"", "").split("x")
if len(parts) != 3:
return None, None, None
try:
return int(parts[0]), int(parts[1]), int(parts[2])
except ValueError:
return None, None, None
def print_comparison(climate, pets, smoker, construction):
"""Print a cost comparison table for all filter types."""
print("\n" + "=" * 72)
print(" AC Filter Annual Cost Comparison")
print("=" * 72)
print(f"\n Climate: {climate}")
conditions = []
if pets:
conditions.append("pets")
if smoker:
conditions.append("indoor smoker")
if construction:
conditions.append("nearby construction")
if conditions:
print(f" Conditions: {', '.join(conditions)}")
else:
print(" Conditions: standard")
print(f"\n {'Filter Type':<30} {'Each':>7} {'Days':>6} {'Changes/Yr':>11} {'Annual':>9}")
print(" " + "-" * 66)
results = []
for key in FILTER_PRICES:
result = calculate_annual_cost(key, climate, pets, smoker, construction)
results.append(result)
print(f" {result['filter']:<30} ${result['price_each']:>5.2f} "
f"{result['interval_days']:>5}d "
f"{result['replacements_per_year']:>10.1f} "
f"${result['annual_cost']:>7.2f}")
# Find best value (lowest cost with MERV >= 8)
good_filters = [r for r in results if "MERV" in r["filter"]
and int(r["filter"].split("MERV ")[1]) >= 8]
if good_filters:
best = min(good_filters, key=lambda x: x["annual_cost"])
print(f"\n >>> Best value (MERV 8+): {best['filter']} "
f"at ${best['annual_cost']:.2f}/year")
print()
def interactive_mode():
"""Walk the user through filter selection."""
print("\n AC Filter Cost Calculator — Interactive Mode\n")
print(" What climate zone are you in?")
for i, (key, _) in enumerate(CLIMATE_FACTORS.items(), 1):
print(f" {i}. {key}")
choice = input("\n Enter number (default: 1): ").strip()
climates = list(CLIMATE_FACTORS.keys())
try:
climate = climates[int(choice) - 1]
except (ValueError, IndexError):
climate = "temperate"
pets = input(" Do you have pets? (y/n, default: n): ").strip().lower() == "y"
smoker = input(" Indoor smoker? (y/n, default: n): ").strip().lower() == "y"
construction = input(" Construction nearby? (y/n, default: n): ").strip().lower() == "y"
print_comparison(climate, pets, smoker, construction)
def main():
parser = argparse.ArgumentParser(
description="Estimate annual AC filter costs based on your setup."
)
parser.add_argument("--size", type=str, help="Filter size, e.g., 20x25x1")
parser.add_argument("--merv", type=int, default=8,
help="MERV rating (default: 8)")
parser.add_argument("--climate", type=str, default="temperate",
choices=list(CLIMATE_FACTORS.keys()),
help="Climate zone (default: temperate)")
parser.add_argument("--pets", type=str, default="false",
help="Have pets? true/false (default: false)")
parser.add_argument("--smoker", type=str, default="false",
help="Indoor smoker? true/false (default: false)")
parser.add_argument("--construction", type=str, default="false",
help="Nearby construction? true/false (default: false)")
parser.add_argument("--interactive", action="store_true",
help="Run in interactive mode")
parser.add_argument("--compare-all", action="store_true",
help="Show cost comparison for all filter types")
args = parser.parse_args()
if args.interactive:
interactive_mode()
return
pets = args.pets.lower() in ("true", "yes", "1", "y")
smoker = args.smoker.lower() in ("true", "yes", "1", "y")
construction = args.construction.lower() in ("true", "yes", "1", "y")
if args.compare_all:
print_comparison(args.climate, pets, smoker, construction)
return
# Parse size to get thickness
thickness = None
if args.size:
_, _, thickness = parse_size(args.size)
matches = find_matching_filters(args.merv, thickness)
if not matches:
print(f"No filter found for MERV {args.merv}"
+ (f" at {thickness}\" thickness" if thickness else ""))
print("Try --compare-all to see all options.")
sys.exit(1)
for key in matches:
result = calculate_annual_cost(key, args.climate, pets,
smoker, construction)
print(f"\n {result['filter']}")
print(f" Price per filter: ${result['price_each']:.2f}")
print(f" Replacement interval: {result['interval_days']} days")
print(f" Replacements per year: {result['replacements_per_year']}")
print(f" Estimated annual cost: ${result['annual_cost']:.2f}")
print()
if __name__ == "__main__":
main()