File size: 7,643 Bytes
ed080d8
 
 
 
 
 
 
 
 
cc9a989
ed080d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import streamlit as st
import numpy as np
import pandas as pd
import time
import joblib as jb
from sklearn.pipeline import Pipeline
import plotly.express as px
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.ensemble import IsolationForest

st.set_page_config(
    page_title="Dashboard",
    page_icon='H'
)

st.markdown("""
<style>
div[data-testid="metric-container"] {
   background-color: rgba(28, 131, 225, 0.1);
   border: 1px solid rgba(28, 131, 225, 0.1);
   padding: 5% 5% 5% 10%;
   border-radius: 5px;
   color: rgb(30, 103, 119);
   overflow-wrap: break-word;
}

/* breakline for metric text         */
div[data-testid="metric-container"] > label[data-testid="stMetricLabel"] > div {
   overflow-wrap: break-word;
   white-space: break-spaces;
   color: red;
}
</style>
"""
, unsafe_allow_html=True)

st.sidebar.success('Pages')

data = pd.read_csv('demonstrate_data.csv')

health = jb.load('predict.pkl')
prep = jb.load('prep.pkl')
anomaly = jb.load('anomaly.pkl')

features = ['Pressure (psi)',	'Temperature (°C)',	'Oil Flow (L/min)',	'Vibration (mm/s)','Oil Level (%)'	,'Tool RPM (rpm)' ,'Current (A)']
health_ft = ['Temperature (°C)','Tool RPM (rpm)']
pressure_cond = 'Normal'
temp_cond = 'Normal'
oil_cond = 'Normal'
rpm_cond = 'Normal'

with open ('style.css') as f:
			st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
               
def checks(i):

    pressure_psi = data.loc[i,'Pressure (psi)']
    temperature_c = data.loc[i,'Temperature (°C)']
    vibration_mm_s = data.loc[i,'Vibration (mm/s)']
    oil_level_percent = data.loc[i,'Oil Level (%)']
    tool_rpm_rpm = data.loc[i,'Tool RPM (rpm)']

    global pressure_cond, temp_cond, oil_cond, rpm_cond,vib_cond
    



    if pressure_psi > data['Pressure (psi)'].quantile(0.98):
        pressure_cond = 'Warning! Too High'
    elif pressure_psi < data['Pressure (psi)'].quantile(0.02):
        pressure_cond = 'Warning! Too Low'
    else:
        pressure_cond = 'Normal'

    if temperature_c > data['Temperature (°C)'].quantile(0.98):
        temp_cond = 'Warning! Too High'
    else:
        temp_cond = 'Normal'

    if oil_level_percent < data['Oil Level (%)'].quantile(0.02):
        oil_cond = 'Warning! Too Low'
    else:
        oil_cond = 'Normal'

    if tool_rpm_rpm > data['Tool RPM (rpm)'].quantile(0.98):
        rpm_cond = 'Warning! Too High'
    elif tool_rpm_rpm < data['Tool RPM (rpm)'].quantile(0.02):
        rpm_cond = 'Warning! Too Low'
    else:
        rpm_cond = 'Normal'
    
    if vibration_mm_s > data['Vibration (mm/s)'].quantile(0.98):
        vib_cond = 'Warning! Too High'
    elif vibration_mm_s < data['Vibration (mm/s)'].quantile(0.02):
        vib_cond = 'Warning! Too Low'
    else:
        vib_cond = 'Normal'

    return pressure_cond,temp_cond,oil_cond,rpm_cond

def predict_health(i):
    k = pd.DataFrame(data.loc[i,health_ft]).T
    feature_map = {'Temperature (°C)':'Process temperature','Tool RPM (rpm)':'Rotational speed'}
    features = ['Process temperature','Rotational speed']
    k = k.rename(columns=feature_map)
    k = prep.fit_transform(k)
    pred = health.predict(k)
    if pred != 0:
        x = 'Likely'
    else:
        x = 'Unlikely'
    return x
    
    


def predict_anomaly(i):
    pred = anomaly.predict(pd.DataFrame(data.loc[i,features]).T)
    if pred==-1:
        x = 'Abnormal'
    else:
        x = 'Normal'
    return x



st.title("Dashboard")
update_interval = 1
update_interval = st.slider(min_value=1,max_value=5,value=None,label='Speed')

