Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-graph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Lambert
swh-graph
Commits
51d6b602
Commit
51d6b602
authored
5 years ago
by
Stefano Zacchiroli
Browse files
Options
Downloads
Patches
Plain Diff
add /last sub-endpoint to only return destination in walks
works for both random and non-random walks Closes T2084
parent
51cd3e1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/api.rst
+6
-1
6 additions, 1 deletion
docs/api.rst
swh/graph/client.py
+8
-4
8 additions, 4 deletions
swh/graph/client.py
swh/graph/server/app.py
+11
-2
11 additions, 2 deletions
swh/graph/server/app.py
swh/graph/tests/test_api_client.py
+27
-9
27 additions, 9 deletions
swh/graph/tests/test_api_client.py
with
52 additions
and
16 deletions
docs/api.rst
+
6
−
1
View file @
51d6b602
...
...
@@ -144,7 +144,6 @@ Walk
swh:1:rev:8d517bdfb57154b8a11d7f1682ecc0f79abf8e02
...
.. http:get:: /graph/randomwalk/:src/:dst
Performs a graph *random* traversal, i.e., picking one random successor
...
...
@@ -178,6 +177,12 @@ Walk
...
.. http:get:: /graph/randomwalk/last/:src/:dst
Same as ``/graph/randomwalk``, but only retururn the last visited node,
i.e., destination, if any.
Visit
-----
...
...
This diff is collapsed.
Click to expand it.
swh/graph/client.py
+
8
−
4
View file @
51d6b602
...
...
@@ -72,18 +72,22 @@ class RemoteGraphClient(RPCClient):
'
direction
'
:
direction
}))
def
walk
(
self
,
src
,
dst
,
edges
=
"
*
"
,
traversal
=
"
dfs
"
,
direction
=
"
forward
"
):
def
walk
(
self
,
src
,
dst
,
edges
=
"
*
"
,
traversal
=
"
dfs
"
,
direction
=
"
forward
"
,
last
=
False
):
endpoint
=
'
walk/last/{}/{}
'
if
last
else
'
walk/{}/{}
'
return
self
.
get_lines
(
'
walk/{}/{}
'
.
format
(
src
,
dst
),
endpoint
.
format
(
src
,
dst
),
params
=
{
'
edges
'
:
edges
,
'
traversal
'
:
traversal
,
'
direction
'
:
direction
})
def
random_walk
(
self
,
src
,
dst
,
edges
=
"
*
"
,
direction
=
"
forward
"
):
def
random_walk
(
self
,
src
,
dst
,
edges
=
"
*
"
,
direction
=
"
forward
"
,
last
=
False
):
endpoint
=
'
randomwalk/last/{}/{}
'
if
last
else
'
randomwalk/{}/{}
'
return
self
.
get_lines
(
'
randomwalk/{}/{}
'
.
format
(
src
,
dst
),
endpoint
.
format
(
src
,
dst
),
params
=
{
'
edges
'
:
edges
,
'
direction
'
:
direction
...
...
This diff is collapsed.
Click to expand it.
swh/graph/server/app.py
+
11
−
2
View file @
51d6b602
...
...
@@ -125,7 +125,7 @@ def get_simple_traversal_handler(ttype):
return
simple_traversal
def
get_walk_handler
(
random
=
False
):
def
get_walk_handler
(
random
=
False
,
last
=
False
):
async
def
walk
(
request
):
backend
=
request
.
app
[
'
backend
'
]
...
...
@@ -144,7 +144,12 @@ def get_walk_handler(random=False):
src_node
,
dst
)
else
:
it
=
backend
.
walk
(
direction
,
edges
,
algo
,
src_node
,
dst
)
res_node
=
None
async
for
res_node
in
it
:
if
not
last
:
res_pid
=
pid_of_node
(
res_node
,
backend
)
await
response
.
write
(
'
{}
\n
'
.
format
(
res_pid
).
encode
())
if
last
and
res_node
is
not
None
:
res_pid
=
pid_of_node
(
res_node
,
backend
)
await
response
.
write
(
'
{}
\n
'
.
format
(
res_pid
).
encode
())
return
response
...
...
@@ -204,9 +209,13 @@ def make_app(backend, **kwargs):
# temporarily disabled in wait of a proper fix for T1969
# app.router.add_get('/graph/walk/{src}/{dst}',
# get_walk_handler(random=False))
# app.router.add_get('/graph/walk/last/{src}/{dst}',
# get_walk_handler(random=False, last=True))
app
.
router
.
add_get
(
'
/graph/randomwalk/{src}/{dst}
'
,
get_walk_handler
(
random
=
True
))
get_walk_handler
(
random
=
True
,
last
=
False
))
app
.
router
.
add_get
(
'
/graph/randomwalk/last/{src}/{dst}
'
,
get_walk_handler
(
random
=
True
,
last
=
True
))
app
.
router
.
add_get
(
'
/graph/neighbors/count/{src}
'
,
get_count_handler
(
'
neighbors
'
))
...
...
This diff is collapsed.
Click to expand it.
swh/graph/tests/test_api_client.py
+
27
−
9
View file @
51d6b602
...
...
@@ -93,12 +93,14 @@ def test_visit_paths(graph_client):
@pytest.mark.skip
(
reason
=
'
currently disabled due to T1969
'
)
def
test_walk
(
graph_client
):
actual
=
list
(
graph_client
.
walk
(
'
swh:1:dir:0000000000000000000000000000000000000016
'
,
'
rel
'
,
edges
=
'
dir:dir,dir:rev,rev:*
'
,
direction
=
'
backward
'
,
traversal
=
'
bfs
'
))
args
=
(
'
swh:1:dir:0000000000000000000000000000000000000016
'
,
'
rel
'
)
kwargs
=
{
'
edges
'
:
'
dir:dir,dir:rev,rev:*
'
,
'
direction
'
:
'
backward
'
,
'
traversal
'
:
'
bfs
'
,
}
actual
=
list
(
graph_client
.
walk
(
*
args
,
**
kwargs
))
expected
=
[
'
swh:1:dir:0000000000000000000000000000000000000016
'
,
'
swh:1:dir:0000000000000000000000000000000000000017
'
,
...
...
@@ -107,18 +109,34 @@ def test_walk(graph_client):
]
assert
set
(
actual
)
==
set
(
expected
)
kwargs2
=
kwargs
.
copy
()
kwargs2
[
'
last
'
]
=
True
actual
=
list
(
graph_client
.
walk
(
*
args
,
**
kwargs2
))
expected
=
[
'
swh:1:rel:0000000000000000000000000000000000000019
'
]
assert
set
(
actual
)
==
set
(
expected
)
def
test_random_walk
(
graph_client
):
"""
as the walk is random, we test a visit from a cnt node to the only origin in
the dataset, and only check the final node of the path (i.e., the origin)
"""
src
=
'
swh:1:cnt:0000000000000000000000000000000000000001
'
actual
=
list
(
graph_client
.
random_walk
(
src
,
'
ori
'
,
direction
=
'
backward
'
))
args
=
(
'
swh:1:cnt:0000000000000000000000000000000000000001
'
,
'
ori
'
)
kwargs
=
{
'
direction
'
:
'
backward
'
}
expected_root
=
'
swh:1:ori:0000000000000000000000000000000000000021
'
assert
actual
[
0
]
==
src
actual
=
list
(
graph_client
.
random_walk
(
*
args
,
**
kwargs
))
assert
len
(
actual
)
>
1
# no origin directly links to a content
assert
actual
[
0
]
==
args
[
0
]
assert
actual
[
-
1
]
==
expected_root
kwargs2
=
kwargs
.
copy
()
kwargs2
[
'
last
'
]
=
True
actual
=
list
(
graph_client
.
random_walk
(
*
args
,
**
kwargs2
))
assert
actual
==
[
expected_root
]
def
test_count
(
graph_client
):
actual
=
graph_client
.
count_leaves
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment