bballkyle34's picture
Add pool chemistry calculator files
dd71fc2
Raw History Blame Contribute Delete
4.94 kB
import gradio as gr
# Pool chemistry calculation functions
def adjust_ph(pool_volume, current_ph, target_ph):
# 1 oz muriatic acid per 10,000 gallons lowers pH by ~0.1
# 1 oz soda ash per 10,000 gallons raises pH by ~0.1
ph_difference = target_ph - current_ph
gallons_per_10000 = pool_volume / 10000
if ph_difference < 0:
oz_muriatic = abs(ph_difference) * 10 * gallons_per_10000
return f"Add {oz_muriatic:.2f} oz of muriatic acid to lower pH."
elif ph_difference > 0:
oz_soda_ash = ph_difference * 10 * gallons_per_10000
return f"Add {oz_soda_ash:.2f} oz of soda ash to raise pH."
else:
return "pH is already at target."
def adjust_chlorine(pool_volume, current_cl, target_cl):
# 1 ppm chlorine increase per 10,000 gallons needs ~2 oz liquid chlorine (10% solution)
cl_difference = target_cl - current_cl
gallons_per_10000 = pool_volume / 10000
if cl_difference > 0:
oz_chlorine = cl_difference * 2 * gallons_per_10000
return f"Add {oz_chlorine:.2f} oz of liquid chlorine (10%) to raise chlorine."
else:
return "Chlorine is at or above target (consider dilution if too high)."
def adjust_alkalinity(pool_volume, current_alk, target_alk):
# 10 ppm alkalinity increase per 10,000 gallons needs ~1.4 lbs sodium bicarbonate
alk_difference = target_alk - current_alk
gallons_per_10000 = pool_volume / 10000
if alk_difference > 0:
lbs_bicarb = (alk_difference / 10) * 1.4 * gallons_per_10000
return f"Add {lbs_bicarb:.2f} lbs of sodium bicarbonate to raise alkalinity."
else:
return "Alkalinity is at or above target."
def adjust_stabilizer(pool_volume, current_stab, target_stab):
# 10 ppm stabilizer increase per 10,000 gallons needs ~1.3 lbs cyanuric acid
stab_difference = target_stab - current_stab
gallons_per_10000 = pool_volume / 10000
if stab_difference > 0:
lbs_cya = (stab_difference / 10) * 1.3 * gallons_per_10000
return f"Add {lbs_cya:.2f} lbs of cyanuric acid to raise stabilizer."
else:
return "Stabilizer is at or above target (reduce via dilution if too high)."
def adjust_calcium(pool_volume, current_calc, target_calc):
# 10 ppm calcium increase per 10,000 gallons needs ~0.9 lbs calcium chloride
calc_difference = target_calc - current_calc
gallons_per_10000 = pool_volume / 10000
if calc_difference > 0:
lbs_calcium = (calc_difference / 10) * 0.9 * gallons_per_10000
return f"Add {lbs_calcium:.2f} lbs of calcium chloride to raise calcium hardness."
else:
return "Calcium hardness is at or above target."
def adjust_salinity(pool_volume, current_salt, target_salt):
# 100 ppm salinity increase per 10,000 gallons needs ~2.5 lbs salt
salt_difference = target_salt - current_salt
gallons_per_10000 = pool_volume / 10000
if salt_difference > 0:
lbs_salt = (salt_difference / 100) * 2.5 * gallons_per_10000
return f"Add {lbs_salt:.2f} lbs of salt to raise salinity."
else:
return "Salinity is at or above target (reduce via dilution if too high)."
# Main calculator function
def calculate_chemicals(pool_volume, current_ph, target_ph, current_cl, target_cl,
current_alk, target_alk, current_stab, target_stab,
current_calc, target_calc, current_salt, target_salt):
ph_result = adjust_ph(pool_volume, current_ph, target_ph)
cl_result = adjust_chlorine(pool_volume, current_cl, target_cl)
alk_result = adjust_alkalinity(pool_volume, current_alk, target_alk)
stab_result = adjust_stabilizer(pool_volume, current_stab, target_stab)
calc_result = adjust_calcium(pool_volume, current_calc, target_calc)
salt_result = adjust_salinity(pool_volume, current_salt, target_salt)
return f"{ph_result}\n{cl_result}\n{alk_result}\n{stab_result}\n{calc_result}\n{salt_result}"
# Gradio interface
interface = gr.Interface(
fn=calculate_chemicals,
inputs=[
gr.Number(label="Pool Volume (gallons)"),
gr.Number(label="Current pH"),
gr.Number(label="Target pH"),
gr.Number(label="Current Free Chlorine (ppm)"),
gr.Number(label="Target Free Chlorine (ppm)"),
gr.Number(label="Current Total Alkalinity (ppm)"),
gr.Number(label="Target Total Alkalinity (ppm)"),
gr.Number(label="Current Stabilizer - Cyanuric Acid (ppm)"),
gr.Number(label="Target Stabilizer - Cyanuric Acid (ppm)"),
gr.Number(label="Current Calcium Hardness (ppm)"),
gr.Number(label="Target Calcium Hardness (ppm)"),
gr.Number(label="Current Salinity (ppm)"),
gr.Number(label="Target Salinity (ppm)")
],
outputs="text",
title="Pool Chemistry Calculator",
description="Enter your pool's volume and readings to calculate chemical adjustments."
)
# Launch the app locally
interface.launch()