Skip to content

Commit

Permalink
group data sources by type
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed Aug 21, 2023
1 parent a7be37f commit 4c2f8af
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions flexmeasures/cli/data_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ def list_data_sources(source: DataSource | None = None, show_attributes: bool =
Show available data sources
"""
if source is None:
sources = DataSource.query.order_by(DataSource.name).all()
sources = (
DataSource.query.order_by(DataSource.name)
.order_by(DataSource.model)
.order_by(DataSource.version)
.all()
)
else:
sources = [source]

Expand All @@ -247,7 +252,7 @@ def list_data_sources(source: DataSource | None = None, show_attributes: bool =
if show_attributes:
headers.append("Attributes")

rows = []
rows = dict()

for source in sources:
row = [
Expand All @@ -260,9 +265,17 @@ def list_data_sources(source: DataSource | None = None, show_attributes: bool =
]
if show_attributes:
row.append(json.dumps(source.attributes, indent=4))
rows.append(row)

click.echo(tabulate(rows, headers=headers))
if source.type not in rows:
rows[source.type] = [row]
else:
rows[source.type].append(row)

for ds_type, rows in rows.items():
click.echo(ds_type)
click.echo("=" * len(ds_type))
click.echo(tabulate(rows, headers=headers))
click.echo("\n")


@fm_show_data.command("beliefs")
Expand Down

0 comments on commit 4c2f8af

Please sign in to comment.