Skip to content

Commit

Permalink
feat: model updates and naming standardization (#342)
Browse files Browse the repository at this point in the history
* feat: standardize naming

* feat: renamed Mapping to ShopAttributeMapping

* feat: rename Scenario/SecenarioSet to ShopScenario/ShopScenarioSet

* feat: update shop property names

* feat: rename preprocessor input and space variable

* feat: rename preprocessor input and space variable

* feat: rename preprocessor input and space variable

* feat: rename Asset to PowerAsset

* feat: update frontend model with bid matrix

* fix: revert space names

* feat: rename process id to workflowExecutionId

* feat: remove backend BidMatrix from front end model

* feat: rename process id to workflowExecutionId

* feat: add powerAsset to PartialBidConfig

* feat: use general field on interface

* feat: clean up function input/output views

* feat: add Price area variants

* feat: add Price area variants

* feat: add power assets back

* feat: dm updates

* feat: regenerated SDK
  • Loading branch information
nodegard authored Apr 16, 2024
1 parent 11d62a8 commit d6b56fc
Show file tree
Hide file tree
Showing 506 changed files with 32,799 additions and 48,736 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.94.0] - 2024-04-16
### Changed
* Updated BidDocument to provide needed context to frontend data model
* Standardized naming
* SHOP -> Shop or shop
* Timeseries -> TimeSeries

## [0.93.0] - 2024-04-09
### Changed
* Added ShopFile type as wrapper for shop files to be used in a Case in CogShop. Changes name from property shopScenarios to
Expand Down
2 changes: 1 addition & 1 deletion cognite/powerops/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.93.0"
__version__ = "0.94.0"
22 changes: 16 additions & 6 deletions cognite/powerops/client/_generated/afrr_bid/_api/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DomainModelCore,
DomainModelWrite,
DomainRelationWrite,
PageInfo,
GraphQLList,
ResourcesWriteResult,
T_DomainModel,
Expand Down Expand Up @@ -482,6 +483,7 @@ class QueryStep:
max_retrieve_limit: int
select: dm.query.Select
result_cls: type[DomainModelCore] | None = None
is_single_direct_relation: bool = False

# Query Variables
cursor: str | None = None
Expand All @@ -499,6 +501,17 @@ def update_expression_limit(self) -> None:
def is_unlimited(self) -> bool:
return self.max_retrieve_limit in {None, -1, math.inf}

@property
def is_finished(self) -> bool:
return (
(not self.is_unlimited and self.total_retrieved >= self.max_retrieve_limit)
or self.cursor is None
or self.last_batch_count == 0
# Single direct relations are dependent on the parent node,
# so we assume that the parent node is the limiting factor.
or self.is_single_direct_relation
)


class QueryBuilder(UserList, Generic[T_DomainModelList]):
# The unique string is in case the data model has a field that ends with _\d+. This will make sure we don't
Expand Down Expand Up @@ -569,12 +582,7 @@ def update(self, batch: dm.query.QueryResult):

@property
def is_finished(self):
return all(
(not expression.is_unlimited and expression.total_retrieved >= expression.max_retrieve_limit)
or expression.cursor is None
or expression.last_batch_count == 0
for expression in self
)
return all(expression.is_finished for expression in self)

def unpack(self) -> T_DomainModelList:
nodes_by_type: dict[str | None, dict[tuple[str, str], DomainModel]] = defaultdict(dict)
Expand Down Expand Up @@ -766,6 +774,8 @@ def parse(self, response: dict[str, Any]) -> GraphQLList:
raise RuntimeError(response["errors"])
_, data = list(response.items())[0]
self._parse_item(data)
if "pageInfo" in data:
self._output.page_info = PageInfo.load(data["pageInfo"])
return self._output

