File size: 5,394 Bytes
95b9724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a2cdc7
95b9724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9473f46
95b9724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15f34c8
95b9724
15f34c8
 
 
 
95b9724
15f34c8
95b9724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6f0804
95b9724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15f34c8
95b9724
 
 
 
4a74b85
95b9724
9fecffe
95b9724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4afd35
b2cfd57
95b9724
b2cfd57
95b9724
 
 
 
 
 
 
 
 
0b130b2
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
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
import pickle
import streamlit as st 

st.title('Repair Time Prediction')
#DLoading the ataset
#df = pd.read_csv('repair_time_sample_50k_modified2.csv')

#new_data = df
#df.drop(['SRU serial number','Date of Manufacture', 'Snag Description'], axis = 1, inplace=True)


# DATA from user
def user_report():
  Aircraft_Type = st.sidebar.selectbox('Aircraft Type',("AH-64","UH-60","UH-63","UH-62","UH-61","AH-65"))
  if Aircraft_Type=="AH-64":
      Aircraft_Type=0
  elif Aircraft_Type=="UH-60":
      Aircraft_Type=2
  elif Aircraft_Type=="UH-63":
      Aircraft_Type=5
  elif Aircraft_Type=="UH-62":
      Aircraft_Type=4
  elif Aircraft_Type=="UH-61":
      Aircraft_Type=3
  else:
      Aircraft_Type=1
  manufacturer = st.sidebar.selectbox("Manufacturer",
        ("JKL Company", "GHI Company","AGS Company","ABC Company","XYZ Company" ))
  if manufacturer=='JKL Company':
      manufacturer=3
  elif manufacturer=="GHI Company":
      manufacturer=2
  elif manufacturer=="AGS Company":
      manufacturer=1
  elif manufacturer=="ABC Company":
      manufacturer =0
  else:
      manufacturer=4
  component_age = st.sidebar.slider('Component Age (in hours)', 500,2000, 600 )
  Issue_category= st.sidebar.selectbox("Issue Category",
        ("Display", "Unservicable","Bootup Problem","Engine Failure","Electrical Fault" ))
  if Issue_category=='Display':
      Issue_category=1
  elif Issue_category=="Unservicable":
      Issue_category=4
  elif Issue_category=="Bootup Problem":
      Issue_category=0
  elif Issue_category=="Engine Failure":
      Issue_category=3
  else:
      Issue_category=2
  Snag_Severity	= st.sidebar.selectbox("Snag Severity",
        ("Low", "Medium","High" ))
  if Snag_Severity	=='Low':
      Snag_Severity=1
  elif Snag_Severity=="Medium":
      Snag_Severity	=2
  else:
       Snag_Severity=0
  Customer= st.sidebar.selectbox("Customer",
        ("IAF", "ARMY","NAVY" ))
  if Customer	=='IAF':
      Customer=1
  elif Customer=="ARMY":
      Customer	=0
  else:
       Customer=2
  Technician_Skill_level= st.sidebar.selectbox("Technician Skill level",
        ("Expert", "Intermediate","Novice" ))
  if Technician_Skill_level	=='Expert':
      Technician_Skill_level=0
  elif Technician_Skill_level=="Intermediate":
      Technician_Skill_level	=1
  else:
       Technician_Skill_level=2
  prior_maintainence = st.sidebar.selectbox('Prior Maintainence',("Regular","Irregular"))
  if prior_maintainence =='Regular':
      prior_maintainence=1
  else:
      prior_maintainence=0
  Logistics_Time = st.sidebar.slider('Logistics Time (hr)', 2,21, 5 )
  total_operating_hours = st.sidebar.slider('Total Operating Hours)', 50,2000, 500 )
  operating_temperature = st.sidebar.slider('Operating Temperature', 10,25, 15 )
  previous_number_of_repairs = st.sidebar.number_input('Enter the Previous Number of Repairs Undergone  0 to 3 )',min_value=0,max_value=3,step=1)
  Power_Input_Voltage= st.sidebar.slider('Power Input Voltage (V)',100,133,115)  


  user_report_data = {
      'Aircraft Type':Aircraft_Type,
      'Manufacturer':manufacturer,
      'Component_Age':component_age,
      'Issue_category':Issue_category,
      'Snag Severity': Snag_Severity,
      'Customer':Customer,
      'Technician Skill level':Technician_Skill_level,
      'Prior Maintenance': prior_maintainence,
      'Logistics Time (hr)':Logistics_Time,
      'total_operating_hours':total_operating_hours,
      'operating_temperature':operating_temperature,
      'previous_number_of_repairs':previous_number_of_repairs,
      'Power_Input_Voltage':Power_Input_Voltage
           
  }
  report_data = pd.DataFrame(user_report_data, index=[0])
  return report_data    
    
#Customer Data
user_data = user_report()
st.header("Component Details")
st.write(user_data)

def preprocess_dataset(X):  
  x = X.values #returns a numpy array
  min_max_scaler = preprocessing.MinMaxScaler()
  x_scaled = min_max_scaler.fit_transform(x)
  X_df = pd.DataFrame(x_scaled)
  return X_df

def label_encoding(data):
  le = LabelEncoder()
  cat = data.select_dtypes(include='O').keys()
  categ = list(cat)
  data[categ] = data[categ].apply(le.fit_transform)
  # X = data.loc[:,data.columns!= "Time required for repair (in hours)"]
  # y = data['Time required for repair (in hours)']
  # return X,y
  return data

def prediction(df):
  #X = df.loc[:,df.columns!= "Time required for repair (in hours)"]
  #y = df['Time required for repair (in hours)']
  #X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)
  #print(X_train.shape)
  #print(X_test.shape)
  #X_test_encoded = label_encoding(df)
  #X_test_df = preprocess_dataset(df)
  x_model = pickle.load(open('repair_time_model.pkl','rb'))
  pred = x_model.predict(df)
  #X_test['Actual_time_to_repair'] = y_test
  #X_test['Predicted_time_to_repair'] = pred
  #X_test.to_csv(r'/content/drive/MyDrive/Colab Notebooks/HAL/repair_time_prediction_results.csv')
  #print(X_test.head())
  return pred
    
y_pred = prediction(user_data)

if st.button("Predict"):
    st.subheader(f"Time required to Repair the Component is {y_pred[0]} hours")