engrmuhammadrizwan01/Calculate_C_Channel
0
1import streamlit as st2import matplotlib.pyplot as plt3import numpy as np4 5def 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) + 113 num_steel_length = int((total_area_m2 ** 0.5) / box_length_m) + 114 total_steel_rods = num_steel_width + num_steel_length15 16 return total_steel_rods17 18def subtract_steel_rods(total_rods, rods_to_subtract):19 return max(0, total_rods - rods_to_subtract)20 21def 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 36st.title("Steel Rods Calculator")37st.markdown("### Calculate the number of steel rods required based on the given area and box size.")38 39unit = st.selectbox("Select measurement unit", ["m", "cm", "mm"], index=1)40 41total_area = st.number_input(f"Enter total area in {unit}²", min_value=0.0, format="%.2f")42steel_length = st.number_input(f"Enter length of one steel rod in {unit}", min_value=0.0, format="%.2f")43box_width = st.number_input(f"Enter width of the box in {unit}", min_value=0.0, format="%.2f")44box_length = st.number_input(f"Enter length of the box in {unit}", min_value=0.0, format="%.2f")45rods_to_subtract = st.number_input("Enter number of rods to subtract", min_value=0, format="%d")46 47if 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.")55 