Skip to content

Commit

Permalink
Clean up flexmeasures show formatting (#540)
Browse files Browse the repository at this point in the history
Clean up table formatting for `flexmeasures show` CLI commands.


* Clean up table formatting

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Streamline how the term ID is printed out

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Nov 24, 2022
1 parent 3c95759 commit f54cea2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -33,6 +33,7 @@ Infrastructure / Support
* Improve documentation and code w.r.t. storage flexibility modelling ― prepare for handling other schedulers & merge battery and car charging schedulers [see `PR #511 <http://www.github.com/FlexMeasures/flexmeasures/pull/511>`_]
* Revised strategy for removing unchanged beliefs when saving data: retain the oldest measurement (ex-post belief), too [see `PR #518 <http://www.github.com/FlexMeasures/flexmeasures/pull/518>`_]
* Scheduling test for maximizing self-consumption, and improved time series db queries for fixed tariffs (and other long-term constants) [see `PR #532 <http://www.github.com/FlexMeasures/flexmeasures/pull/532>`_]
* Clean up table formatting for ``flexmeasures show`` CLI commands [see `PR #540 <http://www.github.com/FlexMeasures/flexmeasures/pull/540>`_]


v0.11.3 | November 2, 2022
Expand Down
34 changes: 17 additions & 17 deletions flexmeasures/cli/data_show.py
Expand Up @@ -48,7 +48,7 @@ def list_accounts():
)
for account in accounts
]
click.echo(tabulate(account_data, headers=["Id", "Name", "Assets"]))
click.echo(tabulate(account_data, headers=["ID", "Name", "Assets"]))


@fm_show_data.command("roles")
Expand All @@ -65,7 +65,7 @@ def list_roles():
click.echo(
tabulate(
[(r.id, r.name, r.description) for r in account_roles],
headers=["Id", "Name", "Description"],
headers=["ID", "Name", "Description"],
)
)
click.echo()
Expand All @@ -77,7 +77,7 @@ def list_roles():
click.echo(
tabulate(
[(r.id, r.name, r.description) for r in user_roles],
headers=["Id", "Name", "Description"],
headers=["ID", "Name", "Description"],
)
)

Expand All @@ -89,9 +89,9 @@ def show_account(account):
"""
Show information about an account, including users and assets.
"""
click.echo(f"========{len(account.name) * '='}==========")
click.echo(f"Account {account.name} (ID:{account.id}):")
click.echo(f"========{len(account.name) * '='}==========\n")
click.echo(f"========{len(account.name) * '='}========")
click.echo(f"Account {account.name} (ID: {account.id})")
click.echo(f"========{len(account.name) * '='}========\n")

if account.account_roles:
click.echo(
Expand All @@ -117,7 +117,7 @@ def show_account(account):
for user in users
]
click.echo(
tabulate(user_data, headers=["Id", "Name", "Email", "Last Login", "Roles"])
tabulate(user_data, headers=["ID", "Name", "Email", "Last Login", "Roles"])
)

click.echo()
Expand All @@ -134,7 +134,7 @@ def show_account(account):
(asset.id, asset.name, asset.generic_asset_type.name, asset.location)
for asset in assets
]
click.echo(tabulate(asset_data, headers=["Id", "Name", "Type", "Location"]))
click.echo(tabulate(asset_data, headers=["ID", "Name", "Type", "Location"]))


@fm_show_data.command("asset-types")
Expand All @@ -150,7 +150,7 @@ def list_asset_types():
click.echo(
tabulate(
[(t.id, t.name, t.description) for t in asset_types],
headers=["Id", "Name", "Description"],
headers=["ID", "Name", "Description"],
)
)

Expand All @@ -162,15 +162,15 @@ def show_generic_asset(asset):
"""
Show asset info and list sensors
"""
click.echo(f"======{len(asset.name) * '='}==========")
click.echo(f"Asset {asset.name} (ID:{asset.id}):")
click.echo(f"======{len(asset.name) * '='}==========\n")
click.echo(f"======{len(asset.name) * '='}=========")
click.echo(f"Asset {asset.name} (ID: {asset.id})")
click.echo(f"======{len(asset.name) * '='}=========\n")

asset_data = [
(
asset.generic_asset_type.name,
asset.location,
"".join([f"{k}:{v}\n" for k, v in asset.attributes.items()]),
"".join([f"{k}: {v}\n" for k, v in asset.attributes.items()]),
)
]
click.echo(tabulate(asset_data, headers=["Type", "Location", "Attributes"]))
Expand All @@ -190,14 +190,14 @@ def show_generic_asset(asset):
sensor.unit,
naturaldelta(sensor.event_resolution),
sensor.timezone,
",".join([f"{k}:{v}\n" for k, v in sensor.attributes.items()]),
"".join([f"{k}: {v}\n" for k, v in sensor.attributes.items()]),
)
for sensor in sensors
]
click.echo(
tabulate(
sensor_data,
headers=["Id", "Name", "Unit", "Resolution", "Timezone", "Attributes"],
headers=["ID", "Name", "Unit", "Resolution", "Timezone", "Attributes"],
)
)

Expand All @@ -215,7 +215,7 @@ def list_data_sources():
click.echo(
tabulate(
[(s.id, s.name, s.type, s.user_id, s.model, s.version) for s in sources],
headers=["Id", "Name", "Type", "User Id", "Model", "Version"],
headers=["ID", "Name", "Type", "User ID", "Model", "Version"],
)
)

Expand Down Expand Up @@ -312,7 +312,7 @@ def plot_beliefs(
# only keep non-empty
for s in sensors:
if beliefs_by_sensor[s.name].empty:
click.echo(f"No data found for sensor '{s.name}' (Id: {s.id})")
click.echo(f"No data found for sensor '{s.name}' (ID: {s.id})")
beliefs_by_sensor.pop(s.name)
sensors.remove(s)
if len(beliefs_by_sensor.keys()) == 0:
Expand Down

0 comments on commit f54cea2

Please sign in to comment.