Skip to content
Open
Show file tree
Hide file tree
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: 2 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'projet_cc'
version: '1.0.0'
version: '1.0.1'
config-version: 2

profile: 'projet_cc'
Expand All @@ -13,3 +13,4 @@ clean-targets: ["target", "dbt_packages"]
models:
projet_cc:
+materialized: view
marts:
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marts: is added under models.projet_cc but has no value/config. In YAML this becomes null, and dbt model configs expect a mapping for subdirectories; this can lead to dbt parsing/runtime errors or silently not applying intended marts configuration. Either remove this key or give it an explicit config block (e.g., set +schema / +materialized, or at least {} if it’s meant as a placeholder).

Suggested change
marts:
marts: {}

Copilot uses AI. Check for mistakes.
30 changes: 30 additions & 0 deletions models/marts/_marts_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

version: 2

models:
- name: mart_mensq_temperatures_sup_20deg
description: >
Table métier utilisée par le dashboard Streamlit.
Contient les mois avec température moyenne supérieure à 20°C.

columns:
- name: annee
tests:
- not_null

- name: mois
tests:
- not_null
Comment on lines +8 to +17
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema tests/documentation for mart_mensq_temperatures_sup_20deg don’t match the model it references. mart_mensq_temperatures_sup_20deg is a passthrough of int_mensq_temperatures_sup_20deg, which outputs ANNEE, Z_GEO, nb_stations, moy_nuits_ge_20 (no mois). As written, the mois not_null test will error because the column doesn’t exist, and the description claims the table contains “mois” data. Update the column list/tests/description to reflect the actual columns (or adjust the underlying model to produce mois if that’s the intent).

Suggested change
Contient les mois avec température moyenne supérieure à 20°C.
columns:
- name: annee
tests:
- not_null
- name: mois
tests:
- not_null
Contient, par année et zone géographique, des indicateurs sur les nuits avec température minimale supérieure ou égale à 20°C.
columns:
- name: annee
tests:
- not_null
- name: z_geo
tests:
- not_null
- name: nb_stations
tests:
- not_null
- name: moy_nuits_ge_20
tests:
- not_null

Copilot uses AI. Check for mistakes.
- name: mart_mensq_pluviometrie_sup_100mm
description: >
Table métier utilisée par le dashboard Streamlit.
Contient les mois avec pluviométrie supérieure à 100mm.

columns:
- name: annee
tests:
- not_null

- name: mois
tests:
- not_null
4 changes: 4 additions & 0 deletions models/marts/mart_mensq_pluviometrie_sup_100mm.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--

select *
from {{ ref('int_mensq_pluviometrie_sup_100mm') }}
4 changes: 4 additions & 0 deletions models/marts/mart_mensq_temperatures_sup_20deg.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--

select *
from {{ ref('int_mensq_temperatures_sup_20deg') }}
117 changes: 51 additions & 66 deletions src/data_layer/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,70 +20,45 @@ def get_bq_client():
def run_query(sql: str):
client = get_bq_client()
return client.query(sql).to_dataframe()

# Exemple de fonction qui fait un truc
def get_todo1():
return run_query(f"""
WITH CTE AS (
SELECT
ANNEE AS annee,
MOIS AS mois,
-- On garde AAAAMM pour le tri ou l'affichage chronologique
AAAAMM AS date_key,

-- Somme des précipitations pour la période donnée
AVG(RR) AS Cumul_Mensuel_Pluie_Total,

-- 'NBRR', c'est le nombre de jours de pluie

-- RRAB précipitation maximale tombée en 24 heures au cours du mois (Average)
AVG(RRAB) AS Cumul_MAxi_par_mois,

-- Nombre de jours > 100mm
AVG(NBJRR100) AS Nb_Jours_Sup_100mm

FROM `cc-reunion.data_meteofrance.stg_mensq_pluviometrie`
-- Indispensable pour fusionner les données de toutes les stations par mois
GROUP BY
ANNEE,
MOIS,
AAAAMM

-- Tri par ordre chronologique (ce qui réglera aussi ton problème de tri dans le graph)
ORDER BY
AAAAMM ASC
)

SELECT *
FROM CTE
WHERE Nb_Jours_Sup_100mm > 1
""")

