Skip to content

Commit ea4cb43

Browse files
authored
Merge pull request #1589 from pierotofy/objdec
AI Object Detection
2 parents 95ce02f + 320bbaf commit ea4cb43

File tree

23 files changed

+579
-25
lines changed

23 files changed

+579
-25
lines changed

app/api/workers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ def get(self, request, celery_task_id=None, **kwargs):
1717
res = TestSafeAsyncResult(celery_task_id)
1818

1919
if not res.ready():
20-
return Response({'ready': False}, status=status.HTTP_200_OK)
20+
out = {'ready': False}
21+
22+
# Copy progress meta
23+
if res.state == "PROGRESS" and res.info is not None:
24+
for k in res.info:
25+
out[k] = res.info[k]
26+
27+
return Response(out, status=status.HTTP_200_OK)
2128
else:
2229
result = res.get()
2330

@@ -29,6 +36,9 @@ def get(self, request, celery_task_id=None, **kwargs):
2936
msg = self.on_error(result)
3037
return Response({'ready': True, 'error': msg})
3138

39+
if isinstance(result.get('file'), str) and not os.path.isfile(result.get('file')):
40+
return Response({'ready': True, 'error': "Cannot generate file"})
41+
3242
return Response({'ready': True})
3343

3444
def on_error(self, result):

app/plugins/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from app.api.tasks import TaskNestedView as TaskView
44
from app.api.workers import CheckTask as CheckTask
55
from app.api.workers import GetTaskResult as GetTaskResult
6+
from app.api.workers import TaskResultOutputError
67

78
from django.http import HttpResponse, Http404
89
from .functions import get_plugin_by_name, get_active_plugins

app/plugins/worker.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ def run_function_async(func, *args, **kwargs):
1515
return eval_async.delay(source, func.__name__, *args, **kwargs)
1616

1717

18-
@app.task
19-
def eval_async(source, funcname, *args, **kwargs):
18+
@app.task(bind=True)
19+
def eval_async(self, source, funcname, *args, **kwargs):
2020
"""
2121
Run Python code asynchronously using Celery.
2222
It's recommended to use run_function_async instead.
2323
"""
2424
ns = {}
2525
code = compile(source, 'file', 'exec')
2626
eval(code, ns, ns)
27+
28+
if kwargs.get("with_progress"):
29+
def progress_callback(status, perc):
30+
self.update_state(state="PROGRESS", meta={"status": status, "progress": perc})
31+
kwargs['progress_callback'] = progress_callback
32+
del kwargs['with_progress']
33+
2734
return ns[funcname](*args, **kwargs)

app/static/app/js/classes/Workers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import $ from 'jquery';
22

