Skip to content

Commit

Permalink
[NEAT-218] 🐻‍❄️ Ensure Lifecycle Tutorials are up-to-date (#457)
Browse files Browse the repository at this point in the history
* refactor: Remove warning

* refactor: Update overview

* docs; Some extra newlines and fixes

* refactor: update

* refactor: added license and rights

* docs: updated David part

* docs: Update Alice

* docs: updated part 2

* docs Update part 3

* refactor: added dataModelType to information sheets

* refactor: Added ref model option for ExcelToRules

* refactor: added missing options for steps

* refactor: added missing modal

* docs: Finished part 3

* refactor: review feedback
  • Loading branch information
doctrino committed May 16, 2024
1 parent fd18985 commit fa1b754
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 168 deletions.
2 changes: 2 additions & 0 deletions cognite/neat/rules/models/information/_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class InformationMetadata(BaseMetadata):
"typically information architects are considered as contributors."
),
)
license: str | None = None
rights: str | None = None

@model_validator(mode="after")
def extension_none_but_schema_extend(self) -> Self:
Expand Down
37 changes: 30 additions & 7 deletions cognite/neat/workflows/steps/lib/current/rules_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,19 @@ class RulesToExcel(Step):
options=["input", *RoleTypes.__members__.keys()],
),
Configurable(
name="Is Reference",
value="False",
label="Export rules as reference rules. If provided, the rules will be exported as reference rules. ",
options=["True", "False"],
name="Dump Format",
value="user",
label="How to dump the rules to the Excel file.\n"
"'user' - just as is.\n'reference' - enterprise model used as basis for a solution model\n"
"'last' - used when updating a data model.",
options=list(exporters.ExcelExporter.dump_options),
),
Configurable(
name="New Data Model ID",
value="",
label="If you chose Dump Format 'reference', the provided ID will be use in the new medata sheet. "
"Expected format 'sp_space:my_external_id'.",
options=list(exporters.ExcelExporter.dump_options),
),
Configurable(
name="File path",
Expand All @@ -285,15 +294,29 @@ def run(self, rules: MultiRuleData) -> FlowMessage: # type: ignore[override, sy
if self.configs is None or self.data_store_path is None:
raise StepNotInitialized(type(self).__name__)

is_reference = self.configs.get("Is Reference") == "True"
dump_format = self.configs.get("Dump Format", "user")
styling = cast(exporters.ExcelExporter.Style, self.configs.get("Styling", "default"))
role = self.configs.get("Output role format")
output_role = None
if role != "input" and role is not None:
output_role = RoleTypes[role]

dump_as = "reference" if is_reference else "user"
excel_exporter = exporters.ExcelExporter(styling=styling, output_role=output_role, dump_as=dump_as) # type: ignore[arg-type]
new_model_str = self.configs.get("New Data Model ID")
new_model_id: tuple[str, str] | None = None
if new_model_str and ":" in new_model_str:
new_model_id = tuple(new_model_str.split(":", 1)) # type: ignore[assignment]
elif new_model_str:
return FlowMessage(
error_text="New Data Model ID must be in the format 'sp_space:my_external_id'!",
step_execution_status=StepExecutionStatus.ABORT_AND_FAIL,
)

excel_exporter = exporters.ExcelExporter(
styling=styling,
output_role=output_role,
dump_as=dump_format, # type: ignore[arg-type]
new_model_id=new_model_id,
)

rule_instance: Rules
if rules.domain:
Expand Down
23 changes: 21 additions & 2 deletions cognite/neat/workflows/steps/lib/current/rules_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import ClassVar

from cognite.client import CogniteClient
from cognite.client.data_classes.data_modeling import DataModelId

from cognite.neat.rules import importers
from cognite.neat.rules.issues.formatters import FORMATTER_BY_NAME
Expand Down Expand Up @@ -184,6 +185,13 @@ class DMSToRules(Step):
type="string",
required=True,
),
Configurable(
name="Reference data model id",
value="",
label="The ID of the Reference Data Model to import. Written at 'my_space:my_data_model(version=1)'. "
"This is typically an enterprise data model when you want to import a solution model",
type="string",
),
Configurable(
name="Report formatter",
value=next(iter(FORMATTER_BY_NAME.keys())),
Expand Down Expand Up @@ -214,8 +222,19 @@ def run(self, cdf_client: CogniteClient) -> (FlowMessage, MultiRuleData): # typ
f"or 'my_space:my_data_model', failed to parse space from {datamodel_id_str}"
)
return FlowMessage(error_text=error_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)

dms_importer = importers.DMSImporter.from_data_model_id(cdf_client, datamodel_entity.as_id())
ref_datamodel_str = self.configs.get("Reference data model id")
ref_model_id: DataModelId | None = None
if ref_datamodel_str is not None:
ref_model = DataModelEntity.load(ref_datamodel_str)
if isinstance(ref_model, DMSUnknownEntity):
error_text = (
f"Reference data model id should be in the format 'my_space:my_data_model(version=1)' "
f"or 'my_space:my_data_model', failed to parse space from {ref_datamodel_str}"
)
return FlowMessage(error_text=error_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)
ref_model_id = ref_model.as_id()

dms_importer = importers.DMSImporter.from_data_model_id(cdf_client, datamodel_entity.as_id(), ref_model_id)

# if role is None, it will be inferred from the rules file
role = self.configs.get("Role")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/artifacts/rules/information-analytics-olav.xlsx
Binary file not shown.
Binary file modified docs/artifacts/rules/information-architect-david.xlsx
Binary file not shown.
21 changes: 15 additions & 6 deletions docs/tutorials/data-modeling-lifecycle/overview.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# Overview

!!! warning annotate "Warning"

This set of tutorials are work in progress, and there might be minor changes to the completed ones while others
are being developed. We appreciate your understanding and patience.

In this set of tutorials, we will walk you through the data modeling lifecycle and how **NEAT** can assist in the
different tasks involved in the lifecycle. But first, let's understand what data modeling is and why it is important.
different tasks involved in building and maintaining data models. But first, let's understand what data modeling
is and why it is important.

Ultimately, the goal of data modeling is to use data to aid decision-making. To achieve this, a company
needs to coordinate between multiple different people and departments. A set of data models can be used as
Expand Down Expand Up @@ -35,3 +31,16 @@ different people with different roles can work together to achieve the goal of b
- **[Analytic Solution](./part-2-analytic-solution.md)**: In this tutorial, you will learn how to build a solution model
for a forecasting use case. The solution model is using a subset of the enterprise model and, in addition, adds
new concepts that are needed for the forecasting use case.

- **[Extending Enterprise Model](./part-3-extending-enterprise-model.md)**: In this tutorial, you will learn how to extend
the enterprise model while keeping the existing model intact. In this tutorial, we will add new concepts discovered
during the implementation of the forecasting use case.

- (Planned)**[Extending Solution Model](./part-4-extending-solution-model.md)**: In this tutorial, you will learn how
to extend the solution model while keeping the existing model intact. In this tutorial, we will add new concepts
discovered during the implementation of the forecasting use case.

- (Planned)**[Business Solution Model](./part-5-business-solution-model.md)**: In this tutorial, you will learn how to
use the Enterprise Model to build a Solution Model for a business case. This data model will only use a subset
of the Enterprise Model and not add any new concepts. It is intended for a business user that only needs to select
the part of the Enterprise Model that is relevant for their business case.
Loading

0 comments on commit fa1b754

Please sign in to comment.