-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[POWEROPS-2219] Shop model to nodes (#321)
* refactor Setup shell for asset converter * tests: added failing tests * refactor; Generator conversion * refactor: Wrote plant transformation * refactor: Added price area, watercourse and reservoir * refactor; added missing connections * refactor: setup CLI * refactor; review feedback * refactor: review feedback * refactor: avoid breaking unreleated code * refactor: fix line endings * refactor: renaming * refactor: review feedback * refactor: review feedback * refactor; typo * refactor: moved apply2
- Loading branch information
Showing
8 changed files
with
455 additions
and
3 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .core import DATAMODEL_ID_TO_RESYNC_NAME, MODELS_BY_NAME, apply, destroy, init, plan, validate | ||
from .core.echo import Echo | ||
from .v2.main import apply2 | ||
|
||
__all__ = ["apply", "plan", "init", "destroy", "validate", "MODELS_BY_NAME", "Echo", "DATAMODEL_ID_TO_RESYNC_NAME"] |
Empty file.
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 __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from rich import print | ||
|
||
from cognite.powerops import PowerOpsClient | ||
from cognite.powerops.resync.v2.shop_to_assets import PowerAssetImporter | ||
|
||
|
||
def apply2(config_dir: Path, client: PowerOpsClient | None = None) -> None: | ||
client = client or PowerOpsClient.from_settings() | ||
|
||
importer = PowerAssetImporter.from_directory(config_dir / "production") | ||
|
||
assets = importer.to_power_assets() | ||
|
||
client.v1.upsert(assets) | ||
|
||
print(f"Upserted {len(assets)} assets") |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Empty file.
19 changes: 19 additions & 0 deletions
19
tests/test_unit/test_resync/test_v2/test_shop_to_assets.py
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,19 @@ | ||
from collections import Counter | ||
|
||
from cognite.powerops.resync.v2.shop_to_assets import PowerAssetImporter | ||
from tests.constants import ReSync | ||
|
||
|
||
class TestShopToAssets: | ||
def test_demo_data_to_assets(self) -> None: | ||
importer = PowerAssetImporter.from_directory(ReSync.production) | ||
|
||
assets = importer.to_power_assets() | ||
|
||
counts = Counter([type(asset).__name__ for asset in assets]) | ||
|
||
assert counts["GeneratorWrite"] == 12 | ||
assert counts["PlantWrite"] == 9 | ||
assert counts["ReservoirWrite"] == 16 | ||
assert counts["WatercourseWrite"] == 1 | ||
assert counts["PriceAreaWrite"] == 1 |