Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added UI+api support for RulesV2. Read-only in the release , editable in the next release. #409

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: run-explorer run-tests run-linters build-ui build-python build-docker run-docker compose-up

version="0.73.4"
version="0.74.0"
run-explorer:
@echo "Running explorer API server..."
# open "http://localhost:8000/static/index.html" || true
Expand Down
2 changes: 1 addition & 1 deletion cognite/neat/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.73.4"
__version__ = "0.74.0"
94 changes: 61 additions & 33 deletions cognite/neat/app/api/routers/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

from cognite.neat.app.api.configuration import NEAT_APP
from cognite.neat.app.api.data_classes.rest import TransformationRulesUpdateRequest
from cognite.neat.rules import exporter, importer
from cognite.neat.rules import exporter, importer, importers
from cognite.neat.rules.models._base import EntityTypes
from cognite.neat.rules.models._rules.base import RoleTypes
from cognite.neat.rules.models.rules import Class, Classes, Metadata, Properties, Property, Rules
from cognite.neat.workflows.steps.data_contracts import RulesData
from cognite.neat.workflows.steps.lib.rules_exporter import RulesToExcel
from cognite.neat.workflows.steps.lib.rules_importer import ExcelToRules
from cognite.neat.workflows.steps.lib.v1.rules_importer import ImportExcelToRules
from cognite.neat.workflows.utils import get_file_hash

Expand All @@ -32,7 +35,9 @@ def get_rules(
workflow_name: str = "default",
file_name: str | None = None,
version: str | None = None,
as_role: str | None = None,
) -> dict[str, Any]:
rules_schema_version = ""
if NEAT_APP.cdf_store is None or NEAT_APP.workflow_manager is None:
return {"error": "NeatApp is not initialized"}
if workflow_name != "undefined":
Expand All @@ -46,6 +51,15 @@ def get_rules(
file_name = step.configs["file_name"]
version = step.configs["version"]
break
if step.method == RulesToExcel.__name__ or step.method == ExcelToRules.__name__:
rules_schema_version = "v2"
as_role = step.configs.get("as_role", "")
file_name = step.configs.get("File name", "")
if file_name:
break
file_name = step.configs.get("File path", "")
break

if not file_name:
return {"error": "File name is not provided"}
rules_file = Path(file_name)
Expand All @@ -72,47 +86,61 @@ def get_rules(
error_text = ""
properties = []
classes = []
remaped_rules = {}
try:
rules = cast(Rules, importer.ExcelImporter(path).to_rules(return_report=False, skip_validation=False))

properties = [
{
"class": value.class_id,
"property": value.property_id,
"property_description": value.description,
"property_type": (
value.expected_value_type.versioned_id
if value.property_type == EntityTypes.object_property
else value.expected_value_type.suffix
),
"cdf_resource_type": value.cdf_resource_type,
"cdf_metadata_type": value.resource_type_property,
"rule_type": value.rule_type,
"rule": value.rule,
}
for value in rules.properties.values()
]

classes = [
{
"class": value.class_id,
"class_description": value.description,
"cdf_resource_type": value.cdf_resource_type,
}
for value in rules.classes.values()
]

# Trying to load rules V1
if rules_schema_version == "" or rules_schema_version == "v1":
rules = cast(Rules, importer.ExcelImporter(path).to_rules(return_report=False, skip_validation=False))
properties = [
{
"class": value.class_id,
"property": value.property_id,
"property_description": value.description,
"property_type": (
value.expected_value_type.versioned_id
if value.property_type == EntityTypes.object_property
else value.expected_value_type.suffix
),
"cdf_resource_type": value.cdf_resource_type,
"cdf_metadata_type": value.resource_type_property,
"rule_type": value.rule_type,
"rule": value.rule,
}
for value in rules.properties.values()
]

classes = [
{
"class": value.class_id,
"class_description": value.description,
"cdf_resource_type": value.cdf_resource_type,
}
for value in rules.classes.values()
]
rules_schema_version = "v1"
remaped_rules = {"properties": properties, "metadata": rules.metadata.model_dump(), "classes": classes}
except Exception as e:
error_text = str(e)

if rules_schema_version == "" or rules_schema_version == "v2":
try:
role = RoleTypes(as_role) if as_role else None
rules_v2, issues = importers.ExcelImporter(path).to_rules(role=role)
error_text = ""
rules_schema_version = "v2"
if rules_v2:
remaped_rules = rules_v2.model_dump()
except Exception as e:
error_text = str(e)
rules_schema_version = "unknown"

return {
"properties": properties,
"metadata": rules.metadata.model_dump(),
"classes": classes,
"rules": remaped_rules,
"file_name": path.name,
"hash": get_file_hash(path),
"error_text": error_text,
"src": src,
"rules_schema_version": rules_schema_version,
}


Expand Down
6 changes: 3 additions & 3 deletions cognite/neat/app/ui/neat-app/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"files": {
"main.css": "./static/css/main.38a62222.css",
"main.js": "./static/js/main.2efd96b2.js",
"main.js": "./static/js/main.25d27396.js",
"static/media/logo.svg": "./static/media/logo.8093b84df9ed36a174c629d6fe0b730d.svg",
"index.html": "./index.html",
"main.38a62222.css.map": "./static/css/main.38a62222.css.map",
"main.2efd96b2.js.map": "./static/js/main.2efd96b2.js.map"
"main.25d27396.js.map": "./static/js/main.25d27396.js.map"
},
"entrypoints": [
"static/css/main.38a62222.css",
"static/js/main.2efd96b2.js"
"static/js/main.25d27396.js"
]
}
116 changes: 116 additions & 0 deletions cognite/neat/app/ui/neat-app/build/img/architect-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading