Commit
·
d0f0456
1
Parent(s):
29cf97a
feat: changed queries for macro countries in talk to ipcc
Browse files
climateqa/engine/talk_to_data/ipcc/queries.py
CHANGED
@@ -44,9 +44,10 @@ def indicator_per_year_at_location_query(
|
|
44 |
if country_code in MACRO_COUNTRIES:
|
45 |
table_path = f"'{IPCC_DATASET_URL}/{table.lower()}/{country_code}_macro.parquet'"
|
46 |
sql_query = f"""
|
47 |
-
SELECT year, scenario, {indicator_column}
|
48 |
FROM {table_path}
|
49 |
-
WHERE
|
|
|
50 |
ORDER BY year, scenario
|
51 |
"""
|
52 |
else:
|
@@ -102,11 +103,10 @@ def indicator_for_given_year_query(
|
|
102 |
if country_code in MACRO_COUNTRIES:
|
103 |
table_path = f"'{IPCC_DATASET_URL}/{table.lower()}/{country_code}_macro.parquet'"
|
104 |
sql_query = f"""
|
105 |
-
SELECT
|
106 |
-
FROM {table_path}
|
107 |
-
RIGHT JOIN '{IPCC_DATASET_URL}/coordinates.parquet' AS c
|
108 |
-
ON c.admin1 = t.admin1 AND c.country_code = t.country_code
|
109 |
WHERE year = {year}
|
|
|
110 |
ORDER BY latitude, longitude, scenario
|
111 |
"""
|
112 |
else:
|
|
|
44 |
if country_code in MACRO_COUNTRIES:
|
45 |
table_path = f"'{IPCC_DATASET_URL}/{table.lower()}/{country_code}_macro.parquet'"
|
46 |
sql_query = f"""
|
47 |
+
SELECT year, scenario, AVG({indicator_column}) as {indicator_column}
|
48 |
FROM {table_path}
|
49 |
+
WHERE latitude = {latitude} AND longitude = {longitude} AND year >= 1950
|
50 |
+
GROUP BY scenario, year
|
51 |
ORDER BY year, scenario
|
52 |
"""
|
53 |
else:
|
|
|
103 |
if country_code in MACRO_COUNTRIES:
|
104 |
table_path = f"'{IPCC_DATASET_URL}/{table.lower()}/{country_code}_macro.parquet'"
|
105 |
sql_query = f"""
|
106 |
+
SELECT latitude, longitude, scenario, AVG({indicator_column}) as {indicator_column}
|
107 |
+
FROM {table_path}
|
|
|
|
|
108 |
WHERE year = {year}
|
109 |
+
GROUP BY latitude, longitude, scenario
|
110 |
ORDER BY latitude, longitude, scenario
|
111 |
"""
|
112 |
else:
|