Skip to content

Commit

Permalink
Merge 7122669 into e4c77cc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad-Wahid committed Jun 5, 2023
2 parents e4c77cc + 7122669 commit cf77f07
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ New features
* Introduction of the classes `Reporter` and `PandasReporter` [see `PR #641 <https://www.github.com/FlexMeasures/flexmeasures/pull/641>`_]
* Add CLI command ``flexmeasures add report`` [see `PR #659 <https://www.github.com/FlexMeasures/flexmeasures/pull/659>`_]
* Add CLI command ``flexmeasures show reporters`` [see `PR #686 <https://www.github.com/FlexMeasures/flexmeasures/pull/686>`_]
* Add CLI command ``flexmeasures show schedulers`` [see `PR #708 <https://github.com/FlexMeasures/flexmeasures/pull/708>`_]

Bugfixes
-----------
Expand Down
1 change: 1 addition & 0 deletions documentation/cli/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ of which some are referred to in this documentation.
``flexmeasures show data-sources`` List available data sources.
``flexmeasures show beliefs`` Plot time series data.
``flexmeasures show reporters`` List available reporters.
``flexmeasures show schedulers`` List available schedulers.
================================================= =======================================


Expand Down
7 changes: 4 additions & 3 deletions flexmeasures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ def create( # noqa C901

register_db_at(app)

# Register Reporters
# Register Reporters and Schedulers
from flexmeasures.utils.coding_utils import get_classes_module
from flexmeasures.data.models.reporting import Reporter
from flexmeasures.data.models import reporting, planning

app.reporters = get_classes_module("flexmeasures.data.models.reporting", Reporter)
app.reporters = get_classes_module("flexmeasures.data.models", reporting.Reporter)
app.schedulers = get_classes_module("flexmeasures.data.models", planning.Scheduler)

# add auth policy

Expand Down
40 changes: 30 additions & 10 deletions flexmeasures/cli/data_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,28 +376,48 @@ def plot_beliefs(
click.secho("Data saved to file.", **MsgStyle.SUCCESS)


@fm_show_data.command("reporters")
@with_appcontext
def list_reporters():
def list_items(item_type):
"""
Show available reporters.
Show available items of a specific type.
"""

click.echo("Reporters:\n")
click.echo(f"{item_type.capitalize()}:\n")
click.echo(
tabulate(
[
(
reporter_name,
reporter_class.__version__,
reporter_class.__author__,
reporter_class.__module__,
item_name,
item_class.__version__,
item_class.__author__,
item_class.__module__,
)
for reporter_name, reporter_class in app.reporters.items()
for item_name, item_class in getattr(app, item_type).items()
],
headers=["name", "version", "author", "module"],
)
)


@fm_show_data.command("reporters")
@with_appcontext
def list_reporters():
"""
Show available reporters.
"""

with app.app_context():
list_items("reporters")


@fm_show_data.command("schedulers")
@with_appcontext
def list_schedulers():
"""
Show available schedulers.
"""

with app.app_context():
list_items("schedulers")


app.cli.add_command(fm_show_data)

0 comments on commit cf77f07

Please sign in to comment.