import streamlit as st import math # Function to convert all units to square meters def convert_to_sqm(length, width, unit): if unit == "Meters (m)": return length * width elif unit == "Centimeters (cm)": return (length / 100) * (width / 100) elif unit == "Millimeters (mm)": return (length / 1000) * (width / 1000) # Function to calculate excluded circular area def calculate_circular_area(diameter, unit): radius = diameter / 2 if unit == "Meters (m)": return math.pi * (radius ** 2) elif unit == "Centimeters (cm)": return math.pi * ((radius / 100) ** 2) elif unit == "Millimeters (mm)": return math.pi * ((radius / 1000) ** 2) # Function to calculate required C Channels/Rods based on spacing def calculate_c_channels(area, rod_length, horizontal_spacing, vertical_spacing): if rod_length <= 0 or horizontal_spacing <= 0 or vertical_spacing <= 0: return None horizontal_rods = area / horizontal_spacing vertical_rods = area / vertical_spacing total_rods = (horizontal_rods + vertical_rods) / rod_length return total_rods # Streamlit UI Configuration st.set_page_config(page_title="Area, Gypsum Board & C Channel Calculator", layout="wide") st.title("📐 Multi-Purpose Calculator") st.markdown("Calculate area, gypsum board requirements, and C Channel/Rod usage.") # Section 1: Area Calculation st.subheader("🔹 Main Area Input") unit = st.selectbox("Select the unit of measurement:", ["Meters (m)", "Centimeters (cm)", "Millimeters (mm)"]) length = st.number_input("Enter Length:", min_value=0.0, format="%.2f") width = st.number_input("Enter Width:", min_value=0.0, format="%.2f") total_area = convert_to_sqm(length, width, unit) # Option to subtract an excluded rectangular area st.subheader("🔹 Excluded Rectangular Area (Optional)") exclude_length = st.number_input("Enter Length of Excluded Area:", min_value=0.0, format="%.2f", key="ex_len") exclude_width = st.number_input("Enter Width of Excluded Area:", min_value=0.0, format="%.2f", key="ex_wid") excluded_rect_area = convert_to_sqm(exclude_length, exclude_width, unit) # Option to subtract an excluded circular area st.subheader("🔹 Excluded Circular Area (Optional)") diameter = st.number_input("Enter Diameter of Circular Excluded Area:", min_value=0.0, format="%.2f", key="circle_dia") excluded_circ_area = calculate_circular_area(diameter, unit) # Calculate final area final_area = total_area - (excluded_rect_area + excluded_circ_area) st.markdown(f"### ✅ Total Area: `{final_area:.2f} m²`") # Section 2: Gypsum Board Calculation st.subheader("🛠 Gypsum Board Calculation") gypsum_board_area = st.number_input("Enter Area of a Single Gypsum Board (m²):", min_value=0.1, format="%.2f") if st.button("Calculate Required Gypsum Boards"): if gypsum_board_area > 0: num_boards = final_area / gypsum_board_area st.success(f"📌 You will need approximately `{num_boards:.2f}` gypsum boards.") else: st.error("Please enter a valid gypsum board area.") # Section 3: C Channel/Rod Calculation st.subheader("🛠 C Channel/Rod Calculation") c_area = st.number_input("Enter Total Area to Cover (m²):", min_value=0.0, format="%.2f", key="c_area") rod_length = st.number_input("Enter Length of One C Channel/Rod (meters):", min_value=0.1, format="%.2f", key="rod_length") horizontal_spacing = st.number_input("Enter Horizontal Distance Between Rods (meters):", min_value=0.1, format="%.2f", key="h_spacing") vertical_spacing = st.number_input("Enter Vertical Distance Between Rods (meters):", min_value=0.1, format="%.2f", key="v_spacing") if st.button("Calculate Required C Channels/Rods"): rods_required = calculate_c_channels(c_area, rod_length, horizontal_spacing, vertical_spacing) if rods_required is not None: st.success(f"📌 You will need approximately `{rods_required:.2f}` C Channels/Rods.") else: st.error("Please enter valid values for the C Channel/Rod calculation.") # Footer st.markdown("---") st.markdown("Developed with ❤️ using Streamlit.")