Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intégration de la base Postgres #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -169,3 +169,6 @@ data/silver/weather_forecasts/*.nc
data/geo/*.nc
.vscode/settings.json
data/bronze/observations/*.csv.gz

#Docker volumes
postgres/postgres_volume/*
131 changes: 83 additions & 48 deletions data/gold/our_tempo_prediction.csv
Original file line number Diff line number Diff line change
@@ -1,49 +1,84 @@
,Type_de_jour_TEMPO,our_tempo_J-1,our_tempo_J-2,our_tempo_J-3
2024-09-01,BLUE,prediction_bleu,,
2024-09-02,BLUE,prediction_bleu,,
2024-09-03,BLUE,prediction_bleu,,
2024-09-04,BLUE,prediction_bleu,,
2024-09-05,BLUE,prediction_bleu,,
2024-09-06,BLUE,prediction_bleu,,
2024-09-07,BLUE,prediction_bleu,,
2024-09-08,BLUE,prediction_bleu,,
2024-09-09,BLUE,prediction_bleu,,
2024-09-10,BLUE,prediction_bleu,,
2024-09-11,BLUE,prediction_bleu,,
2024-09-12,BLUE,prediction_bleu,,
2024-09-13,BLUE,prediction_bleu,,
2024-09-14,BLUE,prediction_bleu,,
2024-09-15,BLUE,prediction_bleu,,
2024-09-16,BLUE,prediction_bleu,,
2024-09-17,BLUE,prediction_bleu,,
2024-09-18,BLUE,prediction_bleu,,
2024-09-19,BLUE,prediction_bleu,,
2024-09-20,BLUE,prediction_bleu,,
2024-09-21,BLUE,prediction_bleu,,
2024-09-22,BLUE,prediction_bleu,,
2024-09-23,BLUE,prediction_bleu,,
2024-09-24,BLUE,prediction_bleu,,
2024-09-25,BLUE,prediction_bleu,,
2024-09-26,BLUE,prediction_bleu,,
2024-09-27,BLUE,prediction_bleu,,
2024-09-28,BLUE,prediction_bleu,,
2024-09-29,BLUE,prediction_bleu,,
2024-09-30,BLUE,prediction_bleu,,
2024-10-01,BLUE,prediction_bleu,,
2024-10-02,BLUE,prediction_bleu,,
2024-10-03,BLUE,prediction_bleu,,
2024-10-04,BLUE,prediction_bleu,,
2024-10-05,BLUE,prediction_bleu,,
2024-10-06,BLUE,prediction_bleu,,
2024-10-07,BLUE,prediction_bleu,,
2024-10-08,BLUE,prediction_bleu,,
2024-10-09,BLUE,prediction_bleu,prediction_bleu,prediction_bleu
2024-10-10,BLUE,prediction_bleu,prediction_bleu,prediction_bleu
2024-10-11,BLUE,prediction_bleu,prediction_bleu,prediction_bleu
2024-10-12,BLUE,prediction_bleu,prediction_bleu,prediction_bleu
2024-10-13,BLUE,prediction_bleu,prediction_bleu,prediction_bleu
2024-10-14,BLUE,prediction_bleu,,
2024-10-15,BLUE,prediction_bleu,,
2024-10-16,BLUE,prediction_bleu,prediction_bleu,
2024-10-17,,,prediction_bleu,prediction_bleu
2024-10-18,,,,prediction_bleu
2024-09-01,BLUE,BLUE,,
2024-09-02,BLUE,BLUE,,
2024-09-03,BLUE,BLUE,,
2024-09-04,BLUE,BLUE,,
2024-09-05,BLUE,BLUE,,
2024-09-06,BLUE,BLUE,,
2024-09-07,BLUE,BLUE,,
2024-09-08,BLUE,BLUE,,
2024-09-09,BLUE,BLUE,,
2024-09-10,BLUE,BLUE,,
2024-09-11,BLUE,BLUE,,
2024-09-12,BLUE,BLUE,,
2024-09-13,BLUE,BLUE,,
2024-09-14,BLUE,BLUE,,
2024-09-15,BLUE,BLUE,,
2024-09-16,BLUE,BLUE,,
2024-09-17,BLUE,BLUE,,
2024-09-18,BLUE,BLUE,,
2024-09-19,BLUE,BLUE,,
2024-09-20,BLUE,BLUE,,
2024-09-21,BLUE,BLUE,,
2024-09-22,BLUE,BLUE,,
2024-09-23,BLUE,BLUE,,
2024-09-24,BLUE,BLUE,,
2024-09-25,BLUE,BLUE,,
2024-09-26,BLUE,BLUE,,
2024-09-27,BLUE,BLUE,,
2024-09-28,BLUE,BLUE,,
2024-09-29,BLUE,BLUE,,
2024-09-30,BLUE,BLUE,,
2024-10-01,BLUE,BLUE,,
2024-10-02,BLUE,BLUE,,
2024-10-03,BLUE,BLUE,,
2024-10-04,BLUE,BLUE,,
2024-10-05,BLUE,BLUE,,
2024-10-06,BLUE,BLUE,,
2024-10-07,BLUE,BLUE,,
2024-10-08,BLUE,BLUE,,
2024-10-09,BLUE,BLUE,BLUE,BLUE
2024-10-10,BLUE,BLUE,BLUE,BLUE
2024-10-11,BLUE,BLUE,BLUE,BLUE
2024-10-12,BLUE,BLUE,BLUE,BLUE
2024-10-13,BLUE,BLUE,BLUE,BLUE
2024-10-14,BLUE,BLUE,,
2024-10-15,BLUE,BLUE,,
2024-10-16,BLUE,BLUE,BLUE,
2024-10-17,BLUE,BLUE,BLUE,BLUE
2024-10-18,BLUE,BLUE,,BLUE
2024-10-19,BLUE,BLUE,,
2024-10-20,BLUE,BLUE,,
2024-10-21,BLUE,BLUE,,
2024-10-22,BLUE,BLUE,,
2024-10-23,BLUE,BLUE,,
2024-10-24,BLUE,BLUE,,
2024-10-25,BLUE,BLUE,,
2024-10-26,BLUE,BLUE,,
2024-10-27,BLUE,BLUE,,
2024-10-28,BLUE,BLUE,BLUE,BLUE
2024-10-29,BLUE,BLUE,BLUE,BLUE
2024-10-30,BLUE,BLUE,BLUE,BLUE
2024-10-31,BLUE,BLUE,,BLUE
2024-11-01,BLUE,BLUE,BLUE,
2024-11-02,BLUE,BLUE,BLUE,BLUE
2024-11-03,BLUE,BLUE,BLUE,BLUE
2024-11-04,BLUE,BLUE,BLUE,BLUE
2024-11-05,BLUE,BLUE,BLUE,WHITE
2024-11-06,BLUE,BLUE,BLUE,BLUE
2024-11-07,BLUE,BLUE,BLUE,BLUE
2024-11-08,BLUE,BLUE,BLUE,BLUE
2024-11-09,BLUE,BLUE,BLUE,BLUE
2024-11-10,BLUE,BLUE,BLUE,BLUE
2024-11-11,BLUE,BLUE,BLUE,BLUE
2024-11-12,BLUE,BLUE,BLUE,BLUE
2024-11-13,BLUE,WHITE,BLUE,WHITE
2024-11-14,WHITE,WHITE,WHITE,WHITE
2024-11-15,WHITE,WHITE,WHITE,WHITE
2024-11-16,BLUE,BLUE,BLUE,BLUE
2024-11-17,BLUE,BLUE,BLUE,BLUE
2024-11-18,BLUE,BLUE,BLUE,BLUE
2024-11-19,BLUE,BLUE,,BLUE
2024-11-20,,WHITE,WHITE,
2024-11-21,,,WHITE,WHITE
2024-11-22,,,,WHITE
29 changes: 29 additions & 0 deletions postgres/compose-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3.8"
services:
postgres:
image: postgres:17-alpine
restart: unless-stopped
env_file:
- postgres.env
- secrets.env
ports:
- "5434:5432"
volumes:
- ./postgres_volume:/var/lib/postgresql/data
- ./init_scripts:/docker-entrypoint-initdb.d
# pgadmin:
# image: dpage/pgadmin4
# restart: always
# environment:
# PGADMIN_DEFAULT_EMAIL: stress.energetic@d4g.com
# PGADMIN_DEFAULT_PASSWORD_FILE: /run/secrets/pgadmin_default_password
# secrets:
# - pgadmin_default_password
# ports:
# - "8880:80"
# depends_on:
# - postgres


volumes:
db:
61 changes: 61 additions & 0 deletions postgres/init_scripts/01_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
\c stress_energetic;

CREATE TABLE IF NOT EXISTS eco2mix_raw (
date_heure TIMESTAMP,
consommation FLOAT,
eolien FLOAT,
solaire FLOAT
);

CREATE TABLE IF NOT EXISTS pred_conso_rte (
date_heure TIMESTAMP,
consommation FLOAT
);

CREATE TABLE IF NOT EXISTS forecast_flux_solaire (
date_heure TIMESTAMP,
departement CHAR,
delta_hours_pred FLOAT,
flux_solaire FLOAT
);

CREATE TABLE IF NOT EXISTS forecast_vent (
date_heure TIMESTAMP,
departement CHAR,
delta_hours_pred FLOAT,
vent FLOAT
);

CREATE TABLE IF NOT EXISTS forecast_ENR (
date_heure TIMESTAMP,
delta_hours_pred FLOAT,
eolien FLOAT,
solaire FLOAT
);

-- Je ne pense pas que ça soit nécessaire, l'information est gardée indirectement
-- dans les données pour prédire le jour tempo
-- CREATE TABLE IF NOT EXISTS temperature (
-- date_heure TIMESTAMP,
-- temperature FLOAT
-- );

CREATE TABLE IF NOT EXISTS prep_prediction_tempo (
date DATE,
consommation FLOAT,
eolien FLOAT,
solaire FLOAT,
temperature FLOAT,
production_nette FLOAT,
production_nette_q40 FLOAT,
production_nette_q80 FLOAT,
mean_temp_q30 FLOAT,
jour_tempo CHAR,
);

CREATE TABLE IF NOT EXISTS prediction_tempo (
date DATE,
delta_hours_pred FLOAT,
eolien FLOAT,
solaire FLOAT
);
13 changes: 13 additions & 0 deletions postgres/init_scripts/02_setup_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Création de l'utilisateur super
CREATE ROLE super_user WITH LOGIN PASSWORD '$$POSTGRES_SUPER_USER_PASSWORD$$' SUPERUSER;

-- Création de l'utilisateur read-only
CREATE ROLE readonly_user WITH LOGIN PASSWORD '$$POSTGRES_READONLY_USER_PASSWORD$$';

-- Accorder des privilèges de lecture
GRANT CONNECT ON DATABASE stress_energetic TO readonly_user;
GRANT USAGE ON SCHEMA public TO readonly_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_user;

-- Pour accorder des privilèges de lecture sur les nouvelles tables créées ultérieurement
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly_user;
3 changes: 3 additions & 0 deletions postgres/postgres.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_USER=root
POSTGRES_HOST=postgres
POSTGRES_DB=stress_energetic
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ dependencies = [
"bokeh>=3.4",
"joblib",
"python-dotenv",
"sqlalchemy>=2.0.36",
]

[project.urls]
Loading