Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: flexmeasures show beliefs (#379)
* first version of flexmeasures show beliefs Signed-off-by: Nicolas Höning <nicolas@seita.nl> * add types lib for mypy Signed-off-by: Nicolas Höning <nicolas@seita.nl> * construct title at the end when we have all info updated Signed-off-by: Nicolas Höning <nicolas@seita.nl> * update changelogs Signed-off-by: Nicolas Höning <nicolas@seita.nl> * add -belief-time-before option Signed-off-by: Nicolas Höning <nicolas@seita.nl> * add simple tests for all show data commands Signed-off-by: Nicolas Höning <nicolas@seita.nl> * flexmeasures/conftest.py fix typo in ficture name Signed-off-by: Nicolas Höning <nicolas@seita.nl> * verifying that CLI tests do not run on GithubActions Signed-off-by: Nicolas Höning <nicolas@seita.nl> * move back to ignoring CLI commands on Github Actions Signed-off-by: Nicolas Höning <nicolas@seita.nl> * small doc improvement Signed-off-by: Nicolas Höning <nicolas@seita.nl> * better handling of DEBUG var Signed-off-by: Nicolas Höning <nicolas@seita.nl> * improve docstring of two fixtures Signed-off-by: Nicolas Höning <nicolas@seita.nl> * if sensor share the same unit, still show it on the y-axis ; Also introduce Schema for DataSourceIdField Signed-off-by: Nicolas Höning <nicolas@seita.nl> * Use AwareDateTimeField for --start Signed-off-by: Nicolas Höning <nicolas@seita.nl> * also use schemas for --duration and --belief-time Signed-off-by: Nicolas Höning <nicolas@seita.nl> * use SensorIdField schema for --sensor-id Signed-off-by: Nicolas Höning <nicolas@seita.nl> * use schemas in show commands for account and asset Signed-off-by: Nicolas Höning <nicolas@seita.nl> * simplify possible traces we need to show with one_deterministic_belief_per_event=True Signed-off-by: Nicolas Höning <nicolas@seita.nl> * use source.description in title Signed-off-by: Nicolas Höning <nicolas@seita.nl> * improve in-code documentation Signed-off-by: Nicolas Höning <nicolas@seita.nl> * resample data from different sensors to minimal resolution if possible; be more informative if no data found for a sensor Signed-off-by: Nicolas Höning <nicolas@seita.nl> * simpler way of making sure data is resample to minimal resolution Signed-off-by: Nicolas Höning <nicolas@seita.nl>
- Loading branch information
Showing
13 changed files
with
323 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import pytest | ||
|
||
from flexmeasures.data.models.time_series import Sensor | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_list_accounts(app, fresh_db, setup_accounts_fresh_db): | ||
from flexmeasures.cli.data_show import list_accounts | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke(list_accounts) | ||
|
||
assert "All accounts on this" in result.output | ||
for account in setup_accounts_fresh_db.values(): | ||
assert account.name in result.output | ||
assert result.exit_code == 0 | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_list_roles(app, fresh_db, setup_roles_users_fresh_db): | ||
from flexmeasures.cli.data_show import list_roles | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke(list_roles) | ||
|
||
assert "Account roles" in result.output | ||
assert "User roles" in result.output | ||
for role in ("account-admin", "Supplier", "Dummy"): | ||
assert role in result.output | ||
assert result.exit_code == 0 | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_list_asset_types(app, fresh_db, setup_generic_asset_types_fresh_db): | ||
from flexmeasures.cli.data_show import list_asset_types | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke(list_asset_types) | ||
|
||
for asset_type in setup_generic_asset_types_fresh_db.values(): | ||
assert asset_type.name in result.output | ||
assert result.exit_code == 0 | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_list_sources(app, fresh_db, setup_sources_fresh_db): | ||
from flexmeasures.cli.data_show import list_data_sources | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke(list_data_sources) | ||
|
||
for source in setup_sources_fresh_db.values(): | ||
assert source.name in result.output | ||
assert result.exit_code == 0 | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_show_accounts(app, fresh_db, setup_accounts_fresh_db): | ||
from flexmeasures.cli.data_show import show_account | ||
|
||
fresh_db.session.flush() # get IDs in DB | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke( | ||
show_account, ["--id", setup_accounts_fresh_db["Prosumer"].id] | ||
) | ||
|
||
assert "Account Test Prosumer Account" in result.output | ||
assert "No users in account" in result.output | ||
assert result.exit_code == 0 | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_show_asset(app, fresh_db, setup_generic_assets_fresh_db): | ||
from flexmeasures.cli.data_show import show_generic_asset | ||
|
||
fresh_db.session.flush() # get IDs in DB | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke( | ||
show_generic_asset, | ||
["--id", setup_generic_assets_fresh_db["test_wind_turbine"].id], | ||
) | ||
|
||
assert "Asset Test wind turbine" in result.output | ||
assert "No sensors in asset" in result.output | ||
assert result.exit_code == 0 | ||
|
||
|
||
@pytest.mark.skip_github | ||
def test_plot_beliefs(app, fresh_db, setup_beliefs_fresh_db): | ||
from flexmeasures.cli.data_show import plot_beliefs | ||
|
||
sensor = Sensor.query.filter(Sensor.name == "epex_da").one_or_none() | ||
|
||
runner = app.test_cli_runner() | ||
result = runner.invoke( | ||
plot_beliefs, | ||
[ | ||
"--sensor-id", | ||
sensor.id, | ||
"--from", | ||
"2021-03-28T16:00+01", | ||
"--duration", | ||
"PT1H", | ||
], | ||
) | ||
|
||
assert "Beliefs for Sensor 'epex_da'" in result.output | ||
assert "Data spans an hour" in result.output | ||
|
||
assert result.exit_code == 0 |
Oops, something went wrong.