|
| 1 | +import time |
1 | 2 | from typing import List, Optional |
2 | 3 |
|
3 | 4 | from django.shortcuts import get_object_or_404 |
@@ -219,3 +220,27 @@ def sessions(self, request, parent_lookup_workspace__name: str, name: str): |
219 | 220 | serializer = NetworkSessionSerializer(sessions, many=True) |
220 | 221 |
|
221 | 222 | return Response(serializer.data, status=status.HTTP_200_OK) |
| 223 | + |
| 224 | + @swagger_auto_schema() |
| 225 | + @action(detail=True, methods=['POST']) |
| 226 | + @require_workspace_permission(WorkspaceRoleChoice.WRITER) |
| 227 | + def algorithm(self, request, parent_lookup_workspace__name: str, name: str): |
| 228 | + workspace: Workspace = get_object_or_404(Workspace, name=parent_lookup_workspace__name) |
| 229 | + network: Network = get_object_or_404(Network, workspace=workspace, name=name) |
| 230 | + |
| 231 | + print(f'running label propagation on {workspace.name}/{network.name}') |
| 232 | + db = workspace.get_arango_db() |
| 233 | + job_id = db.pregel.create_job( |
| 234 | + graph=network.name, |
| 235 | + algorithm='labelpropagation', |
| 236 | + store=True, |
| 237 | + async_mode=False, |
| 238 | + result_field='_community_LP', |
| 239 | + ) |
| 240 | + job = db.pregel.job(job_id) |
| 241 | + |
| 242 | + while job['state'] in {'running', 'storing'}: |
| 243 | + time.sleep(0.25) |
| 244 | + print('[label propagation] waiting') |
| 245 | + |
| 246 | + return Response(status=status.HTTP_204_NO_CONTENT) |
0 commit comments