import streamlit as st # 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 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 # Calculate number of rods required in horizontal and vertical directions horizontal_rods = area / horizontal_spacing vertical_rods = area / vertical_spacing # Calculate total rods required based on their length 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") # Calculate area total_area = convert_to_sqm(length, width, unit) # Option to subtract an excluded area st.subheader("🔹 Excluded 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_area = convert_to_sqm(exclude_length, exclude_width, unit) final_area = total_area - excluded_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: Direct Area Input for Gypsum Board Calculation st.subheader("📏 Enter a Custom Area for Gypsum Board Calculation") custom_area = st.number_input("Enter Total Area in m²:", min_value=0.0, format="%.2f", key="custom_area") if st.button("Calculate Required Gypsum Boards (Based on Custom Area)"): if gypsum_board_area > 0: num_boards_custom = custom_area / gypsum_board_area st.success(f"📌 You will need approximately `{num_boards_custom:.2f}` gypsum boards.") else: st.error("Please enter a valid gypsum board area.") # Section 4: C Channel/Rod Calculation (New Function) 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.")