Skip to content

Commit

Permalink
Improve Charts
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine TAVANT committed Jul 1, 2024
1 parent 5849530 commit 442e91d
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 82 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ extra-dependencies = [
"nbsphinx",
"taipy",
"streamlit",

]
[tool.hatch.envs.docs.scripts]
build = "sphinx-build -b html doc/ doc/_build"

[tool.hatch.envs.serve]
extra-dependencies = [
"streamlit",
"streamlit-analytics2",
]

[tool.hatch.envs.serve.scripts]
prod = "streamlit run --server.port 8502 --server.baseUrlPath energy_forecast src/energy_forecast/dashboard/dashboard_streamlit.py"
prod = "streamlit run --server.port 8502 --server.baseUrlPath energy_forecast src/energy_forecast/dashboard/Accueil.py"

[tool.coverage.run]
source_pkgs = ["energy_forecast", "tests"]
Expand Down
21 changes: 21 additions & 0 deletions src/energy_forecast/dashboard/Accueil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import streamlit as st

if __name__ == "__main__":
st.set_page_config(
page_title="Prévision ENR",
page_icon="🌞",
)

st.markdown("""# Bienvenue dans Energy Forecast! 🌞
Cette application est une démonstration d'un tableau de bord de prévision énergétique simple.
Il est divisé en trois sections:
- <a href="weather" target = "_self">Prévision météo</a>
- <a href="power_generation" target = "_self">Prévision énergétique</a>
- <a href="consumption_prediction" target = "_self">Prévision de consommation</a>
- <a href="prediction_tempo" target = "_self">Prédiction Tempo</a>
"""
, unsafe_allow_html=True)

st.sidebar.success("Sélectionnez une démo ci-dessus.")
21 changes: 0 additions & 21 deletions src/energy_forecast/dashboard/dashboard_streamlit.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
import streamlit as st
import altair as alt
alt.renderers.set_embed_options(time_format_locale="fr-FR", format_locale="fr-FR")


@memory.cache
Expand Down Expand Up @@ -91,23 +92,27 @@ def compute_data_wind(date: str)->pd.DataFrame:
return data

if __name__ == "__main__":

st.title("Prévision meteo")
st.markdown("Cette page affiche les prévisions météorologiques pour les prochains jours."
" Les données sont obtenues à partir de [Météo France](https://www.meteofrance.com/).")
date = pd.Timestamp.now().strftime("%Y-%m-%d")
wind_data = compute_data_wind(date)


wind_barplot = alt.Chart(wind_data).mark_bar().encode(
y="wind_speed",
x="time"
)
y=alt.Y("wind_speed:Q").title("Vitesse du vent (m/s)"),
x=alt.X("time:T").title("Date")
).properties(title="Vitesse moyenne du vent en France.")
st.altair_chart(wind_barplot,
use_container_width=True
)

