Analysis Builder
elements.sdk.builder.analysis
This is a basic builder to help build factories in a safe way instead of managing JSON configuration files. This includes all the methods to incrementally build out an Analysis Manifest and Analysis Config proto struct that can be used in API calls.
AnalysisManifest
AnalysisManifest.metadata()
- description (str) - description of the Analysis Version
- version (str) - version of the Analysis
- tags (List[str]) - descriptive tags for the Analysis Version
AnalysisManifest.manifest_version()
- version (str) - version of the Analysis Manifest
AnalysisManifest.add_node()
Add a node to the DAG. Note, this is a unique name safe generated as it will add a UUID to the end of the name given as a suffix to ensure uniqueness.
- name (str) - unique name for the Algorithm node
- algorithm_version_id (str) - Algorithm Version to use for the node
- [Optional] children (List[str]) - list of the names of child nodes
AnalysisManifest.add_node_edge()
Creates a directed edge between two nodes in the DAG.
- parent_index (int) - parent node index to draw an edge from
- child_index (int) - child node index to draw an edge to
AnalysisManifest.get_name()
- node_index (int) - node index to get the name for
AnalysisManifest.get() - return full Analysis Manifest
AnalysisManifest.print() - display Analysis DAG structure (not to be used in production code)
Single Node Directed Acyclic Graph
from elements.sdk.elements_sdk as TerraScopeSDK
from elements.sdk.builder.analysis import AnalysisManifest
# Construct Analysis Manifest
manifest = AnalysisManifest()
manifest.metadata(description="Test description for the greatest manifest in the world.",
version="0.0.1",
tags=["device-visits", "result-test"])
manifest.add_node(name="device-visits",
algorithm_version_id="5ee03b8e-ab45-4553-b5f4-a5029254a9de")
# Create Analysis Version
sdk = ElementsSDK()
await sdk.analysis_version.create(analysis_id="76be2b51-660f-47c8-8125-b04f2d1c2463",
analysis_manifest=manifest)Multi-Node Directed Acyclic Graph
from elements.sdk.elements_sdk as TerraScopeSDK
from elements.sdk.builder.analysis import AnalysisManifest
# Construct Analysis Manifest
manifest = AnalysisManifest()
manifest.metadata(description="Test description for the greatest manifest in the world.",
version="0.0.1",
tags=["device-visits", "result-test"])
manifest.add_node(name="device-visits",
algorithm_version_id="5ee03b8e-ab45-4553-b5f4-a5029254a9de")
manifest.add_node(name="device-tracks",
algorithm_version_id="6f7cff18-c2a2-4246-b0d4-21be09673a6b")
#Make device-visits the parent of device tracks
manifest.add_node_edge(parent_index=0, child_index=1)
# Create Analysis Version
sdk = ElementsSDK()
await sdk.analysis_version.create(analysis_id="76be2b51-660f-47c8-8125-b04f2d1c2463",
analysis_manifest=manifest)AnalysisConfiguration
AnalysisConfiguration.add_config_node()
This method adds an AnalysisAlgorithmConfigNode which references the EXACT node name used to define a node in the analyses that you are referencing. It also assigns the Algorithm Configuration ID to that node meaning here are the specific runtime specifications.
- name (str) - name of the node you wish to set the config for (exact match)
- algorithm_config_id (str) - the Algorithm Config you would like to apply to the node
- [Optional] node_index (int) - if specified, the node will be inserted before the provided index
AnalysisConfiguration.get() - return the full Analysis Config
from elements.sdk.builder.analysis import AnalysisConfiguration
# Construct Config
config = AnalysisConfiguration(analysis_version_id="96b49764-007d-4166-9a5f-600b9bfa9ba6")
config.add_config_node(name="device-visits", algorithm_config_id="3e868d01-e433-4fe8-a15f-ed63dfb47b11")
config.add_config_node(name="device-tracks", algorithm_config_id="b549fde5-c452-4bad-80a3-791f535f3027")
# Create Analysis Config
await sdk.analysis_config.create(
analysis_version_id="96b49764-007d-4166-9a5f-600b9bfa9ba6",
algorithm_config_nodes=config.get(),
name="Cool Conifg",
description="My first mulit-node analysis config"
)Updated 6 months ago