File size: 2,579 Bytes
1f699ba
9986111
 
1f699ba
4b85951
 
9986111
 
 
 
4b85951
 
 
 
 
 
 
9986111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b85951
 
 
 
 
 
 
 
 
9986111
4b85951
 
 
9986111
 
 
 
1f699ba
4b85951
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np

def calculate_steel_required(total_area, unit, steel_length, box_width, box_length):
    conversion = {'m': 1, 'cm': 0.01, 'mm': 0.001}
    total_area_m2 = total_area * (conversion[unit] ** 2)
    steel_length_m = steel_length * conversion[unit]
    box_width_m = box_width * conversion[unit]
    box_length_m = box_length * conversion[unit]
    
    num_steel_width = int((total_area_m2 ** 0.5) / box_width_m) + 1
    num_steel_length = int((total_area_m2 ** 0.5) / box_length_m) + 1
    total_steel_rods = num_steel_width + num_steel_length
    
    return total_steel_rods

def subtract_steel_rods(total_rods, rods_to_subtract):
    return max(0, total_rods - rods_to_subtract)

def plot_steel_grid(total_area, unit, box_width, box_length):
    conversion = {'m': 1, 'cm': 0.01, 'mm': 0.001}
    area_side = (total_area ** 0.5) * conversion[unit]
    box_width_m = box_width * conversion[unit]
    box_length_m = box_length * conversion[unit]
    
    fig, ax = plt.subplots(figsize=(6,6))
    ax.set_xticks(np.arange(0, area_side, box_width_m))
    ax.set_yticks(np.arange(0, area_side, box_length_m))
    ax.grid(True, linestyle='--', linewidth=0.5)
    ax.set_xlim(0, area_side)
    ax.set_ylim(0, area_side)
    ax.set_title("Graphical Representation of Steel Rods")
    st.pyplot(fig)

st.title("Steel Rods Calculator")
st.markdown("### Calculate the number of steel rods required based on the given area and box size.")

unit = st.selectbox("Select measurement unit", ["m", "cm", "mm"], index=1)

total_area = st.number_input(f"Enter total area in {unit}²", min_value=0.0, format="%.2f")
steel_length = st.number_input(f"Enter length of one steel rod in {unit}", min_value=0.0, format="%.2f")
box_width = st.number_input(f"Enter width of the box in {unit}", min_value=0.0, format="%.2f")
box_length = st.number_input(f"Enter length of the box in {unit}", min_value=0.0, format="%.2f")
rods_to_subtract = st.number_input("Enter number of rods to subtract", min_value=0, format="%d")

if st.button("Calculate Steel Required"):
    if total_area > 0 and steel_length > 0 and box_width > 0 and box_length > 0:
        total_rods = calculate_steel_required(total_area, unit, steel_length, box_width, box_length)
        adjusted_rods = subtract_steel_rods(total_rods, rods_to_subtract)
        st.success(f"Total steel rods required: {adjusted_rods}")
        plot_steel_grid(total_area, unit, box_width, box_length)
    else:
        st.error("Please enter valid positive numbers for all inputs.")