Skip to content

Mw/demoday - #10

Merged
45 commits merged into
mainfrom
mw/demoday
Aug 19, 2025
Merged

45 commits merged into
mainfrom
mw/demoday

Conversation

@ghost

@ghost ghost commented Aug 14, 2025

Copy link
Copy Markdown

No description provided.

Daniel Thom and others added 29 commits August 5, 2025 15:02
…ab layouts into modules. Simplified functions. Ruff fixes.
@ghost ghost added the Draft label Aug 14, 2025
@ghost ghost linked an issue Aug 14, 2025 that may be closed by this pull request
9 tasks

@daniel-thom daniel-thom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I made a very quick pass of the core files. I have not attempted to check the SQL yet.

Did we discuss using mypy? I'm guessing that there are a lot of complaints. Maybe we should discuss it.

Comment thread src/stride/api/__init__.py Resolved
Comment thread src/stride/api/__init__.py Outdated
project_config: "ProjectConfig | None" = None,
):
logger.debug(
f"APIClient.__init__ called with project_config: {project_config is not None}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The convention for loguru is logger.debug("my test {}", my_var). Unlike the stdlib logger, it doesn't skip interpolation if debug isn't enabled. There is a separate call for lazy behavior. Still, we should follow their convention in case they optimize something.

Secondly, I'm using a convention where info goes to console, debug goes to files, and trace is for truly debug information. Sound good to you?

Comment thread src/stride/api/__init__.py Resolved
Comment thread src/stride/api/__init__.py Outdated
def _connect_from_path(self, db_path: Path):
# Create DuckDB connection
try:
import duckdb

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not import at the top?

Comment thread src/stride/api/__init__.py Resolved
Comment thread src/stride/api/__init__.py Resolved
Comment thread src/stride/api/__init__.py Resolved
go.Figure or dict
Plotly figure object or error dictionary
"""
print(f"Callback triggered with scenarios: {selected_scenarios}, breakdown: {breakdown}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming that print to stdout is intentional for Dash errors. Is that right? I'm wondering if we need to log any of these.

@ghost

ghost commented Aug 14, 2025

Copy link
Copy Markdown
Author

@daniel-thom I haven't gotten to fixing the mypy problems I've just finished the tests for the UI, but am having trouble using your "default_project" fixture, which is causing most of the tests to fail, so I think I'm missing a step around setting up dsgrid. Below is an example error output.

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x73eb298cddc0>, _basetemp=PosixPath('/tmp/pytest-of-mwebb-wsl/pytest-48'), _retention_count=3, _retention_policy='all'), project_config_file = PosixPath('tests/data/project_input.json5')

@pytest.fixture(scope="module")
def default_project(tmp_path_factory: TempPathFactory, project_config_file: Path) -> Project:
    """Create the default test project.
    Callers must not mutate any data because this is a shared fixture.
    """
    tmp_path = tmp_path_factory.mktemp("tmpdir")
    project_dir = tmp_path / "test_project"
    assert not project_dir.exists()
    cmd = ["projects", "create", str(project_config_file), "--directory", str(tmp_path)]
    runner = CliRunner()
    result = runner.invoke(cli, cmd)
  assert result.exit_code == 0

E AssertionError: assert 1 == 0
E + where 1 = <Result 1 validation error for DatasetRegistrationModel\nmissing_dimension_associations_file\n Extra inputs are not per...ions.csv'), input_type=PosixPath]\n For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden>.exit_code

@daniel-thom daniel-thom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've gone through everything now. This is all really great. I have a few questions and comments, some of which could be deferred.

Comment thread src/stride/api/__init__.py Resolved
Comment thread src/stride/api/__init__.py Resolved
Comment thread src/stride/api/__init__.py Outdated
Comment on lines +26 to +32
import threading
from pathlib import Path
import pandas as pd
from stride.project import Project
from loguru import logger
import duckdb
from typing import Any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: let the LSP fix the import order


if invalid_scenarios:
err = f"Invalid scenarios: {invalid_scenarios}. Valid scenarios are: {list(valid_scenarios)}"
raise ValueError(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We haven't discussed error handling. For errors like this that get raised back to the user, I like to suppress the backtrace and only show the error plus corrective action. This is what I am doing in the CLI handler with handle_stride_exception. Should we follow the convention in this API module? If so, let's open an issue and implement it later.

Comment on lines +575 to +576
- {scenario_name} or {year}: float, demand values sorted from highest to lowest
for each scenario (if multiple scenarios) or year (if multiple years)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this should be split two different functions. More simplistically, would it make sense to have a rule that says a function must always return the same basic schema?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm inclined to agree that we should return the same schema. I would need to change/add many of the functions in the API to do this and handle the routing logic in the UI callback functions which I think makes sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine merging without this. Is it tracked in an issue?

Comment thread src/stride/api/utils.py Resolved
Comment thread src/stride/api/utils.py Resolved
Comment thread src/stride/api/utils.py Resolved
Comment thread src/stride/api/utils.py Resolved
Comment thread tests/test_api.py Resolved
@ghost ghost removed the Draft label Aug 18, 2025
@ghost
ghost requested a review from daniel-thom August 18, 2025 22:29

@daniel-thom daniel-thom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome work!

@ghost
ghost merged commit 108ae05 into main Aug 19, 2025
github-actions Bot pushed a commit that referenced this pull request Aug 19, 2025
* Add UI code from Zack Jensen

* rough api spec

* some polishing to api docstrings.

* conversion to singleton class, improved docstrings with examples.

* changed hour col to 0-23

* moved api into module outside of ui. Added pytest for test driven dev.

* conversion to tall tables.

* Mostly complete implementation of the wireframe design.

* saving settings

* ui migration to new db schema.

* better state management.

* Some polishing for the demo.

* hard-coded to run dash in single thread. Changed default color palette.

* Add UI code from Zack Jensen

* rough api spec

* some polishing to api docstrings.

* conversion to singleton class, improved docstrings with examples.

* changed hour col to 0-23

* moved api into module outside of ui. Added pytest for test driven dev.

* conversion to tall tables.

* Mostly complete implementation of the wireframe design.

* saving settings

* ui migration to new db schema.

* better state management.

* Some polishing for the demo.

* hard-coded to run dash in single thread. Changed default color palette.

* added plotting dependencies to pyproject.toml. Refactored plot page/tab layouts into modules. Simplified functions. Ruff fixes.

* ui tests, debugging default_project fixture

* Support pushing Pages to github

* mypy fixes

* saving progress

* api query fixes

* improve test speed

* Add read-only option for the Project database

* more test fixes

* ruff formatting

* Add context manager

* Fixed Seasonal SQL, migrated TODOs to github issue, converted tests to functional instead of classes.

* Changed PEAK_DMD to PEAK_DEMAND and PERC_GROWTH to PERCENT_GROWTH

* fixed scenario stat keys in test

---------

Co-authored-by: Daniel Thom <daniel.thom@nrel.gov>
@elainethale
elainethale deleted the mw/demoday branch February 2, 2026 15:30
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI - Remaining Items

2 participants