def get_data():
return run_query("""
SELECT ANNEE, moy_nuits_ge_20
FROM `cc-reunion.data_meteofrance.int_mensq_temperatures_sup_20deg`
ORDER BY ANNEE ASC
""")
# Cette fonction est un mapping pour accéder à la table définie dans le dictionnaire TABLES.
TABLES = {
"histo_simu_ann": "cc-reunion.data_meteofrance.histo_simu_ann",
"histo_simu_geo": "cc-reunion.data_meteofrance.histo_simu_geo",
"mensq_pluviometrie": "cc-reunion.data_meteofrance.stg_mensq_pluviometrie",
"mensq_temperatures": "cc-reunion.data_meteofrance.stg_mensq_temperatures",
"mensq_temperatures_sup_20deg": "cc-reunion.data_meteofrance.mart_mensq_temperatures_sup_20deg",
"stations": "cc-reunion.MENS_meteofrance.stations",
"stations_zones": "cc-reunion.MENS_meteofrance.stations_zones",
"Table_NBJTXS32_ANNEE": "cc-reunion.MENS_meteofrance.Table_NBJTXS32_ANNEE",
"Table_sim_2100": "cc-reunion.MENS_meteofrance.Table_sim_2100"
}

# Cette fonction est un raccourci pour accéder aux tables définies dans le dictionnaire TABLES.
def t(table_name: str):
return TABLES[table_name]

