Skip to content

Commit 6f2b52a

Browse files
authored
Merge pull request #57 from dsgrid/eh/view-bugfixes
View Bugfixes
2 parents aeb0bfd + 5e8db80 commit 6f2b52a

44 files changed

Lines changed: 3679 additions & 3033 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ repos:
88
args: [ --fix ]
99
# Run the formatter.
1010
- id: ruff-format
11+
- repo: local
12+
hooks:
13+
- id: mypy
14+
name: mypy
15+
entry: mypy
16+
language: system
17+
pass_filenames: false
18+
stages: [pre-push]

docs/how_tos/compare_scenarios.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ client = APIClient(project)
1616
## Query Multiple Scenarios
1717

1818
```python
19-
baseline = client.get_total_consumption(scenario="baseline")
20-
high_growth = client.get_total_consumption(scenario="high_growth")
19+
baseline = client.get_annual_electricity_consumption(scenarios=["baseline"])
20+
high_growth = client.get_annual_electricity_consumption(scenarios=["high_growth"])
2121
```
2222

2323
## Calculate Differences
@@ -27,7 +27,7 @@ import pandas as pd
2727

2828
comparison = pd.merge(
2929
baseline, high_growth,
30-
on=["geography", "model_year"],
30+
on=["year"],
3131
suffixes=("_baseline", "_high_growth")
3232
)
3333
comparison["difference"] = (
@@ -45,9 +45,8 @@ import plotly.express as px
4545

4646
fig = px.scatter(
4747
comparison,
48-
x="model_year",
49-
y="pct_change",
50-
color="geography",
48+
x="year",
49+
y="pct_difference",
5150
title="Consumption Change: High Growth vs Baseline"
5251
)
5352
fig.show()

docs/how_tos/customize_palette.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ Create consistent colors for visualizations.
1414

1515
## Preview a Palette
1616

17+
Launch the dashboard and open the Settings panel to preview and edit palette
18+
colors:
19+
1720
```{eval-rst}
1821
1922
.. code-block:: console
2023
21-
$ stride palette view my_project
24+
$ stride view my_project
2225
```
2326

2427
## Create a Custom Palette

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ classifiers = [
2525
]
2626
dependencies = [
2727
"click",
28-
"dash>=3.2.0",
28+
"dash>=4.0.0, <5",
2929
"dash-bootstrap-components>=2.0.3",
3030
"dbt-core >= 1.10.5, < 2",
3131
"dbt-duckdb",

src/stride/api/__init__.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def get_annual_peak_demand(
566566
t.scenario,
567567
t.model_year as year,
568568
t.{group_col},
569-
t.value
569+
SUM(t.value) as value
570570
FROM energy_projection t
571571
INNER JOIN peak_hours p ON
572572
t.scenario = p.scenario
@@ -576,6 +576,7 @@ def get_annual_peak_demand(
576576
WHERE t.geography = ?
577577
AND t.scenario = ANY(?)
578578
AND t.model_year = ANY(?)
579+
GROUP BY t.scenario, t.model_year, t.{group_col}
579580
ORDER BY {scenario_order}, t.model_year, t.{group_col}
580581
"""
581582
params = [
@@ -1177,17 +1178,28 @@ def get_time_series_comparison(
11771178
group_col = "metric"
11781179
else: # group_by == "Sector"
11791180
group_col = "sector"
1181+
group_time_period_calc = f"ROW_NUMBER() OVER (PARTITION BY scenario, model_year, {group_col} ORDER BY timestamp)"
11801182
sql = f"""
1183+
WITH hourly_totals AS (
1184+
SELECT
1185+
scenario,
1186+
model_year,
1187+
timestamp,
1188+
{group_col},
1189+
SUM(value) as value
1190+
FROM energy_projection
1191+
WHERE geography = ?
1192+
AND scenario = ?
1193+
AND model_year = ANY(?)
1194+
GROUP BY scenario, model_year, timestamp, {group_col}
1195+
)
11811196
SELECT
11821197
scenario,
11831198
model_year as year,
1184-
{time_period_calc} as time_period,
1199+
{group_time_period_calc} as time_period,
11851200
{group_col},
11861201
value
1187-
FROM energy_projection
1188-
WHERE geography = ?
1189-
AND scenario = ?
1190-
AND model_year = ANY(?)
1202+
FROM hourly_totals
11911203
ORDER BY scenario, model_year, timestamp, {group_col}
11921204
"""
11931205
params: list[Any] = [self.project_country, scenario, years]
@@ -1238,31 +1250,50 @@ def get_time_series_comparison(
12381250
else: # group_by == "Sector"
12391251
group_col = "sector"
12401252
sql = f"""
1253+
WITH hourly_totals AS (
1254+
SELECT
1255+
scenario,
1256+
model_year,
1257+
timestamp,
1258+
{group_col},
1259+
SUM(value) as value
1260+
FROM energy_projection
1261+
WHERE geography = ?
1262+
AND scenario = ?
1263+
AND model_year = ANY(?)
1264+
GROUP BY scenario, model_year, timestamp, {group_col}
1265+
)
12411266
SELECT
12421267
scenario,
12431268
model_year as year,
12441269
{time_period_calc} as time_period,
12451270
{group_col},
12461271
AVG(value) as value
1247-
FROM energy_projection
1248-
WHERE geography = ?
1249-
AND scenario = ?
1250-
AND model_year = ANY(?)
1272+
FROM hourly_totals
12511273
GROUP BY scenario, model_year, {time_period_calc}, {group_col}
12521274
ORDER BY scenario, model_year, time_period, {group_col}
12531275
"""
12541276
params = [self.project_country, scenario, years]
12551277
else:
12561278
sql = f"""
1279+
WITH hourly_totals AS (
1280+
SELECT
1281+
scenario,
1282+
model_year,
1283+
timestamp,
1284+
SUM(value) as value
1285+
FROM energy_projection
1286+
WHERE geography = ?
1287+
AND scenario = ?
1288+
AND model_year = ANY(?)
1289+
GROUP BY scenario, model_year, timestamp
1290+
)
12571291
SELECT
12581292
scenario,
12591293
model_year as year,
12601294
{time_period_calc} as time_period,
12611295
AVG(value) as value
1262-
FROM energy_projection
1263-
WHERE geography = ?
1264-
AND scenario = ?
1265-
AND model_year = ANY(?)
1296+
FROM hourly_totals
12661297
GROUP BY scenario, model_year, {time_period_calc}
12671298
ORDER BY scenario, model_year, time_period
12681299
"""

0 commit comments

Comments
 (0)