Packages

Pest control and termite treatment cost calculator for Southern California homeowners and property managers.

Current section

Files

Jump to
pest_control lib pest_control.ex
Raw

lib/pest_control.ex

defmodule PestControl do
@moduledoc """
Pest Control Cost Calculator — Elixir Engine
Built by Treebark Termite and Pest Control
https://treebarktermiteandpestcontrol.com
"""
@pest_base_rates %{
"subterranean_termite" => 0.55,
"drywood_termite" => 0.65,
"dampwood_termite" => 0.50,
"ants" => 0.12,
"cockroaches" => 0.14,
"spiders" => 0.10,
"rodents" => 0.20,
"fleas" => 0.15,
"general_pest" => 0.12,
"multi_pest" => 0.22
}
@treatment_multipliers %{
"liquid_barrier" => 1.0,
"bait_stations" => 0.6,
"fumigation" => 2.2,
"heat_treatment" => 1.8,
"spot_treatment" => 0.4,
"ipm" => 0.9,
"organic" => 1.1
}
@severity_multipliers %{
"preventive" => 0.6,
"light" => 0.85,
"moderate" => 1.0,
"severe" => 1.5
}
@frequency_factors %{
"one_time" => 1.0,
"annual" => 0.95,
"quarterly" => 0.85,
"bimonthly" => 0.80,
"monthly" => 0.70
}
@treatments_per_year %{
"one_time" => 1,
"annual" => 1,
"quarterly" => 4,
"bimonthly" => 6,
"monthly" => 12
}
@access_multipliers %{
"standard" => 1.0,
"crawl_space" => 1.25,
"attic" => 1.20,
"multi_story" => 1.35,
"slab_drill" => 1.50
}
@property_minimums %{
"single_family" => 150,
"multi_family" => 250,
"condo" => 120,
"commercial_office" => 350,
"restaurant" => 300,
"warehouse" => 400
}
@regional_multipliers %{
"orange_county" => 1.10,
"los_angeles_county" => 1.05,
"riverside_county" => 0.90
}
@seasonal_adjustments %{
"Q1" => 0.95,
"Q2" => 1.15,
"Q3" => 1.05,
"Q4" => 1.00
}
@addon_costs %{
"wdi_wdo_inspection" => 150,
"exclusion_sealing" => 350,
"attic_insulation_treatment" => 500,
"termite_damage_repair_estimate" => 0
}
@labor_ratio 0.65
@default_margin 0.25
@termite_types ["subterranean_termite", "drywood_termite", "dampwood_termite"]
def calculate(params) do
pest_type = params.pest_type
property_sqft = params.property_sqft
profit_margin = Map.get(params, :profit_margin, @default_margin)
quarter = Map.get(params, :quarter, "Q2")
addons = Map.get(params, :addons, [])
base_rate = Map.get(@pest_base_rates, pest_type, 0.12)
minimum = Map.get(@property_minimums, params.property_type, 150)
raw_cost = max(base_rate * property_sqft, minimum)
treat_mult = Map.get(@treatment_multipliers, params.treatment_method, 1.0)
sev_mult = Map.get(@severity_multipliers, params.infestation_severity, 1.0)
acc_mult = Map.get(@access_multipliers, params.access_difficulty, 1.0)
reg_mult = Map.get(@regional_multipliers, params.region, 1.0)
sea_mult = Map.get(@seasonal_adjustments, quarter, 1.0)
adjusted = raw_cost * treat_mult * sev_mult * acc_mult * reg_mult * sea_mult
labor = Float.round(adjusted * @labor_ratio, 2)
materials = Float.round(adjusted * (1 - @labor_ratio), 2)
subtotal = Float.round(labor + materials, 2)
margin_amount = Float.round(subtotal * profit_margin, 2)
per_treatment = Float.round(subtotal + margin_amount, 2)
addon_total = Enum.reduce(addons, 0, fn a, acc -> acc + Map.get(@addon_costs, a, 0) end)
per_treatment_total = Float.round(per_treatment + addon_total, 2)
freq_factor = Map.get(@frequency_factors, params.service_frequency, 1.0)
treats_year = Map.get(@treatments_per_year, params.service_frequency, 1)
annual_per = Float.round(per_treatment_total * freq_factor, 2)
annual_total = Float.round(annual_per * treats_year, 2)
cost_per_sqft =
if property_sqft > 0,
do: Float.round(per_treatment_total / property_sqft, 4),
else: 0
{fumigation, savings} =
if pest_type in @termite_types do
fum_adj = raw_cost * 2.2 * sev_mult * acc_mult * reg_mult * sea_mult
fum = Float.round(fum_adj * (1.0 + profit_margin), 2)
{fum, Float.round(fum - per_treatment_total, 2)}
else
{nil, nil}
end
%{
per_treatment_cost: per_treatment_total,
cost_per_sqft: cost_per_sqft,
annual_total: annual_total,
fumigation_comparison: fumigation,
savings_vs_fumigation: savings
}
end
end