Skip to main content

Hi,

I understand that we can define properties on edges, but it isn’t clear from the documentation how these properties are populated. I am trying to implement the following model

And defined the data model using DML as follows
 

How can I add a UserActivity edge with properties start_time and stop_time, that I can read while listing all the activities that a User has performed?

Thank you

Hi ​@Yatish Pitta 

 

The model definition you have provided will create a view UserActvitivy and a corresponding container to hold the edge properties. To populate edges you can use the Python SDK like this:


 

from cognite.client import CogniteClient
import cognite.client.data_classes.data_modeling as dm

client = CogniteClient()


client.data_modeling.instances.apply(
edges=dm.EdgeApply(
space=space_name,
external_id="user_activity001", # external id of the edge you are creating
type=dm.DirectRelationReference(space=space_name, external_id="User.activity"), # Required type property
start_node=dm.DirectRelationReference(space=space_name, external_id="activity001"), # Assuming presence of this activity node
end_node=dm.DirectRelationReference(space=space_name, external_id="user001"), // Assuming presence of this user nade
sources=r
dm.NodeOrEdgeData(
# View version for UserActivity is auto created

source=dm.ViewId(space=space_name, external_id="UserActivity", version=version),
properties={"start_time": "2025-02-28T09:00:00", "stop_time": "2025-02-28T09:01:00"},
)
],
)
)

Hope this helps.

 

Arild Eide


Reply