def get_nb_moy_nuits_sup_20deg():
return run_query("""
table_name = t("mensq_temperatures_sup_20deg")
return run_query(f"""
SELECT ANNEE, AVG(moy_nuits_ge_20) as nb_moy_nuits_sup_20deg
FROM `cc-reunion.data_meteofrance.int_mensq_temperatures_sup_20deg`
FROM `{table_name}`
GROUP BY ANNEE
ORDER BY ANNEE ASC
""")

def get_nb_moy_nuits_sup_20deg_par_zone_par_annee():
return run_query("""
table_name_temp = t("mensq_temperatures")
table_name_stations_zones = t("stations_zones")
return run_query(f"""
WITH nuit_par_station AS (
SELECT
t.NUM_POSTE,
sz.Z_GEO,
t.ANNEE,
SUM(t.NBJTNS20) AS nuits_ge_20_par_station
FROM `cc-reunion.data_meteofrance.stg_mensq_temperatures` t
JOIN `cc-reunion.MENS_meteofrance.stations_zones` sz
FROM `{table_name_temp}` t
JOIN `{table_name_stations_zones}` sz
ON t.NUM_POSTE = sz.NUM_POSTE
GROUP BY t.NUM_POSTE, sz.Z_GEO, t.ANNEE
),
Expand All @@ -106,23 +81,27 @@ def get_nb_moy_nuits_sup_20deg_par_zone_par_annee():
FROM par_zone
ORDER BY zone_geographique, ANNEE
""")

def get_table_histo_simu():
table_name = t("histo_simu_ann")
return run_query(f"""
SELECT *
FROM `cc-reunion.data_meteofrance.histo_simu_ann`
FROM `{table_name}`
""")

def get_table(tab_name):
def get_table(table_name):
return run_query(f"""
SELECT *
FROM `{tab_name}`
FROM `{table_name}`
""")

def get_full_table_for_cyclone():
return run_query("SELECT * FROM `cc-reunion.data_meteofrance.histo_simu_geo`")
table_name = t("histo_simu_geo")
return run_query(f"SELECT * FROM `{table_name}`")

def get_table_pluie_extreme():
return run_query("""
table_name = t("histo_simu_geo")
return run_query(f"""
WITH CTE AS (
SELECT
NBJFXI3S16X,
Expand All @@ -141,7 +120,7 @@ def get_table_pluie_extreme():
ELSE 'Normal'
END AS Forte_pluviometrie
FROM
`cc-reunion.data_meteofrance.histo_simu_geo` AS t1
`{table_name}` AS t1
)

SELECT
Expand All @@ -158,7 +137,7 @@ def get_table_pluie_extreme():
FROM CTE
""")

#histo_ann
#histo_ann
# CREATE OR REPLACE TABLE `data_meteofrance.histo_simu_geo` AS (
# SELECT
# NUM_POSTE,
Expand All @@ -179,7 +158,8 @@ def get_table_pluie_extreme():


def get_detection_precip_superieure100mm():
return run_query("""
table_name = t("mensq_pluviometrie")
return run_query(f"""
WITH CTE AS (
SELECT
ANNEE AS annee,
Expand All @@ -198,7 +178,7 @@ def get_detection_precip_superieure100mm():
-- Nombre de jours > 100mm
AVG(NBJRR100) AS Nb_Jours_Sup_100mm

FROM `cc-reunion.data_meteofrance.stg_mensq_pluviometrie`
FROM `{table_name}`
GROUP BY
ANNEE,
MOIS,
Expand All @@ -216,7 +196,9 @@ def get_detection_precip_superieure100mm():
# --- Requête SQL ---
# La requête SQL reste inchangée, elle récupère toutes les données annuelles agrégées par zone.
def get_annuelles_par_zone():
return run_query("""
table_name_annee = t("Table_NBJTXS32_ANNEE")
stations = t("stations")
return run_query(f"""
WITH CTE AS (
SELECT
t1.ANNEE,
Expand All @@ -225,9 +207,9 @@ def get_annuelles_par_zone():
AVG(t1.total_jours_sup_32c_annuel) AS moyenne_jours_chauds_zone,
COUNT(DISTINCT t1.NUM_POSTE) AS nombre_stations_incluses
FROM
`cc-reunion.MENS_meteofrance.Table_NBJTXS32_ANNEE` AS t1
`{table_name_annee}` AS t1
INNER JOIN
`cc-reunion.MENS_meteofrance.stations` AS t2
`{stations}` AS t2
ON t1.NUM_POSTE = t2.NUM_POSTE
GROUP BY
t1.ANNEE,
Expand All @@ -250,7 +232,10 @@ def get_annuelles_par_zone():
# --- Requête SQL (Version Statique 2100) ---
# La requête a été simplifiée et corrigée pour ne calculer que la projection en 2100.
def get_projection_2100():
return run_query("""
table_name_annee = t("Table_NBJTXS32_ANNEE")
stations = t("stations")
table_sim_2100 = t("Table_sim_2100")
return run_query(f"""
WITH T_OBS_REF AS (
-- 1. CALCUL DE LA BASELINE OBSERVÉE PAR STATION (Moyenne 1991-2020)
SELECT
Expand All @@ -259,9 +244,9 @@ def get_projection_2100():
t2.Z_GEO,
AVG(t1.total_jours_sup_32c_annuel) AS baseline_jours_chauds_ref
FROM
`cc-reunion.MENS_meteofrance.Table_NBJTXS32_ANNEE` AS t1
`{table_name_annee}` AS t1
INNER JOIN
`cc-reunion.MENS_meteofrance.stations` AS t2
`{stations}` AS t2
ON t1.NUM_POSTE = t2.NUM_POSTE
WHERE
t1.ANNEE BETWEEN '1991' AND '2020'
Expand All @@ -276,7 +261,7 @@ def get_projection_2100():
t2.Z_GEO,
AVG(t2.NBJTXS32) AS delta_jours_chauds_moyen_2100
FROM
`cc-reunion.MENS_meteofrance.Table_sim_2100` AS t2
`{table_sim_2100}` AS t2
WHERE
EXTRACT(YEAR FROM t2.date_2100) = 2100
GROUP BY
Expand All @@ -302,7 +287,7 @@ def get_projection_2100():
FROM
T_PROJ_AGR AS T_PROJ
INNER JOIN
`cc-reunion.MENS_meteofrance.stations` AS T_ST
`{stations}` AS T_ST
ON T_PROJ.Z_GEO = T_ST.Z_GEO
INNER JOIN
T_OBS_REF
Expand Down
17 changes: 17 additions & 0 deletions src/data_layer/diag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is meant to be temporary. Once the changes described below are implemented, this file should be deleted.
# List of tables to be used in the project, sorted by dataset.
# The goal is to have a clear overview of the tables we are using that aren't using dbt processes,
# so that we can easily identify which tables we need to update.
# For example, stg_ -> int_ - > mart_ (or similar) for tables that are currently in stg_
# but should be in int_ or mart_.
"""
data_meteofrance.stg_mensq_pluviometrie
data_meteofrance.stg_mensq_temperatures
data_meteofrance.histo_simu_ann
data_meteofrance.histo_simu_geo

MENS_meteofrance.stations
MENS_meteofrance.stations_zones
MENS_meteofrance.Table_NBJTXS32_ANNEE
MENS_meteofrance.Table_sim_2100
"""