File size: 7,090 Bytes
6b3a4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import streamlit as st
import pandas as pd
import pickle

# Load the trained models
with open('C:/Users/Samridh Joshi/Downloads/EY_PROJECT_1/EY_PROJECT_1/best_model.pkl', 'rb') as model_file:
    input_weight_model = pickle.load(model_file)
with open('C:/Users/Samridh Joshi/Downloads/EY_PROJECT_1/EY_PROJECT_1/inspection_model.pkl', 'rb') as model_file:
    machining_model = pickle.load(model_file)
with open('C:/Users/Samridh Joshi/Downloads/EY_PROJECT_1/EY_PROJECT_1/machining_model.pkl', 'rb') as model_file:
    inspection_model = pickle.load(model_file)

# Final landed cost based on grade type
final_landed_cost = {
    '1  MT  XX (25-95 dia)': 103,  
    '1  MT  XX (100-210 dia)': 113,
    '1  MT YY (25-95 dia)': 160,
    '1  MT  YY (100-125 dia)': 173,
    '1  MT  XY (25-95 dia))': 106,
    '1  MT  8319 (100-210 dia)':116,
    '1  MT  8319':104      
}

# Function to calculate raw material cost
def calculate_raw_material_cost(process_type, input_weight, grade_type):
    if process_type == 0:  # 0 represents casting
        return 0
    elif process_type == 1:  # 1 represents forging
        return input_weight * final_landed_cost[grade_type]


# Function to calculate process cost
def calculate_process_cost(process_type, input_weight):
    if process_type == 0:  # 0 represents casting
        return (input_weight * (120.57788 / 1000)*1000)
    elif process_type == 1:  # 1 represents forging
        return input_weight * 30

# Streamlit interface
st.title("EX-Works Calculator")

# User input form
with st.form("input_form"):
    part_no = st.number_input("Part No", min_value=1, step=1)
    process_type = st.selectbox("Process Type", options=[0,1])
    part_od = st.number_input("Part Od", min_value=0.0, step=0.1)
    part_id = st.number_input("Part ID", min_value=0.0, step=0.1)
    part_width = st.number_input("Part Width", min_value=0, step=1)
    finish_wt = st.number_input("Finish Wt", min_value=0.0, step=0.1)
    grade_type = st.selectbox("Grade Type", options=list(final_landed_cost.keys()))
    
    submitted = st.form_submit_button("Calculate")

    if submitted:
        # Prepare the input data for prediction
        input_data = pd.DataFrame({
            'Process type': [process_type],
            'Part Od': [part_od],
            'Part ID': [part_id],
            'Part Width': [part_width],
            'Finish Wt': [finish_wt]
        })

        # Predict the input weight
        predicted_input_weight = input_weight_model.predict(input_data)[0]

        # Calculate raw material cost
        raw_material_cost = calculate_raw_material_cost(process_type, predicted_input_weight, grade_type)
        
        # Calculate process cost
        process_cost = calculate_process_cost(process_type, predicted_input_weight)
        
        # Prepare the data for machining time prediction
        machining_data = pd.DataFrame({
            'Process type': [process_type],
            'Part Od': [part_od],
            'Part ID': [part_id],
            'Part Width': [part_width],
            'Finish Wt': [finish_wt],
            'Input Weight': [predicted_input_weight],
            'Raw material cost': [raw_material_cost],
            'Process cost': [process_cost]
        })

        # Predict the machining time
        predicted_machining_time = machining_model.predict(machining_data)[0]

        # Calculate machining cost
        machining_cost = predicted_machining_time * 375.71
        
        # Calculate scrap recovery
        scrap_recovery = (predicted_input_weight - finish_wt) * 11.5
        
        # Prepare the data for inspection time prediction
        inspection_data = pd.DataFrame({
            'Process type': [process_type],
            'Part Od': [part_od],
            'Part ID': [part_id],
            'Part Width': [part_width],
            'Finish Wt': [finish_wt],
            'Input Weight': [predicted_input_weight],
            'Raw material cost': [raw_material_cost],
            'Process cost': [process_cost],            
            'Machining Time': [predicted_machining_time],
            'Machining cost ': [machining_cost],
        })

        # Predict the inspection time
        predicted_inspection_time = inspection_model.predict(inspection_data)[0]
        
        # Calculate inspection cost
        inspection_cost = predicted_inspection_time * 435.43
        
        # Calculate total Mg cost
        total_mg_cost = raw_material_cost + process_cost + machining_cost + inspection_cost - scrap_recovery
        
        # Calculate rejection on manufacturing cost
        rejection_on_manufacturing_cost = total_mg_cost * 0.003
        
        # Calculate 'Oiling, Inspection' cost
        oiling_inspection_cost = total_mg_cost * 0.005
        
        # Calculate 'Transport and packing (BIN + 80 micron bag)' cost
        transport_packing_cost = total_mg_cost * 0.01
        
        # Calculate 'Overheads & Profit on Material'
        overheads_profit_material = raw_material_cost * 0.003

        # Calculate 'Overheads & Profit on Conversion'
        overheads_profit_conversion = (total_mg_cost - raw_material_cost) * 0.07

        # Calculate 'ICC'
        icc = total_mg_cost * 0.01
        # Calculate 'Ex-works'
        ex_works = total_mg_cost + rejection_on_manufacturing_cost + oiling_inspection_cost + \
                transport_packing_cost + overheads_profit_material + overheads_profit_conversion

        # Create DataFrame to display the results
        data = {
            'Part No': [part_no],
            'Process type': ['casting' if process_type == 0 else 'forging'],
            'Part Od': [part_od],
            'Part ID': [part_id],
            'Part Width': [part_width],
            'Finish Wt': [finish_wt],
            'Predicted Input Weight': [predicted_input_weight],
            'Grade type': [grade_type],
            'Raw material cost': [raw_material_cost],
            'Process cost': [process_cost],
            'Predicted Machining Time': [predicted_machining_time],
            'Machining Cost': [machining_cost],
            'Scrap Recovery': [scrap_recovery],
            'Predicted Inspection Time': [predicted_inspection_time],
            'Inspection Cost': [inspection_cost],
            'Total Mg Cost': [total_mg_cost],
            'Rejection on Manufacturing cost': [rejection_on_manufacturing_cost],
            'Oiling, Inspectio': [oiling_inspection_cost],  # Ensure the column name remains the same
            'Transport and packing( BIN + 80 micron bag)': [transport_packing_cost],
            'Overheads & Profit on Material': [overheads_profit_material],
            'Overheads & Profit on Conversion': [overheads_profit_conversion],
            'ICC': [icc],
            'Ex-works': [ex_works]
        }

        df = pd.DataFrame(data)
        
        st.write("Input Data, Predicted Input Weight, and Calculated Costs:")
        st.dataframe(df)