Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,54 @@
|
|
| 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)
|
| 7 |
-
steel_length_m = steel_length * conversion[unit]
|
| 8 |
-
box_width_m = box_width * conversion[unit]
|
| 9 |
-
box_length_m = box_length * conversion[unit]
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
else:
|
| 36 |
st.error("Please enter valid positive numbers for all inputs.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
def calculate_steel_required(total_area, unit, steel_length, box_width, box_length):
|
|
|
|
| 6 |
conversion = {'m': 1, 'cm': 0.01, 'mm': 0.001}
|
| 7 |
+
total_area_m2 = total_area * (conversion[unit] ** 2)
|
| 8 |
+
steel_length_m = steel_length * conversion[unit]
|
| 9 |
+
box_width_m = box_width * conversion[unit]
|
| 10 |
+
box_length_m = box_length * conversion[unit]
|
| 11 |
|
|
|
|
| 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 |
+
def subtract_steel_rods(total_rods, rods_to_subtract):
|
| 19 |
+
return max(0, total_rods - rods_to_subtract)
|
| 20 |
+
|
| 21 |
+
def plot_steel_grid(total_area, unit, box_width, box_length):
|
| 22 |
+
conversion = {'m': 1, 'cm': 0.01, 'mm': 0.001}
|
| 23 |
+
area_side = (total_area ** 0.5) * conversion[unit]
|
| 24 |
+
box_width_m = box_width * conversion[unit]
|
| 25 |
+
box_length_m = box_length * conversion[unit]
|
| 26 |
+
|
| 27 |
+
fig, ax = plt.subplots(figsize=(6,6))
|
| 28 |
+
ax.set_xticks(np.arange(0, area_side, box_width_m))
|
| 29 |
+
ax.set_yticks(np.arange(0, area_side, box_length_m))
|
| 30 |
+
ax.grid(True, linestyle='--', linewidth=0.5)
|
| 31 |
+
ax.set_xlim(0, area_side)
|
| 32 |
+
ax.set_ylim(0, area_side)
|
| 33 |
+
ax.set_title("Graphical Representation of Steel Rods")
|
| 34 |
+
st.pyplot(fig)
|
| 35 |
+
|
| 36 |
st.title("Steel Rods Calculator")
|
| 37 |
st.markdown("### Calculate the number of steel rods required based on the given area and box size.")
|
| 38 |
|
|
|
|
| 39 |
unit = st.selectbox("Select measurement unit", ["m", "cm", "mm"], index=1)
|
| 40 |
|
|
|
|
| 41 |
total_area = st.number_input(f"Enter total area in {unit}²", min_value=0.0, format="%.2f")
|
| 42 |
steel_length = st.number_input(f"Enter length of one steel rod in {unit}", min_value=0.0, format="%.2f")
|
| 43 |
box_width = st.number_input(f"Enter width of the box in {unit}", min_value=0.0, format="%.2f")
|
| 44 |
box_length = st.number_input(f"Enter length of the box in {unit}", min_value=0.0, format="%.2f")
|
| 45 |
+
rods_to_subtract = st.number_input("Enter number of rods to subtract", min_value=0, format="%d")
|
| 46 |
|
| 47 |
if st.button("Calculate Steel Required"):
|
| 48 |
if total_area > 0 and steel_length > 0 and box_width > 0 and box_length > 0:
|
| 49 |
+
total_rods = calculate_steel_required(total_area, unit, steel_length, box_width, box_length)
|
| 50 |
+
adjusted_rods = subtract_steel_rods(total_rods, rods_to_subtract)
|
| 51 |
+
st.success(f"Total steel rods required: {adjusted_rods}")
|
| 52 |
+
plot_steel_grid(total_area, unit, box_width, box_length)
|
| 53 |
else:
|
| 54 |
st.error("Please enter valid positive numbers for all inputs.")
|