Py.Cafe

GabrielProdEng/

streamlit-manufacturing-productivity

📊 Dashboard de Produtividade na Manufatura

DocsPricing
  • app.py
  • requirements.txt
app.py
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
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px

# Configuração do layout
st.set_page_config(page_title="Dashboard de Produtividade", layout="wide")

# Gerando dados hipotéticos
np.random.seed(42)

data = {
    "Machine": ["M1", "M2", "M3", "M4", "M5"] * 3,
    "Shift": ["Morning"] * 5 + ["Afternoon"] * 5 + ["Night"] * 5,
    "Produced": np.random.randint(100, 200, 15),
    "Rejected": np.random.randint(2, 10, 15),
    "Labor Hours": np.random.randint(8, 12, 15),
    "Energy Consumption": np.random.randint(50, 100, 15),
}

df = pd.DataFrame(data)
df = df.dropna(subset=["Machine"])
df["Machine"] = df["Machine"].astype(str)

# Conversão de tipos para evitar erros
df["Produced"] = df["Produced"].astype(int)
df["Rejected"] = df["Rejected"].astype(int)
df["Labor Hours"] = df["Labor Hours"].astype(float)
df["Energy Consumption"] = df["Energy Consumption"].astype(float)

# Criando a coluna de eficiência
df["Efficiency (%)"] = ((df["Produced"] - df["Rejected"]) / df["Produced"]) * 100

# Interface do Streamlit
st.title("📊 Dashboard de Produtividade na Manufatura")

# Filtros interativos
shift_filter = st.selectbox("Selecione o Turno", ["Todos"] + sorted(df["Shift"].unique()))
machine_filter = st.selectbox("Selecione a Máquina", ["Todas"] + sorted(df["Machine"].unique()))

# Aplicando filtros
filtered_df = df.copy()
if shift_filter != "Todos":
    filtered_df = filtered_df[filtered_df["Shift"] == shift_filter]
if machine_filter != "Todas":
    filtered_df = filtered_df[filtered_df["Machine"] == machine_filter]

# Garantindo que há dados para exibir
if filtered_df.empty:
    st.warning("Nenhum dado disponível para os filtros selecionados.")
else:
    # KPI Cards
    col1, col2, col3 = st.columns(3)
    
    col1.metric("📦 Produção Média", round(filtered_df["Produced"].mean(), 2) if not filtered_df.empty else "N/A")
    col2.metric("⚠️ Rejeições Médias", round(filtered_df["Rejected"].mean(), 2) if not filtered_df.empty else "N/A")
    col3.metric("🔋 Consumo Médio de Energia", round(filtered_df["Energy Consumption"].mean(), 2) if not filtered_df.empty else "N/A")

    
# Conclusão
st.subheader("📌 Conclusão")
st.write("""
Esse dashboard fornece uma visão geral da produtividade das máquinas ao longo dos turnos,
com indicadores-chave e uma análise de eficiência básica.

Use os filtros para explorar os dados e otimizar processos produtivos!
""")