Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
# Function to convert all units to square meters
|
| 5 |
+
def convert_to_sqm(length, width, unit):
|
| 6 |
+
if unit == "Meters (m)":
|
| 7 |
+
return length * width
|
| 8 |
+
elif unit == "Centimeters (cm)":
|
| 9 |
+
return (length / 100) * (width / 100)
|
| 10 |
+
elif unit == "Millimeters (mm)":
|
| 11 |
+
return (length / 1000) * (width / 1000)
|
| 12 |
+
|
| 13 |
+
# Function to calculate excluded circular area
|
| 14 |
+
def calculate_circular_area(diameter, unit):
|
| 15 |
+
radius = diameter / 2
|
| 16 |
+
if unit == "Meters (m)":
|
| 17 |
+
return math.pi * (radius ** 2)
|
| 18 |
+
elif unit == "Centimeters (cm)":
|
| 19 |
+
return math.pi * ((radius / 100) ** 2)
|
| 20 |
+
elif unit == "Millimeters (mm)":
|
| 21 |
+
return math.pi * ((radius / 1000) ** 2)
|
| 22 |
+
|
| 23 |
+
# Function to calculate required C Channels/Rods based on spacing
|
| 24 |
+
def calculate_c_channels(area, rod_length, horizontal_spacing, vertical_spacing):
|
| 25 |
+
if rod_length <= 0 or horizontal_spacing <= 0 or vertical_spacing <= 0:
|
| 26 |
+
return None
|
| 27 |
+
|
| 28 |
+
horizontal_rods = area / horizontal_spacing
|
| 29 |
+
vertical_rods = area / vertical_spacing
|
| 30 |
+
|
| 31 |
+
total_rods = (horizontal_rods + vertical_rods) / rod_length
|
| 32 |
+
return total_rods
|
| 33 |
+
|
| 34 |
+
# Streamlit UI Configuration
|
| 35 |
+
st.set_page_config(page_title="Area, Gypsum Board & C Channel Calculator", layout="wide")
|
| 36 |
+
|
| 37 |
+
st.title("📐 Multi-Purpose Calculator")
|
| 38 |
+
st.markdown("Calculate area, gypsum board requirements, and C Channel/Rod usage.")
|
| 39 |
+
|
| 40 |
+
# Section 1: Area Calculation
|
| 41 |
+
st.subheader("🔹 Main Area Input")
|
| 42 |
+
unit = st.selectbox("Select the unit of measurement:", ["Meters (m)", "Centimeters (cm)", "Millimeters (mm)"])
|
| 43 |
+
|
| 44 |
+
length = st.number_input("Enter Length:", min_value=0.0, format="%.2f")
|
| 45 |
+
width = st.number_input("Enter Width:", min_value=0.0, format="%.2f")
|
| 46 |
+
|
| 47 |
+
total_area = convert_to_sqm(length, width, unit)
|
| 48 |
+
|
| 49 |
+
# Option to subtract an excluded rectangular area
|
| 50 |
+
st.subheader("🔹 Excluded Rectangular Area (Optional)")
|
| 51 |
+
exclude_length = st.number_input("Enter Length of Excluded Area:", min_value=0.0, format="%.2f", key="ex_len")
|
| 52 |
+
exclude_width = st.number_input("Enter Width of Excluded Area:", min_value=0.0, format="%.2f", key="ex_wid")
|
| 53 |
+
|
| 54 |
+
excluded_rect_area = convert_to_sqm(exclude_length, exclude_width, unit)
|
| 55 |
+
|
| 56 |
+
# Option to subtract an excluded circular area
|
| 57 |
+
st.subheader("🔹 Excluded Circular Area (Optional)")
|
| 58 |
+
diameter = st.number_input("Enter Diameter of Circular Excluded Area:", min_value=0.0, format="%.2f", key="circle_dia")
|
| 59 |
+
excluded_circ_area = calculate_circular_area(diameter, unit)
|
| 60 |
+
|
| 61 |
+
# Calculate final area
|
| 62 |
+
final_area = total_area - (excluded_rect_area + excluded_circ_area)
|
| 63 |
+
|
| 64 |
+
st.markdown(f"### ✅ Total Area: `{final_area:.2f} m²`")
|
| 65 |
+
|
| 66 |
+
# Section 2: Gypsum Board Calculation
|
| 67 |
+
st.subheader("🛠 Gypsum Board Calculation")
|
| 68 |
+
gypsum_board_area = st.number_input("Enter Area of a Single Gypsum Board (m²):", min_value=0.1, format="%.2f")
|
| 69 |
+
|
| 70 |
+
if st.button("Calculate Required Gypsum Boards"):
|
| 71 |
+
if gypsum_board_area > 0:
|
| 72 |
+
num_boards = final_area / gypsum_board_area
|
| 73 |
+
st.success(f"📌 You will need approximately `{num_boards:.2f}` gypsum boards.")
|
| 74 |
+
else:
|
| 75 |
+
st.error("Please enter a valid gypsum board area.")
|
| 76 |
+
|
| 77 |
+
# Section 3: C Channel/Rod Calculation
|
| 78 |
+
st.subheader("🛠 C Channel/Rod Calculation")
|
| 79 |
+
c_area = st.number_input("Enter Total Area to Cover (m²):", min_value=0.0, format="%.2f", key="c_area")
|
| 80 |
+
rod_length = st.number_input("Enter Length of One C Channel/Rod (meters):", min_value=0.1, format="%.2f", key="rod_length")
|
| 81 |
+
horizontal_spacing = st.number_input("Enter Horizontal Distance Between Rods (meters):", min_value=0.1, format="%.2f", key="h_spacing")
|
| 82 |
+
vertical_spacing = st.number_input("Enter Vertical Distance Between Rods (meters):", min_value=0.1, format="%.2f", key="v_spacing")
|
| 83 |
+
|
| 84 |
+
if st.button("Calculate Required C Channels/Rods"):
|
| 85 |
+
rods_required = calculate_c_channels(c_area, rod_length, horizontal_spacing, vertical_spacing)
|
| 86 |
+
if rods_required is not None:
|
| 87 |
+
st.success(f"📌 You will need approximately `{rods_required:.2f}` C Channels/Rods.")
|
| 88 |
+
else:
|
| 89 |
+
st.error("Please enter valid values for the C Channel/Rod calculation.")
|
| 90 |
+
|
| 91 |
+
# Footer
|
| 92 |
+
st.markdown("---")
|
| 93 |
+
st.markdown("Developed with ❤️ using Streamlit.")
|