def _parse_item(self, data: dict[str, Any]) -> None:
Expand Down
141 changes: 131 additions & 10 deletions cognite/powerops/client/_generated/afrr_bid/_api/bid_document_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
BidDocument,
PriceArea,
)
from cognite.powerops.client._generated.afrr_bid.data_classes._alert import (
Alert,
_create_alert_filter,
)
from cognite.powerops.client._generated.afrr_bid.data_classes._bid_row import (
BidRow,
_create_bid_row_filter,
)
from ._core import DEFAULT_QUERY_LIMIT, QueryBuilder, QueryStep, QueryAPI, T_DomainModelList, _create_edge_filter

if TYPE_CHECKING:
Expand Down Expand Up @@ -43,17 +51,51 @@ def __init__(

def alerts(
self,
min_time: datetime.datetime | None = None,
max_time: datetime.datetime | None = None,
title: str | list[str] | None = None,
title_prefix: str | None = None,
description: str | list[str] | None = None,
description_prefix: str | None = None,
severity: str | list[str] | None = None,
severity_prefix: str | None = None,
alert_type: str | list[str] | None = None,
alert_type_prefix: str | None = None,
min_status_code: int | None = None,
max_status_code: int | None = None,
calculation_run: str | list[str] | None = None,
calculation_run_prefix: str | None = None,
external_id_prefix: str | None = None,
space: str | list[str] | None = None,
external_id_prefix_edge: str | None = None,
space_edge: str | list[str] | None = None,
filter: dm.Filter | None = None,
limit: int | None = DEFAULT_QUERY_LIMIT,
retrieve_price_area: bool = False,
) -> AlertQueryAPI[T_DomainModelList]:
"""Query along the alert edges of the bid document.
Args:
min_time: The minimum value of the time to filter on.
max_time: The maximum value of the time to filter on.
title: The title to filter on.
title_prefix: The prefix of the title to filter on.
description: The description to filter on.
description_prefix: The prefix of the description to filter on.
severity: The severity to filter on.
severity_prefix: The prefix of the severity to filter on.
alert_type: The alert type to filter on.
alert_type_prefix: The prefix of the alert type to filter on.
min_status_code: The minimum value of the status code to filter on.
max_status_code: The maximum value of the status code to filter on.
calculation_run: The calculation run to filter on.
calculation_run_prefix: The prefix of the calculation run to filter on.
external_id_prefix: The prefix of the external ID to filter on.
space: The space to filter on.
limit: Maximum number of alert edges to return. Defaults to 25. Set to -1, float("inf") or None
external_id_prefix_edge: The prefix of the external ID to filter on.
space_edge: The space to filter on.
filter: (Advanced) Filter applied to node. If the filtering available in the above is not sufficient, you can write your own filtering which will be ANDed with the filter above.
limit: Maximum number of alert edges to return. Defaults to 3. Set to -1, float("inf") or None
to return all items.
retrieve_price_area: Whether to retrieve the price area for each bid document or not.
Expand All @@ -63,11 +105,10 @@ def alerts(
from .alert_query import AlertQueryAPI

from_ = self._builder[-1].name

edge_filter = _create_edge_filter(
dm.DirectRelationReference("power-ops-types", "calculationIssue"),
external_id_prefix=external_id_prefix,
space=space,
external_id_prefix=external_id_prefix_edge,
space=space_edge,
)
self._builder.append(
QueryStep(
Expand All @@ -81,23 +122,80 @@ def alerts(
max_retrieve_limit=limit,
)
)

view_id = self._view_by_read_class[Alert]
has_data = dm.filters.HasData(views=[view_id])
node_filer = _create_alert_filter(
view_id,
min_time,
max_time,
title,
title_prefix,
description,
description_prefix,
severity,
severity_prefix,
alert_type,
alert_type_prefix,
min_status_code,
max_status_code,
calculation_run,
calculation_run_prefix,
external_id_prefix,
space,
(filter and dm.filters.And(filter, has_data)) or has_data,
)
if retrieve_price_area:
self._query_append_price_area(from_)
return AlertQueryAPI(self._client, self._builder, self._view_by_read_class, None, limit)
return AlertQueryAPI(self._client, self._builder, self._view_by_read_class, node_filer, limit)

def bids(
self,
min_price: float | None = None,
max_price: float | None = None,
product: str | list[str] | None = None,
product_prefix: str | None = None,
is_divisible: bool | None = None,
is_block: bool | None = None,
exclusive_group_id: str | list[str] | None = None,
exclusive_group_id_prefix: str | None = None,
linked_bid: str | tuple[str, str] | list[str] | list[tuple[str, str]] | None = None,
asset_type: str | list[str] | None = None,
asset_type_prefix: str | None = None,
asset_id: str | list[str] | None = None,
asset_id_prefix: str | None = None,
method: str | tuple[str, str] | list[str] | list[tuple[str, str]] | None = None,
external_id_prefix: str | None = None,
space: str | list[str] | None = None,
external_id_prefix_edge: str | None = None,
space_edge: str | list[str] | None = None,
filter: dm.Filter | None = None,
limit: int | None = DEFAULT_QUERY_LIMIT,
retrieve_price_area: bool = False,
) -> BidRowQueryAPI[T_DomainModelList]:
"""Query along the bid edges of the bid document.
Args:
min_price: The minimum value of the price to filter on.
max_price: The maximum value of the price to filter on.
product: The product to filter on.
product_prefix: The prefix of the product to filter on.
is_divisible: The is divisible to filter on.
is_block: The is block to filter on.
exclusive_group_id: The exclusive group id to filter on.
exclusive_group_id_prefix: The prefix of the exclusive group id to filter on.
linked_bid: The linked bid to filter on.
asset_type: The asset type to filter on.
asset_type_prefix: The prefix of the asset type to filter on.
asset_id: The asset id to filter on.
asset_id_prefix: The prefix of the asset id to filter on.
method: The method to filter on.
external_id_prefix: The prefix of the external ID to filter on.
space: The space to filter on.
limit: Maximum number of bid edges to return. Defaults to 25. Set to -1, float("inf") or None
external_id_prefix_edge: The prefix of the external ID to filter on.
space_edge: The space to filter on.
filter: (Advanced) Filter applied to node. If the filtering available in the above is not sufficient, you can write your own filtering which will be ANDed with the filter above.
limit: Maximum number of bid edges to return. Defaults to 3. Set to -1, float("inf") or None
to return all items.
retrieve_price_area: Whether to retrieve the price area for each bid document or not.
Expand All @@ -107,11 +205,10 @@ def bids(
from .bid_row_query import BidRowQueryAPI

from_ = self._builder[-1].name

edge_filter = _create_edge_filter(
dm.DirectRelationReference("power-ops-types", "partialBid"),
external_id_prefix=external_id_prefix,
space=space,
external_id_prefix=external_id_prefix_edge,
space=space_edge,
)
self._builder.append(
QueryStep(
Expand All @@ -125,9 +222,32 @@ def bids(
max_retrieve_limit=limit,
)
)

view_id = self._view_by_read_class[BidRow]
has_data = dm.filters.HasData(views=[view_id])
node_filer = _create_bid_row_filter(
view_id,
min_price,
max_price,
product,
product_prefix,
is_divisible,
is_block,
exclusive_group_id,
exclusive_group_id_prefix,
linked_bid,
asset_type,
asset_type_prefix,
asset_id,
asset_id_prefix,
method,
external_id_prefix,
space,
(filter and dm.filters.And(filter, has_data)) or has_data,
)
if retrieve_price_area:
self._query_append_price_area(from_)
return BidRowQueryAPI(self._client, self._builder, self._view_by_read_class, None, limit)
return BidRowQueryAPI(self._client, self._builder, self._view_by_read_class, node_filer, limit)

def query(
self,
Expand Down Expand Up @@ -161,5 +281,6 @@ def _query_append_price_area(self, from_: str) -> None:
select=dm.query.Select([dm.query.SourceSelector(view_id, ["*"])]),
max_retrieve_limit=-1,
result_cls=PriceArea,
is_single_direct_relation=True,
),
)
Loading

0 comments on commit d6b56fc

Please sign in to comment.