33
export default {
4-
waitForCompletion: (celery_task_id, cb, checkUrl = "/api/workers/check/") => {
4+
waitForCompletion: (celery_task_id, cb, progress_cb) => {
5+
const checkUrl = "/api/workers/check/";
56
let errorCount = 0;
67
let url = checkUrl + celery_task_id;
78

@@ -15,6 +16,9 @@ export default {
1516
}else if (result.ready){
1617
cb();
1718
}else{
19+
if (typeof progress_cb === "function" && result.progress !== undefined && result.status !== undefined){
20+
progress_cb(result.status, result.progress);
21+
}
1822
// Retry
1923
setTimeout(() => check(), 2000);
2024
}

coreplugins/contours/api.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ def post(self, request, pk=None):
109109
except ContoursException as e:
110110
return Response({'error': str(e)}, status=status.HTTP_200_OK)
111111

112-
class TaskContoursCheck(CheckTask):
113-
def on_error(self, result):
114-
pass
115-
116-
def error_check(self, result):
117-
contours_file = result.get('file')
118-
if not contours_file or not os.path.exists(contours_file):
119-
return _('Could not generate contour file. This might be a bug.')
120112

121113
class TaskContoursDownload(GetTaskResult):
122114
pass

coreplugins/contours/plugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from app.plugins import PluginBase
22
from app.plugins import MountPoint
33
from .api import TaskContoursGenerate
4-
from .api import TaskContoursCheck
54
from .api import TaskContoursDownload
65

76

@@ -15,6 +14,5 @@ def build_jsx_components(self):
1514
def api_mount_points(self):
1615
return [
1716
MountPoint('task/(?P<pk>[^/.]+)/contours/generate', TaskContoursGenerate.as_view()),
18-
MountPoint('task/[^/.]+/contours/check/(?P<celery_task_id>.+)', TaskContoursCheck.as_view()),
1917
MountPoint('task/[^/.]+/contours/download/(?P<celery_task_id>.+)', TaskContoursDownload.as_view()),
2018
]

coreplugins/contours/public/ContoursPanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default class ContoursPanel extends React.Component {
241241
this.setState({[loadingProp]: false});
242242
}
243243
}
244-
}, `/api/plugins/contours/task/${taskId}/contours/check/`);
244+
});
245245
}else if (result.error){
246246
this.setState({[loadingProp]: false, error: result.error});
247247
}else{

coreplugins/measure/api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework import serializers
33
from rest_framework import status
44
from rest_framework.response import Response
5-
from app.api.workers import GetTaskResult, TaskResultOutputError, CheckTask
5+
from app.api.workers import GetTaskResult, TaskResultOutputError
66
from app.models import Task
77
from app.plugins.views import TaskView
88
from django.utils.translation import gettext_lazy as _
@@ -34,9 +34,6 @@ def post(self, request, pk=None):
3434
except Exception as e:
3535
return Response({'error': str(e)}, status=status.HTTP_200_OK)
3636

37-
class TaskVolumeCheck(CheckTask):
38-
pass
39-
4037
class TaskVolumeResult(GetTaskResult):
4138
def get(self, request, pk=None, celery_task_id=None):
4239
task = Task.objects.only('dsm_extent').get(pk=pk)

coreplugins/measure/plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from app.plugins import MountPoint
22
from app.plugins import PluginBase
3-
from .api import TaskVolume, TaskVolumeCheck, TaskVolumeResult
3+
from .api import TaskVolume, TaskVolumeResult
44

55
class Plugin(PluginBase):
66
def include_js_files(self):
@@ -12,6 +12,5 @@ def build_jsx_components(self):
1212
def api_mount_points(self):
1313
return [
1414
MountPoint('task/(?P<pk>[^/.]+)/volume$', TaskVolume.as_view()),
15-
MountPoint('task/[^/.]+/volume/check/(?P<celery_task_id>.+)$', TaskVolumeCheck.as_view()),
1615
MountPoint('task/(?P<pk>[^/.]+)/volume/get/(?P<celery_task_id>.+)$', TaskVolumeResult.as_view()),
1716
]

coreplugins/measure/public/MeasurePopup.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class MeasurePopup extends React.Component {
6868
}
6969

7070
getGeoJSON(){
71-
const geoJSON = this.props.resultFeature.toGeoJSON();
71+
const geoJSON = this.props.resultFeature.toGeoJSON(14);
7272
geoJSON.properties = this.getProperties();
7373
return geoJSON;
7474
}
@@ -125,7 +125,7 @@ export default class MeasurePopup extends React.Component {
125125
type: 'POST',
126126
url: `/api/plugins/measure/task/${task.id}/volume`,
127127
data: JSON.stringify({
128-
area: this.props.resultFeature.toGeoJSON(),
128+
area: this.props.resultFeature.toGeoJSON(14),
129129
method: baseMethod
130130
}),
131131
contentType: "application/json"
@@ -139,7 +139,7 @@ export default class MeasurePopup extends React.Component {
139139
else this.setState({volume: parseFloat(volume)});
140140
}, `/api/plugins/measure/task/${task.id}/volume/get/`);
141141
}
142-
}, `/api/plugins/measure/task/${task.id}/volume/check/`);
142+
});
143143
}else if (result.error){
144144
this.setState({error: result.error});
145145
}else{

0 commit comments

Comments
 (0)