Créer moi une application qui permet de crée un dashboard à partir d'une table existante que l'on importe avec cette dénomination : CHEM_TEST.LOGBOOK et qui a plusieurs colonnes : 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, il faut que le dashboard puisse être trié par type de chimique, par date et aussi par point d'injection. En utilisant que des librairies par défaut streamlit.
Drop files here
or click to upload
import streamlit as st
import pandas as pd
import plotly.express as px
from datetime import datetime
# Configuration de la page
st.set_page_config(page_title="Chemical Treatment Dashboard", layout="wide")
# Titre de l'application
st.title("Chemical Treatment Dashboard")
# Création d'un DataFrame exemple (à remplacer par votre connexion réelle à CHEM_TEST.LOGBOOK)
@st.cache_data
def load_data():
# Remplacer ceci par votre vraie connexion à la base de données
df = pd.DataFrame({
'CHEM_DATE': pd.date_range(start='2023-01-01', periods=100),
'INJECTION_POINT': ['Point A', 'Point B', 'Point C'] * 34,
'CHEM_PRODUCT_NAME': ['Chemical X', 'Chemical Y', 'Chemical Z'] * 34,
'TREATED_FLUID': ['Water', 'Oil', 'Gas'] * 34,
'TREATED_FLOWRATE': [100 + i for i in range(100)],
'TARGET_INJECTION_RATE': [5 + i/10 for i in range(100)],
'TARGET_PPM': [50 + i for i in range(100)],
'IS_FIELD_TEST': [True, False] * 50,
'IS_BATCH': [True, False] * 50,
'BSW_TREATED_FLUID': [i/100 for i in range(100)],
'TEMP_TREATED_FLUID': [30 + i/10 for i in range(100)],
'PRESSURE_TREATED_FLUID': [100 + i for i in range(100)],
'TDS_TREATED_FLUID': [1000 + i*10 for i in range(100)],
'PH_TREATED_FLUID': [6 + i/100 for i in range(100)],
'SUBSTITUTE_PRODUCT': ['Sub A', 'Sub B', 'None'] * 34
})
return df
df = load_data()
# Création des filtres dans la sidebar
st.sidebar.header("Filtres")
# Filtre de date
date_range = st.sidebar.date_input(
"Sélectionner la période",
[df['CHEM_DATE'].min(), df['CHEM_DATE'].max()]
)
# Filtre de produit chimique
all_chemicals = sorted(df['CHEM_PRODUCT_NAME'].unique())
selected_chemicals = st.sidebar.multiselect(
"Sélectionner les produits chimiques",
all_chemicals,
default=all_chemicals
)
# Filtre de point d'injection
all_points = sorted(df['INJECTION_POINT'].unique())
selected_points = st.sidebar.multiselect(
"Sélectionner les points d'injection",
all_points,
default=all_points
)
# Filtrage des données
mask = (
(df['CHEM_DATE'].dt.date >= date_range[0])
& (df['CHEM_DATE'].dt.date <= date_range[1])
& (df['CHEM_PRODUCT_NAME'].isin(selected_chemicals))
& (df['INJECTION_POINT'].isin(selected_points))
)
filtered_df = df[mask]
# Création du dashboard
col1, col2 = st.columns(2)
with col1:
# Graphique de l'utilisation des produits chimiques dans le temps
fig1 = px.line(filtered_df,
x='CHEM_DATE',
y='TARGET_INJECTION_RATE',
color='CHEM_PRODUCT_NAME',
title="Taux d'injection par produit chimique")
st.plotly_chart(fig1, use_container_width=True)
# Distribution des points d'injection
fig3 = px.pie(filtered_df,
names='INJECTION_POINT',
title="Distribution des points d'injection")
st.plotly_chart(fig3, use_container_width=True)
with col2:
# Graphique des PPM par produit
fig2 = px.box(filtered_df,
x='CHEM_PRODUCT_NAME',
y='TARGET_PPM',
title="Distribution des PPM par produit")
st.plotly_chart(fig2, use_container_width=True)
# Température vs Pression
fig4 = px.scatter(filtered_df,
x='TEMP_TREATED_FLUID',
y='PRESSURE_TREATED_FLUID',
color='INJECTION_POINT',
title="Température vs Pression par point d'injection")
st.plotly_chart(fig4, use_container_width=True)
# Tableau de données filtré
st.header("Données détaillées")
st.dataframe(filtered_df)
# Statistiques de base
st.header("Statistiques")
col3, col4, col5 = st.columns(3)
with col3:
st.metric("Nombre total d'injections", len(filtered_df))
with col4:
st.metric("Taux d'injection moyen",
f"{filtered_df['TARGET_INJECTION_RATE'].mean():.2f}")
with col5:
st.metric("PPM moyen",
f"{filtered_df['TARGET_PPM'].mean():.2f}")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?