Working with the Celonis Studio¶
In this tutorial you can see the basic way of how interact with the Celonis studio. Be aware that any change you make will only appear in the Celonis Studio after you publish the package via .publish()
1. Connect to Celonis¶
In [ ]:
Copied!
from pycelonis import get_celonis
celonis = get_celonis()
from pycelonis import get_celonis
celonis = get_celonis()
2. Find or Create a space and package¶
You can find spaces and packages using key, id or name.
In [11]:
Copied!
space = celonis.create_space("test-space") # Create space
space = celonis.spaces.find("test-space") # Find space
space
space = celonis.create_space("test-space") # Create space
space = celonis.spaces.find("test-space") # Find space
space
Out[11]:
<Space, id fac75d2a-5967-43ae-bb74-869b59efc0c4, name test-space>
In [8]:
Copied!
package = space.create_package("name_or_key")
package = space.create_package("name_or_key")
In [ ]:
Copied!
package = space.packages.find("name_or_key")
package.publish(version="1.1.1")
package = space.packages.find("name_or_key")
package.publish(version="1.1.1")
In [10]:
Copied!
package
package
Out[10]:
<Package, id 9994ac3c-af82-4065-8444-f5b64a1cfca5, name name_or_key>
Package Information
In [8]:
Copied!
package.name
package.name
Out[8]:
'test-package'
In [9]:
Copied!
package.history
package.history
Out[9]:
[{'key': 'test-package', 'name': 'test-package', 'version': None, 'date': 1612779377367, 'active': False, 'authorId': '32a2e630-8e1b-4add-a1be-4e9d9ec02a42', 'draftId': '2bf15b80-7ce8-43d8-89d9-c732259d2c62'}]
In [30]:
Copied!
package.variables
package.variables
Out[30]:
[{'description': 'test_var_descr', 'key': 'create-test', 'type': 'DATA_MODEL'}, {'description': 'test_var_descr', 'key': 'create-test2', 'type': 'DATA_MODEL'}]
In [31]:
Copied!
package.knowledge_models
package.knowledge_models
Out[31]:
[<KnowledgeModel, id d0cf6e40-8b12-4014-88f9-fe65b967e928, name test-km-123>,]
In [32]:
Copied!
package.folders
package.folders
Out[32]:
[]
In [13]:
Copied!
package.nodes
package.nodes
Out[13]:
[]
In [34]:
Copied!
package.variable_assignments
package.variable_assignments
Out[34]:
[{'key': 'create-test', 'value': '14182f83-9841-4416-8e4b-e2613183bc55', 'type': 'DATA_MODEL'}, {'key': 'create-test2', 'value': '14182f83-9841-4416-8e4b-e2613183bc55', 'type': 'DATA_MODEL'}]
Create a Variable in the Package
In [16]:
Copied!
package.create_variable(
"create-test2",
'14182f83-9841-4416-8e4b-e2613183bc55',
variable_type='DATA_MODEL',
description='test_var_descr',
)
package.create_variable(
"create-test2",
'14182f83-9841-4416-8e4b-e2613183bc55',
variable_type='DATA_MODEL',
description='test_var_descr',
)
In [17]:
Copied!
package.variables
package.variables
Out[17]:
[{'description': 'test_var_descr', 'key': 'create-test', 'type': 'DATA_MODEL'}, {'description': 'test_var_descr', 'key': 'create-test2', 'type': 'DATA_MODEL'}]
3. Find or Create Knowledge Model in Package¶
In [ ]:
Copied!
km = package.create_knowledge_model(
"test-km-123",
key=None,
data_model_id='abc12345',
data_model_variable='',
)
km = package.create_knowledge_model(
"test-km-123",
key=None,
data_model_id='abc12345',
data_model_variable='',
)
In [18]:
Copied!
km = package.knowledge_models.find("test-km-123")
km = package.knowledge_models.find("test-km-123")
In [19]:
Copied!
km
km
Out[19]:
<KnowledgeModel, id d0cf6e40-8b12-4014-88f9-fe65b967e928, name test-km-123>
In [25]:
Copied!
km.content
km.content
Out[25]:
{'customObjects': [{'customAttributes': {'attr1': 'value1'}, 'displayName': 'testname', 'id': 'testid'}], 'dataModelId': 'abc12345', 'kind': 'BASE', 'kpis': [], 'metadata': {'displayName': 'test-km-123', 'key': 'test-km-123'}, 'variables': []}
Knowledge Model Information
In [26]:
Copied!
km.custom_objects
km.custom_objects
Out[26]:
[{'customAttributes': {'attr1': 'value1'}, 'displayName': 'testname', 'id': 'testid'}]
In [27]:
Copied!
km.kpis
km.kpis
Out[27]:
[]
In [28]:
Copied!
km.variables
km.variables
Out[28]:
[]
Add and remove Custom Objects to Knowledge Model
In [29]:
Copied!
km.add_custom_object("testid2", "testname2", custom_attributes={"attr1": "value1"})
km.add_custom_object("testid2", "testname2", custom_attributes={"attr1": "value1"})
In [ ]:
Copied!
km.remove_custom_object(id="12345")
km.remove_custom_object(id="12345")
Execute PQL from Knowledgemodel
In [ ]:
Copied!
from celonis_api.pql.pql import PQL
#### Executing KPI - PQL from Knowledge Model
space = celonis.spaces.find("space-name")
p = space.packages.find("package-name")
km = p.knowledge_models.find("km-name")
dm = celonis.datamodels.find("dm-id")
# Appending KPI
query = PQL()
query += km.kpis.find("kpi-name")
# Verify evaluated query
print(km.kpis.find("kpi-name").query)
result = dm.get_data_frame(query)
result.head()
from celonis_api.pql.pql import PQL
#### Executing KPI - PQL from Knowledge Model
space = celonis.spaces.find("space-name")
p = space.packages.find("package-name")
km = p.knowledge_models.find("km-name")
dm = celonis.datamodels.find("dm-id")
# Appending KPI
query = PQL()
query += km.kpis.find("kpi-name")
# Verify evaluated query
print(km.kpis.find("kpi-name").query)
result = dm.get_data_frame(query)
result.head()
In [ ]:
Copied!
#### Executing Records - PQL from Knowledge Model
space = celonis.spaces.find("space-name")
p = space.packages.find("package-name")
km = p.knowledge_models.find("km-name")
dm = celonis.datamodels.find("dm-id")
# Appending record
query = PQL()
query += km.records.find("record-name")
# Verify evaluated query
print("Record: ",km.records.find("record-name"))
result = dm.get_data_frame(query)
result.head()
#### Executing Records - PQL from Knowledge Model
space = celonis.spaces.find("space-name")
p = space.packages.find("package-name")
km = p.knowledge_models.find("km-name")
dm = celonis.datamodels.find("dm-id")
# Appending record
query = PQL()
query += km.records.find("record-name")
# Verify evaluated query
print("Record: ",km.records.find("record-name"))
result = dm.get_data_frame(query)
result.head()
In [2]:
Copied!
#### Executing Records (Identifier and Attributes separately) - PQL from Knowledge Model
space = celonis.spaces.find("space-name")
p = space.packages.find("package-name")
km = p.knowledge_models.find("km-name")
dm = celonis.datamodels.find("dm-id")
# Appending record identifier
query = PQL()
query += km.records.find("record-name").identifier
# Appending record attributes
query += km.records.find("record-name").attributes
# Verify evaluated query
print("Record identifier: ",km.records.find("record-name").identifier)
print("Record attributes: ",km.records.find("record-name").attributes)
result = dm.get_data_frame(query)
result.head()
#### Executing Records (Identifier and Attributes separately) - PQL from Knowledge Model
space = celonis.spaces.find("space-name")
p = space.packages.find("package-name")
km = p.knowledge_models.find("km-name")
dm = celonis.datamodels.find("dm-id")
# Appending record identifier
query = PQL()
query += km.records.find("record-name").identifier
# Appending record attributes
query += km.records.find("record-name").attributes
# Verify evaluated query
print("Record identifier: ",km.records.find("record-name").identifier)
print("Record attributes: ",km.records.find("record-name").attributes)
result = dm.get_data_frame(query)
result.head()
4. Publish a package¶
In [ ]:
Copied!
# explicit version
package.publish(version="2.0.3")
# explicit version
package.publish(version="2.0.3")
In [35]:
Copied!
# or simply next version number
package.publish()
# or simply next version number
package.publish()
2021-02-08 10:20:34 - pycelonis: Successfully published version 0.0.1 of package.
5. Working with analyses in Studio¶
Retrieve analysis:
In [9]:
Copied!
a = package.analyses.find("celosphere21_analysis")
a
a = package.analyses.find("celosphere21_analysis")
a
Out[9]:
<Analysis, id 2a686c53-f4e6-40bf-8647-d410a004bd29, name celosphere21_analysis>
Work with variables and formulas:
In [10]:
Copied!
a.draft.variables
a.draft.variables
Out[10]:
[]
In [12]:
Copied!
a.draft.create_variable("TEST_VAR", "TEST_VALUE", var_type="text_replacement")
a.draft.create_variable("TEST_VAR", "TEST_VALUE", var_type="text_replacement")
Out[12]:
{'name': 'TEST_VAR', 'type': 'text_replacement', 'value': 'TEST_VALUE'}
In [14]:
Copied!
a.saved_formulas
a.saved_formulas
Out[14]:
[]
In [17]:
Copied!
a.create_saved_formula(
name="TEST_FORMULA",
description="TEST_DESCRIPTION",
template=""" COUNT_TABLE("VBAP") """
)
a.create_saved_formula(
name="TEST_FORMULA",
description="TEST_DESCRIPTION",
template=""" COUNT_TABLE("VBAP") """
)
Out[17]:
<BaseAnalysisSavedFormula, id 20a63ffa-4236-499d-8db7-ca28f5c4a8f2, name TEST_FORMULA>
Interact with sheets and components:
In [22]:
Copied!
a.draft.sheets
a.draft.sheets
Out[22]:
[<BaseAnalysisSheet, id 88ddb7b2-dffd-4b2c-8725-fe06bc4ccace, name Data Overview>, <BaseAnalysisSheet, id dd437fef-f36d-486f-8123-7af2f69b8254, name Anomalies>,]
In [23]:
Copied!
a.draft.components
a.draft.components
Out[23]:
[<BaseAnalysisTable, id 179e6d61-7a2f-4bd8-a92f-13e5de4950b0, name # New Sales Order Items>, <BaseAnalysisTable, id 0c1bc604-2bae-4d7b-af2a-1570e445278a, name #{# New Sales Order Items Per Customer}>, <BaseAnalysisTable, id 66c2f2b8-1f34-483b-ba89-6b3a0d56e645, name #{# New Sales Order Items Per Material}>, <BaseAnalysisComponent, id b7fe435d-6be1-4780-b24b-fc3c119642a0, name >, <BaseAnalysisComponent, id 3e41a063-40ed-4100-a240-913c06ef9e97, name >, <BaseAnalysisTable, id be0e8b09-e560-4f98-805b-8dc3ed14c4f3, name #{Most Recent Anomalies}>, <BaseAnalysisComponent, id f18e05bf-423d-4332-b49b-de9942d2d7d5, name >, <BaseAnalysisComponent, id c5af935b-cc89-4860-b293-b922c798c349, name >, <BaseAnalysisTable, id 6a58028e-7ff3-479f-a8a2-32d8f31e3f33, name #{#Anomalies per Day}>, <BaseAnalysisTable, id dc47ef8b-a3eb-41e1-abe7-2ea68d3dc5e9, name # New Sales Order Items>,]
Information on how to pull data from analysis can be found in notebook 01_Pulling_data.ipynb
In [ ]:
Copied!