Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Dashboard using GenericAssets (#251)
* Create draft PR for #249 * working state of new dashboard; created new file asset_grouping with class AssetGroup, which is aimed to replace resources.Resource; created new view /sensor/<id>/state * smaller items from review and add a default ACL for generic assets * move querying assets by type to a data.queries module * make asset type grouping configurable & simplify initialising an AssetGroup * query asset for its state (via one of its power sensors) and also identify power sensors by unit * Dashboard only shows asset groups where at least one asset has a location and power sensors * add missing module * restore grouping by location behaviour for later * move intro text to modal dialogue * make is_power_unit only care about power * include energy assets on dashboard * fix docstring Co-authored-by: nhoening <nhoening@users.noreply.github.com> Co-authored-by: Nicolas Höning <nicolas@seita.nl>
- Loading branch information
1 parent
0d26f7c
commit 754b46b
Showing
19 changed files
with
967 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from flask import abort | ||
from marshmallow import fields | ||
|
||
from flexmeasures.data.models.generic_assets import GenericAsset | ||
|
||
|
||
class AssetIdField(fields.Integer): | ||
""" | ||
Field that represents a generic asset ID. It de-serializes from the asset id to an asset instance. | ||
""" | ||
|
||
def _deserialize(self, asset_id: int, attr, obj, **kwargs) -> GenericAsset: | ||
asset: GenericAsset = GenericAsset.query.filter_by( | ||
id=int(asset_id) | ||
).one_or_none() | ||
if asset is None: | ||
raise abort(404, f"GenericAsset {asset_id} not found") | ||
return asset | ||
|
||
def _serialize(self, asset: GenericAsset, attr, data, **kwargs) -> int: | ||
return asset.id |
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,20 @@ | ||
from typing import List, Union | ||
|
||
from sqlalchemy.orm import Query | ||
|
||
from flexmeasures.data.models.generic_assets import GenericAsset, GenericAssetType | ||
|
||
|
||
def query_assets_by_type(type_names: Union[List[str], str]) -> Query: | ||
""" | ||
Return a query which looks for GenericAssets by their type. | ||
Pass in a list of type names or only one type name. | ||
""" | ||
query = GenericAsset.query.join(GenericAssetType).filter( | ||
GenericAsset.generic_asset_type_id == GenericAssetType.id | ||
) | ||
if isinstance(type_names, str): | ||
query = query.filter(GenericAssetType.name == type_names) | ||
else: | ||
query = query.filter(GenericAssetType.name.in_(type_names)) | ||
return query |
Oops, something went wrong.