Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/latest and active #1786

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions python/python/raphtory/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ class Edge:
def id(self):
"""The id of the edge."""

def is_active(self):
"""
Check if the edge is currently active (i.e., has at least one update within this period)
Returns:
bool
"""

def is_deleted(self):
"""
Check if the edge is currently deleted
Expand All @@ -458,6 +465,14 @@ class Edge:
bool
"""

def latest(self):
"""
Create a view of the Edge including all events at the latest time.

Returns:
A Edge object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -882,6 +897,7 @@ class Edges:
def id(self):
"""Returns all ids of the edges."""

def is_active(self): ...
def is_deleted(self):
"""Check if the edges are deleted"""

Expand All @@ -891,6 +907,14 @@ class Edges:
def is_valid(self):
"""Check if the edges are valid (i.e. not deleted)"""

def latest(self):
"""
Create a view of the Edges including all events at the latest time.

Returns:
A Edges object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -1275,6 +1299,7 @@ class Graph:
The latest datetime that this GraphView is valid or None if the GraphView is valid for all times.
"""

def event_graph(self): ...
def exclude_layer(self, name):
"""
Return a view of GraphView containing all layers except the excluded `name`
Expand Down Expand Up @@ -1519,6 +1544,14 @@ class Graph:

"""

def latest(self):
"""
Create a view of the GraphView including all events at the latest time.

Returns:
A GraphView object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -2394,6 +2427,13 @@ class MutableEdge:
def id(self):
"""The id of the edge."""

def is_active(self):
"""
Check if the edge is currently active (i.e., has at least one update within this period)
Returns:
bool
"""

def is_deleted(self):
"""
Check if the edge is currently deleted
Expand All @@ -2415,6 +2455,14 @@ class MutableEdge:
bool
"""

def latest(self):
"""
Create a view of the Edge including all events at the latest time.

Returns:
A Edge object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -2878,6 +2926,15 @@ class MutableNode:
An iterator over the neighbours of this node that point into this node.
"""

def is_active(self): ...
def latest(self):
"""
Create a view of the Node including all events at the latest time.

Returns:
A Node object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -3347,6 +3404,15 @@ class Node:
An iterator over the neighbours of this node that point into this node.
"""

def is_active(self): ...
def latest(self):
"""
Create a view of the Node including all events at the latest time.

Returns:
A Node object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -3795,6 +3861,14 @@ class Nodes:
An iterator over the neighbours of this node that point into this node.
"""

def latest(self):
"""
Create a view of the Nodes including all events at the latest time.

Returns:
A Nodes object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -4443,6 +4517,14 @@ class PersistentGraph:
GraphIndex - Returns a GraphIndex
"""

def latest(self):
"""
Create a view of the GraphView including all events at the latest time.

Returns:
A GraphView object.
"""

@property
def latest_date_time(self):
"""
Expand Down Expand Up @@ -4813,6 +4895,7 @@ class PersistentGraph:
the nodes in the graph
"""

def persistent_graph(self): ...
@property
def properties(self):
"""
Expand Down
117 changes: 117 additions & 0 deletions python/tests/graphql/misc/test_latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from raphtory.graphql import RaphtoryClient


def test_latest_and_active():
from raphtory.graphql import GraphServer
from raphtory import Graph
import tempfile

query = """
{
graph(path: "graph") {
node(name: "1") {
name
isActive
latest {
history
}
}
e12: edge(src: "1", dst: "2") {
isActive
latest {
history
}
}
e13: edge(src: "1", dst: "3") {
latest {
isActive
history
}
}
nodes {
list {
name
edges {
latest {
list {
history
}
}
}
}
latest {
list {
name
history
}
}
}
edges {
latest {
list {
history
}
}
}
}
}
"""

result = {
"graph": {
"node": {"name": "1", "isActive": True, "latest": {"history": [3]}},
"e12": {"isActive": True, "latest": {"history": [3]}},
"e13": {"latest": {"isActive": False, "history": []}},
"nodes": {
"list": [
{
"name": "1",
"edges": {
"latest": {
"list": [
{"history": [3]},
{"history": []},
{"history": [3]},
]
}
},
},
{"name": "2", "edges": {"latest": {"list": [{"history": [3]}]}}},
{"name": "3", "edges": {"latest": {"list": [{"history": []}]}}},
{"name": "4", "edges": {"latest": {"list": [{"history": [3]}]}}},
],
"latest": {
"list": [
{"name": "1", "history": [3]},
{"name": "2", "history": [3]},
{"name": "4", "history": [3]},
]
},
},
"edges": {
"latest": {
"list": [{"history": [3]}, {"history": []}, {"history": [3]}]
}
},
}
}

work_dir = tempfile.mkdtemp()
g = Graph()
g.add_edge(1, 1, 2, {"int_prop": 123})
g.add_edge(2, 1, 2, {"int_prop": 124})
g.add_edge(3, 1, 2, {"int_prop": 125})

g.add_edge(1, 1, 3, {"int_prop": 123})
g.add_edge(2, 1, 3, {"int_prop": 124})
g.add_edge(3, 1, 4, {"int_prop": 125})

g.add_node(1, 1, {"int_prop": 123})
g.add_node(2, 1, {"int_prop": 124})
g.add_node(1, 2, {"int_prop": 125})
g.add_node(2, 2, {"int_prop": 125})

g.save_to_file(work_dir + "/graph")
with GraphServer(work_dir).start():
client = RaphtoryClient("http://localhost:1736")
assert client.query(query) == result
Loading
Loading