placeholder = st.empty()

run = []
run = pd.DataFrame(run,columns=data.columns)

anom = data

for i in range(1,len(data)):
    checks(i)
    with placeholder.container():      
        element1,element2,element3 = st.columns(3)
        e4, e5, e6 = st.columns(3)
        e7, e8 = st.columns(2)
        e9, e10 = st.columns(2)
        d1,d2= st.columns(2)
        d3,d4= st.columns(2)
        d5, machine_health= st.columns(2)

        element1.metric(value=data.loc[i,'Pressure (psi)'],label='Pressure (psi)',delta=round((data.loc[i,'Pressure (psi)']-data.loc[i-1,'Pressure (psi)'])))
        element2.metric(value=data.loc[i,'Temperature (°C)'],label='Temperature (°C)',delta=round((data.loc[i,'Temperature (°C)']-data.loc[i-1,'Temperature (°C)'])))
        element3.metric(value=data.loc[i,'Oil Flow (L/min)'],label='Oil Flow (L/min)',delta=round((data.loc[i,'Oil Flow (L/min)']-data.loc[i-1,'Oil Flow (L/min)'])))
        e4.metric(value=data.loc[i,'Vibration (mm/s)'],label='Vibration (mm/s)',delta=round((data.loc[i,'Vibration (mm/s)']-data.loc[i-1,'Vibration (mm/s)'])))
        e5.metric(value=data.loc[i,'Power Status'],label='Power Status')
        e6.metric(value=data.loc[i,'Oil Level (%)'],label='Oil Level (%)',delta=round((data.loc[i,'Oil Level (%)']-data.loc[i-1,'Oil Level (%)'])))
        e7.metric(value=data.loc[i,'Tool RPM (rpm)'],label='Tool RPM (rpm)',delta=round((data.loc[i,'Tool RPM (rpm)']-data.loc[i-1,'Tool RPM (rpm)'])))
        e8.metric(value=data.loc[i,'Current (A)'],label='Current (A)',delta=round((data.loc[i,'Current (A)']-data.loc[i-1,'Current (A)'])))
        e9.metric(value=data.loc[i,'Machine Status'],label='Machine Status')
        e10.metric(value=predict_anomaly(i),label='Anomaly')


        d1.metric(label=f"Pressure Levels", value=pressure_cond)
        d2.metric(label=f"Temperature Levels", value=temp_cond)
        d3.metric(label=f"Oil Levels", value=oil_cond)
        d4.metric(label=f"RPM Levels", value=rpm_cond)
        d5.metric(label=f"Vibration Levels", value=vib_cond)
        machine_health.metric(value=predict_health(i),label='Temperature/RPM Failure')
       
        new_row = pd.Series(data.loc[i,data.columns])
        #un = run.append(new_row, ignore_index=True)

        new_row = pd.DataFrame(data.loc[i,:]).T
        run = pd.concat([run,new_row])

        fig_col1, fig_col2 = st.columns(2)
        fig_col3, fig_col4 = st.columns(2)
        fig_col5, fig_col6 = st.columns(2)
        fig_col7 = st.empty()


        with fig_col1:
            st.markdown("Pressure (psi)")
            fig = px.line(data_frame=run, y = 'Pressure (psi)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
        with fig_col2:
            st.markdown("Temperature (°C)")
            fig = px.line(data_frame=run, y = 'Temperature (°C)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
        with fig_col3:
            st.markdown("Oil Flow (L/min)")
            fig = px.line(data_frame=run, y = 'Oil Flow (L/min)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
        with fig_col4:
            st.markdown("Tool RPM (rpm)")
            fig = px.line(data_frame=run, y = 'Tool RPM (rpm)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
        with fig_col5:
            st.markdown("Vibration (mm/s)")
            fig = px.line(data_frame=run, y = 'Vibration (mm/s)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
        with fig_col6:
            st.markdown("Oil Level (%)")
            fig = px.line(data_frame=run, y = 'Oil Level (%)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
        with fig_col7:
            st.markdown("Current (A)")
            fig = px.line(data_frame=run, y = 'Current (A)', x = run.index)
            fig.update_layout(width=350,height=350) 
            st.write(fig)
    
        
        time.sleep(1/update_interval)