sun_data = compute_data_sun(date)
sun_barplot = alt.Chart(sun_data).mark_bar().encode(
y="sun_flux",
x="time"
)
y=alt.Y("sun_flux:Q").title("Flux solaire (W/m^2)"),
x=alt.X("time:T").title("Date")
).properties(title="Flux solaire moyen en France.")
st.altair_chart(sun_barplot,
use_container_width=True
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import pandas as pd
import streamlit as st
import altair as alt
alt.renderers.set_embed_options(time_format_locale="fr-FR", format_locale="fr-FR")


@memory.cache
def compute_data_pv_power(date: str)->pd.DataFrame:
Expand Down Expand Up @@ -110,6 +112,7 @@ def compute_energy(date:str):
energy = r.read_file()

energy = energy[["Eolien", "Solaire"]]
energy.rename(columns={"Eolien": "Eolien Production", "Solaire": "PV Production"}, inplace=True)
offset_days = 5
history_start = pd.Timestamp(date) - pd.Timedelta(f"{offset_days} days")
energy = energy[history_start:]
Expand All @@ -132,29 +135,34 @@ def compute_energy(date:str):
energy = energy[energy["time"].dt.minute == 0]

st.title("Prévision de production ENR")
st.markdown("Cette page affiche les prévisions de production d'énergie renouvelable pour la date sélectionnée."
" Les données sont obtenues à partir de [RTE](https://www.rte-france.com/eco2mix/la-production-delectricite-en-temps-reel).")


energy_long = energy.melt(id_vars="time", var_name="source", value_name="power")
eolen_long = energy_long[energy_long["source"].str.contains("Eolien")]
pv_long = energy_long[energy_long["source"].str.contains("PV")]

eolen_title = alt.Title("Production Eolien",
subtitle="Production historique et prévisionnelle")

wind_history = alt.Chart(energy).mark_line().encode(
y="Eolien",
x="time"
).interactive()
wind_prediction = alt.Chart(energy).mark_line(color="red").encode(
y="Eolien Prediction",
x="time"
).interactive()
wind_barplot = wind_prediction + wind_history
st.altair_chart(wind_barplot,
eolen_chart = alt.Chart(eolen_long, title=eolen_title).mark_line().encode(
x=alt.X("time:T", title="Date"),
y=alt.Y("power:Q", title="Production (MW)"),
color=alt.Color("source:N", title="Type de production"),
)

st.altair_chart(eolen_chart,
use_container_width=True
)

sun_history = alt.Chart(energy).mark_line().encode(
y="Solaire",
x="time"
)
sun_prediction = alt.Chart(energy).mark_line(color="red").encode(
y="PV Prediction",
x="time"
sun_title = alt.Title("Production Solaire",
subtitle="Production historique et prévisionnelle")
sun_chart = alt.Chart(pv_long, title=sun_title).mark_line().encode(
x=alt.X("time:T", title="Date"),
y=alt.Y("power:Q", title="Production (MW)"),
color=alt.Color("source:N", title="Type de production"),
)
sun_barplot = sun_prediction + sun_history
st.altair_chart(sun_barplot,
st.altair_chart(sun_chart,
use_container_width=True
)
55 changes: 55 additions & 0 deletions src/energy_forecast/dashboard/pages/3_Consomation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Create a Streamlit page to display the consumption forecast.
The Consumption forecast is obtained from the :class:`energy_forecast.consumption_forecast.PredictionForecastAPI` class.
It uses RTE predictions.
"""

from energy_forecast.consumption_forecast import PredictionForecastAPI
from energy_forecast import ROOT_DIR
import pandas as pd
import streamlit as st
import altair as alt
alt.renderers.set_embed_options(time_format_locale="fr-FR", format_locale="fr-FR")

@st.cache
def get_weekly_forecast(secret: str)->pd.DataFrame:
"""Get the weekly forecast for the total electricity consumption.
Parameters
----------
secret : str
The secret key to access the RTE API.
Returns
-------
pd.DataFrame
The weekly forecast for the total electricity consumption.
The columns are ["time", "predicted_consumption"]
"""
consumption_forecast_api = PredictionForecastAPI(secret=secret)
consumption_forecast = consumption_forecast_api.get_weekly_forecast(
start_date=pd.Timestamp.now().date()
).reset_index()
return consumption_forecast

if __name__ == "__main__":
env_file = ROOT_DIR / ".env"
with env_file.open("r") as f:
secret = f.readline().strip().split("=", 1)[1]
consumption_forecast = get_weekly_forecast(secret)


st.title("Prévision de consomation electrique total")
st.markdown("Prévision de consomation electrique total pour la semaine prochaine"
" en utilisant les données de RTE.")

title = alt.Title("Consomation electrique total prévue", anchor="start",
subtitle="France métropolitaine")

consumption_chart = alt.Chart(consumption_forecast, title=title).mark_line().encode(
y=alt.Y("predicted_consumption:Q", title="Consomation electrique (MW)"),
x=alt.X("time:T", title="Date")
)
st.altair_chart(consumption_chart,
use_container_width=True
)
33 changes: 0 additions & 33 deletions src/energy_forecast/dashboard/pages/3_consumption_prediction.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

for offset, col in zip(range(3), [col1, col2, col3]):
text = f"Prévision pour le {today + pd.Timedelta(days=offset)}"
text += "\n\n <h1 style='color: white;'> Jour Bleu </h1>"
text += "\n\n <h1 style='color: white;'> Jour Bleu </h1> \n\n"
# an html blue square the size of the column with the text and H1 in white
col.markdown(f"<div style='background-color: blue ; padding: 10px ; border-radius: 10px ; color: white ; text-align: center'>{text}</div>", unsafe_allow_html=True)
col.markdown(f"<div style='background-color: blue ; padding: 10px ; border-radius: 10px ; color: white ; text-align: center'>{text}</div> \n", unsafe_allow_html=True)
col.markdown("\n")

0 comments on commit 442e91d

Please sign in to comment.