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 itertools import count st.set_page_config( page_title="Dashboard", page_icon='H' ) st.markdown(""" """ , 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'', 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)