je veux une app qui me permet de faire un dashboard de consommation de produits chimiques à partir d'un tableau qui existent déjà et qui répertorie : CHEM_DATE, INJECTION_POINT, CHEM_PRODUCT_NAME, TREATED_FLUID, TREATED_FLOWRATE, TARGET_INJECTION_RATE, TARGET_PPM, IS_FIELD_TEST, IS_BATCH, BSW_TREATED_FLUID, TEMP_TREATED_FLUID, PRESSURE_TREATED_FLUID, TDS_TREATED_FLUID, PH_TREATED_FLUID, SUBSTITUTE_PRODUCT
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime
import numpy as np
st.set_page_config(layout="wide", page_title="Dashboard Consommation Produits Chimiques")
# Fonction pour charger les données (simulation)
@st.cache_data
def load_data():
# Simulation de données
dates = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D')
np.random.seed(42)
data = {
'CHEM_DATE': dates,
'INJECTION_POINT': np.random.choice(['Point A', 'Point B', 'Point C'], size=len(dates)),
'CHEM_PRODUCT_NAME': np.random.choice(['Produit X', 'Produit Y', 'Produit Z'], size=len(dates)),
'TREATED_FLUID': np.random.choice(['Eau', 'Huile', 'Mélange'], size=len(dates)),
'TREATED_FLOWRATE': np.random.uniform(100, 1000, len(dates)),
'TARGET_INJECTION_RATE': np.random.uniform(1, 10, len(dates)),
'TARGET_PPM': np.random.uniform(10, 100, len(dates)),
'IS_FIELD_TEST': np.random.choice([True, False], size=len(dates)),
'IS_BATCH': np.random.choice([True, False], size=len(dates)),
'BSW_TREATED_FLUID': np.random.uniform(0, 100, len(dates)),
'TEMP_TREATED_FLUID': np.random.uniform(20, 80, len(dates)),
'PRESSURE_TREATED_FLUID': np.random.uniform(1, 50, len(dates)),
'TDS_TREATED_FLUID': np.random.uniform(1000, 5000, len(dates)),
'PH_TREATED_FLUID': np.random.uniform(5, 9, len(dates)),
'SUBSTITUTE_PRODUCT': np.random.choice(['Sub A', 'Sub B', 'None'], size=len(dates))
}
return pd.DataFrame(data)
# Chargement des données
df = load_data()
# Titre de l'application
st.title("Dashboard de Consommation des Produits Chimiques")
# Filtres dans la barre latérale
st.sidebar.header("Filtres")
# Sélection de la période
date_range = st.sidebar.date_input(
"Sélectionner la période",
[df['CHEM_DATE'].min(), df['CHEM_DATE'].max()]
)
# Sélection des points d'injection
selected_points = st.sidebar.multiselect(
"Points d'injection",
options=df['INJECTION_POINT'].unique(),
default=df['INJECTION_POINT'].unique()
)
# Sélection des produits
selected_products = st.sidebar.multiselect(
"Produits chimiques",
options=df['CHEM_PRODUCT_NAME'].unique(),
default=df['CHEM_PRODUCT_NAME'].unique()
)
# Filtrage des données
mask = (
(df['CHEM_DATE'].dt.date >= date_range[0]) &
(df['CHEM_DATE'].dt.date <= date_range[1]) &
(df['INJECTION_POINT'].isin(selected_points)) &
(df['CHEM_PRODUCT_NAME'].isin(selected_products))
)
filtered_df = df[mask]
# Layout en colonnes
col1, col2 = st.columns(2)
with col1:
# Graphique de consommation par produit
fig_consumption = px.bar(
filtered_df.groupby('CHEM_PRODUCT_NAME')['TARGET_INJECTION_RATE'].mean().reset_index(),
x='CHEM_PRODUCT_NAME',
y='TARGET_INJECTION_RATE',
title="Taux d'injection moyen par produit"
)
st.plotly_chart(fig_consumption, use_container_width=True)
with col2:
# Graphique de tendance temporelle
fig_trend = px.line(
filtered_df,
x='CHEM_DATE',
y='TARGET_INJECTION_RATE',
color='CHEM_PRODUCT_NAME',
title="Évolution du taux d'injection dans le temps"
)
st.plotly_chart(fig_trend, use_container_width=True)
# Métriques clés
col3, col4, col5 = st.columns(3)
with col3:
avg_rate = filtered_df['TARGET_INJECTION_RATE'].mean()
st.metric("Taux d'injection moyen", f"{avg_rate:.2f}")
with col4:
avg_ppm = filtered_df['TARGET_PPM'].mean()
st.metric("PPM moyen", f"{avg_ppm:.2f}")
with col5:
avg_temp = filtered_df['TEMP_TREATED_FLUID'].mean()
st.metric("Température moyenne", f"{avg_temp:.1f}°C")
# Tableau détaillé
st.subheader("Données détaillées")
st.dataframe(
filtered_df.style.format({
'TARGET_INJECTION_RATE': '{:.2f}',
'TARGET_PPM': '{:.2f}',
'TEMP_TREATED_FLUID': '{:.1f}',
'PRESSURE_TREATED_FLUID': '{:.1f}',
'PH_TREATED_FLUID': '{:.1f}'
})
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?