Vertex metrics and functions
Vertices can be accessed by storing the object returned from a call to add_vertex()
, by directly asking for a specific node via vertex()
, or by iterating over all nodes via vertices()
. Once you have a vertex, we can ask it some questions.
Update history
Vertices have functions for querying their earliest/latest update time (as an epoch or datetime) as well as for accessing their full history (history()
). In the code below we create a vertex object for the monkey Felipe
and see when their updates occurred.
v = g.vertex("FELIPE")
print(
f"{v.name()}'s first interaction was at {v.earliest_date_time()} and their last interaction was at {v.latest_date_time()}\n"
)
print(f"{v.name()} had interactions at the following times: {v.history()}\n")
Output
FELIPE's first interaction was at 2019-06-13 09:50:00 and their last interaction was at 2019-07-10 11:05:00
FELIPE had interactions at the following times: [1560419400000, 1560419460000, 1560419520000, 1560419580000, 1560419640000, 1560420720000, 1560421260000, 1560422580000, 1560423360000, 1560423420000, 1560423600000, 1560437400000, 1560437460000, 1560437640000, 1560439920000, 1560439980000, 1560440160000, 1560440640000, 1560441780000, 1560441840000, 1560441960000, 1560443040000, 1560504000000, 1560504540000, 1560506760000, 1560507540000, 1560508320000, 1560508380000, 1560508500000, 1560523260000, 1560523620000, 1560523680000, 1560523740000, 1560523860000, 1560524880000, 1560525600000, 1560525720000, 1560526140000, 1560526260000, 1560526320000, 1560769320000, 1560769440000, 1560775740000, 1560780060000, 1560780120000, 1560853500000, 1560854160000, 1560854400000, 1560855660000, 1560865320000, 1560865440000, 1560865500000, 1560934560000, 1560934680000, 1560934740000, 1560935460000, 1560935520000, 1560935640000, 1560936360000, 1560936660000, 1560937320000, 1560939900000, 1560939960000, 1560940020000, 1560943500000, 1560945660000, 1560945900000, 1560945960000, 1560946980000, 1560947640000, 1560948180000, 1560948480000, 1560948540000, 1560948600000, 1561025100000, 1561025700000, 1561026960000, 1561027860000, 1561029420000, 1561042560000, 1561042620000, 1561042740000, 1561043280000, 1561043340000, 1561044000000, 1561044420000, 1561044600000, 1561046100000, 1561110180000, 1561113480000, 1561113540000, 1561115460000, 1561115640000, 1561117140000, 1561117200000, 1561117560000, 1561117620000, 1561117680000, 1561117740000, 1561118580000, 1561120860000, 1561121820000, 1561122000000, 1561122060000, 1561122120000, 1561373640000, 1561373760000, 1561373820000, 1561373880000, 1561373940000, 1561374060000, 1561374480000, 1561374540000, 1561374840000, 1561375320000, 1561390800000, 1561390860000, 1561390920000, 1561390980000, 1561392540000, 1561392660000, 1561458300000, 1561458600000, 1561459680000, 1561459740000, 1561461180000, 1561461240000, 1561461960000, 1561475460000, 1561475820000, 1561477920000, 1561478040000, 1561478580000, 1561478640000, 1561478940000, 1561540200000, 1561540260000, 1561541520000, 1561541580000, 1561542780000, 1561542840000, 1561543080000, 1561543500000, 1561543560000, 1561545420000, 1561545540000, 1561555320000, 1561556100000, 1561556340000, 1561556400000, 1561558620000, 1561558680000, 1561627860000, 1561628220000, 1561638540000, 1561639560000, 1561640580000, 1561643340000, 1561643520000, 1561643580000, 1561716900000, 1561716960000, 1561717020000, 1561717080000, 1561717140000, 1561717200000, 1561720320000, 1561720380000, 1561970640000, 1561970760000, 1561970940000, 1561971060000, 1561971960000, 1561972860000, 1561975980000, 1561987200000, 1561992300000, 1562057520000, 1562074320000, 1562074380000, 1562074440000, 1562074500000, 1562074560000, 1562078100000, 1562078340000, 1562146020000, 1562146740000, 1562146860000, 1562148840000, 1562148900000, 1562148960000, 1562149020000, 1562149080000, 1562151240000, 1562152560000, 1562152620000, 1562153820000, 1562155380000, 1562155500000, 1562232600000, 1562232660000, 1562233140000, 1562233500000, 1562233560000, 1562234400000, 1562235900000, 1562237700000, 1562237940000, 1562248920000, 1562249040000, 1562249100000, 1562250600000, 1562251080000, 1562252940000, 1562253540000, 1562321400000, 1562321520000, 1562321580000, 1562322000000, 1562323560000, 1562324700000, 1562326800000, 1562326860000, 1562327820000, 1562331420000, 1562331720000, 1562332020000, 1562332380000, 1562585640000, 1562585940000, 1562586000000, 1562586360000, 1562586600000, 1562589420000, 1562596320000, 1562596380000, 1562600520000, 1562600880000, 1562601060000, 1562669820000, 1562669940000, 1562670060000, 1562671020000, 1562671200000, 1562679420000, 1562679480000, 1562679540000, 1562679600000, 1562682840000, 1562682960000, 1562683020000, 1562752800000, 1562753160000, 1562753640000, 1562754600000, 1562755440000, 1562756700000]
Neighbours, edges and paths
To investigate who a vertex is connected with we can ask for its degree()
, edges()
, or neighbours()
. As Raphtory is a directed graph all of these functions also have an in_
and out_
variation, allowing you get only incoming and outgoing connections respectively. These functions return the following:
- degree: A count of the number of unique connections a vertex has.
- edges: An iterable (
Edges
) of edge objects, one for each unique(src,dst)
pair. - neighbours: An iterable of vertex objects (
PathFromVertex
), one for each node the vertex shares an edge with.
In the code below we call a selection of these functions to show the sort of questions you may ask.
Info
The final section of the code makes use of v.neighbours().name().collect()
- this is a chain of functions which are run on each vertex in the PathFromVertex
iterable. We will discuss these sort of operations more in Chaining functions.
v = g.vertex("FELIPE")
v_name = v.name()
in_degree = v.in_degree()
out_degree = v.out_degree()
in_edges = v.in_edges()
neighbours = v.neighbours()
neighbour_names = v.neighbours().name().collect()
print(
f"{v_name} has {in_degree} incoming interactions and {out_degree} outgoing interactions.\n"
)
print(in_edges)
print(neighbours, "\n")
print(f"{v_name} interacted with the following baboons {neighbour_names}")
Output
FELIPE has 17 incoming interactions and 18 outgoing interactions.
Edges(Edge(source=ANGELE, target=FELIPE, earliest_time=1560419400000, latest_time=1562753640000, properties={Weight: 1}), Edge(source=LIPS, target=FELIPE, earliest_time=1560423600000, latest_time=1562756700000, properties={Weight: 1}), Edge(source=NEKKE, target=FELIPE, earliest_time=1560443040000, latest_time=1562596380000, properties={Weight: 1}), Edge(source=LOME, target=FELIPE, earliest_time=1560421260000, latest_time=1562149080000, properties={Weight: 1}), Edge(source=BOBO, target=FELIPE, earliest_time=1560423360000, latest_time=1561543080000, properties={Weight: -1}), Edge(source=ATMOSPHERE, target=FELIPE, earliest_time=1560524880000, latest_time=1561638540000, properties={Weight: 1}), Edge(source=FEYA, target=FELIPE, earliest_time=1560853500000, latest_time=1562586000000, properties={Weight: 1}), Edge(source=FANA, target=FELIPE, earliest_time=1560526140000, latest_time=1562752800000, properties={Weight: 1}), Edge(source=PIPO, target=FELIPE, earliest_time=1560420720000, latest_time=1562151240000, properties={Weight: 1}), Edge(source=MUSE, target=FELIPE, earliest_time=1560504540000, latest_time=1562755440000, properties={Weight: 1}), ...)
PathFromVertex(Vertex(name=ANGELE, earliest_time="1560419400000", latest_time="1562754600000", properties={_id: ANGELE}), Vertex(name=LIPS, earliest_time="1560419460000", latest_time="1562756700000", properties={_id: LIPS}), Vertex(name=NEKKE, earliest_time="1560419520000", latest_time="1562756700000", properties={_id: NEKKE}), Vertex(name=LOME, earliest_time="1560419520000", latest_time="1562756100000", properties={_id: LOME}), Vertex(name=BOBO, earliest_time="1560419520000", latest_time="1562755500000", properties={_id: BOBO}), Vertex(name=ATMOSPHERE, earliest_time="1560419640000", latest_time="1562683260000", properties={_id: ATMOSPHERE}), Vertex(name=FEYA, earliest_time="1560420000000", latest_time="1562756040000", properties={_id: FEYA}), Vertex(name=FANA, earliest_time="1560420000000", latest_time="1562754600000", properties={_id: FANA}), Vertex(name=PIPO, earliest_time="1560420660000", latest_time="1562752560000", properties={_id: PIPO}), Vertex(name=MUSE, earliest_time="1560421080000", latest_time="1562755500000", properties={_id: MUSE}), ...)
FELIPE interacted with the following baboons ['ANGELE', 'LIPS', 'NEKKE', 'LOME', 'BOBO', 'ATMOSPHERE', 'FEYA', 'FANA', 'PIPO', 'MUSE', 'MAKO', 'MALI', 'PETOULETTE', 'ARIELLE', 'HARLEM', 'VIOLETTE', 'EWINE', 'SELF']