File size: 2,641 Bytes
a1b6bac
 
 
 
 
47201ad
1168fca
e607e8c
1168fca
47201ad
 
 
 
 
 
e607e8c
47201ad
 
 
c3623e5
e607e8c
c3623e5
47201ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e607e8c
47201ad
 
e607e8c
 
47201ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
import pandas as pd

@st.cache_data
def load_aisc_data():
    df = pd.read_csv("AISC_Shape_Database.csv")
    df.columns = df.columns.str.strip()  # clean column headers
    # Normalize section names to uppercase and strip spaces
    df['AISC_Manual_Label'] = df['AISC_Manual_Label'].str.strip().str.upper()
    return df[['AISC_Manual_Label', 'W']]

def main():
    st.title("Steel Weight Estimator Using AISC Data")

    aisc_df = load_aisc_data()
    st.write("Sample AISC sections:", aisc_df['AISC_Manual_Label'].head(10).tolist())

    price_per_kg = st.number_input("Price per kg (e.g. 150)", min_value=0.0, format="%.2f")

    user_input = st.text_area(
        "Enter Section and Length separated by comma (one per line)\nExample:\nW44X408, 5.5\nHSS11.75X.250, 3"
    )

    if st.button("Calculate Weight and Price"):
        if not user_input.strip():
            st.error("Please enter section and length data.")
            return
        if price_per_kg <= 0:
            st.error("Please enter a valid price per kg.")
            return

        lines = user_input.strip().split('\n')
        results = []

        for line in lines:
            try:
                section, length_str = line.split(',')
                section = section.strip().upper()  # Normalize user input
                length_m = float(length_str.strip())

                st.write(f"Checking section: '{section}'")  # debug output

                row = aisc_df[aisc_df['AISC_Manual_Label'] == section]

                if row.empty:
                    results.append((section, length_m, None, None))
                    continue

                weight_lb_per_ft = float(row['W'].values[0])
                length_ft = length_m * 3.28084
                total_weight_lb = weight_lb_per_ft * length_ft
                total_weight_kg = total_weight_lb * 0.453592
                total_price = total_weight_kg * price_per_kg

                results.append((section, length_m, total_weight_kg, total_price))

            except Exception as e:
                results.append((line, None, None, None))

        st.write("### Results:")
        st.write("| Section | Length (m) | Weight (kg) | Price |")
        st.write("|---------|------------|-------------|-------|")
        for res in results:
            section, length_m, weight_kg, price = res
            if weight_kg is None:
                st.write(f"| {section} | {length_m if length_m else '-'} | Not found | - |")
            else:
                st.write(f"| {section} | {length_m:.2f} | {weight_kg:.2f} | {price:.2f} |")

if __name__ == "__main__":
    main()