engrmuhammadrizwan01 commited on
Commit
4b85951
·
verified ·
1 Parent(s): 213365a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -49
app.py CHANGED
@@ -1,52 +1,36 @@
1
  import streamlit as st
2
- import math
3
 
4
- # Function to calculate required C Channels/Rods based on spacing
5
- def calculate_c_channels(area_length, area_width, rod_length, horizontal_spacing, vertical_spacing):
6
- if rod_length <= 0 or horizontal_spacing <= 0 or vertical_spacing <= 0:
7
- return None, None
8
-
9
- # Calculate number of horizontal and vertical rods needed
10
- num_horizontal_rods = math.ceil(area_width / horizontal_spacing) + 1 # Extra rod at boundary
11
- num_vertical_rods = math.ceil(area_length / vertical_spacing) + 1 # Extra rod at boundary
12
-
13
- # Total length required for horizontal and vertical rods
14
- total_horizontal_length = num_horizontal_rods * area_length
15
- total_vertical_length = num_vertical_rods * area_width
16
-
17
- # Compute number of rods needed based on length
18
- required_horizontal_rods = math.ceil(total_horizontal_length / rod_length)
19
- required_vertical_rods = math.ceil(total_vertical_length / rod_length)
20
-
21
- return required_horizontal_rods, required_vertical_rods
22
-
23
- # Streamlit UI Configuration
24
- st.set_page_config(page_title="C Channel/Rod Calculator", layout="wide")
25
-
26
- st.title("🛠 C Channel/Rod Calculator")
27
- st.markdown("Calculate required C Channels/Rods based on area and spacing.")
28
-
29
- # Area Input
30
- st.subheader("📏 Area Dimensions")
31
- area_length = st.number_input("Enter Total Length of Area (meters):", min_value=0.1, format="%.2f")
32
- area_width = st.number_input("Enter Total Width of Area (meters):", min_value=0.1, format="%.2f")
33
-
34
- # C Channel/Rod Inputs
35
- st.subheader("🔩 C Channel/Rod Specifications")
36
- rod_length = st.number_input("Enter Length of One C Channel/Rod (meters):", min_value=0.1, format="%.2f")
37
- horizontal_spacing = st.number_input("Enter Horizontal Distance Between Rods (meters):", min_value=0.1, format="%.2f")
38
- vertical_spacing = st.number_input("Enter Vertical Distance Between Rods (meters):", min_value=0.1, format="%.2f")
39
-
40
- if st.button("Calculate Required C Channels/Rods"):
41
- num_horizontal, num_vertical = calculate_c_channels(area_length, area_width, rod_length, horizontal_spacing, vertical_spacing)
42
-
43
- if num_horizontal is not None and num_vertical is not None:
44
- total_rods = num_horizontal + num_vertical
45
- st.success(f"📌 You will need `{num_horizontal}` Horizontal C Channels/Rods and `{num_vertical}` Vertical C Channels/Rods.")
46
- st.info(f"✅ **Total C Channels/Rods Required:** `{total_rods}`")
47
  else:
48
- st.error("Please enter valid values for the C Channel/Rod calculation.")
49
-
50
- # Footer
51
- st.markdown("---")
52
- st.markdown("Developed with ❤️ using Streamlit.")
 
1
  import streamlit as st
 
2
 
3
+ def calculate_steel_required(total_area, unit, steel_length, box_width, box_length):
4
+ # Convert everything to meters for consistency
5
+ conversion = {'m': 1, 'cm': 0.01, 'mm': 0.001}
6
+ total_area_m2 = total_area * (conversion[unit] ** 2) # Convert area to square meters
7
+ steel_length_m = steel_length * conversion[unit] # Convert steel length to meters
8
+ box_width_m = box_width * conversion[unit] # Convert box width to meters
9
+ box_length_m = box_length * conversion[unit] # Convert box length to meters
10
+
11
+ # Number of steel rods required
12
+ num_steel_width = int((total_area_m2 ** 0.5) / box_width_m) + 1
13
+ num_steel_length = int((total_area_m2 ** 0.5) / box_length_m) + 1
14
+ total_steel_rods = num_steel_width + num_steel_length
15
+
16
+ return total_steel_rods
17
+
18
+ # Streamlit UI
19
+ st.title("Steel Rods Calculator")
20
+ st.markdown("### Calculate the number of steel rods required based on the given area and box size.")
21
+
22
+ # Select measurement unit
23
+ unit = st.selectbox("Select measurement unit", ["m", "cm", "mm"], index=1)
24
+
25
+ # Input fields
26
+ total_area = st.number_input(f"Enter total area in {unit}²", min_value=0.0, format="%.2f")
27
+ steel_length = st.number_input(f"Enter length of one steel rod in {unit}", min_value=0.0, format="%.2f")
28
+ box_width = st.number_input(f"Enter width of the box in {unit}", min_value=0.0, format="%.2f")
29
+ box_length = st.number_input(f"Enter length of the box in {unit}", min_value=0.0, format="%.2f")
30
+
31
+ if st.button("Calculate Steel Required"):
32
+ if total_area > 0 and steel_length > 0 and box_width > 0 and box_length > 0:
33
+ result = calculate_steel_required(total_area, unit, steel_length, box_width, box_length)
34
+ st.success(f"Total steel rods required: {result}")
 
 
 
 
 
 
 
 
 
 
 
35
  else:
36
+ st.error("Please enter valid positive numbers for all inputs.")