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

Job status was implemented #153

Merged
merged 4 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions cvat/apps/engine/migrations/0012_auto_20181024_1504.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.0.9 on 2018-10-24 12:04

import cvat.apps.engine.models
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('engine', '0011_add_task_source_and_safecharfield'),
]

operations = [
migrations.AddField(
model_name='job',
name='status',
field=cvat.apps.engine.models.SafeCharField(default='annotation', max_length=32),
),
migrations.AlterField(
model_name='task',
name='status',
field=cvat.apps.engine.models.SafeCharField(default='annotation', max_length=32),
),
]
3 changes: 2 additions & 1 deletion cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Task(models.Model):
bug_tracker = models.CharField(max_length=2000, default="")
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now_add=True)
status = models.CharField(max_length=32, default="annotate")
status = SafeCharField(max_length=32, default="annotation")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you don't want the change. It is our internal error if we try to put here something more than 32. Better way to implement that is using Enums: https://hackernoon.com/using-enum-as-model-field-choice-in-django-92d8b97aaa63

overlap = models.PositiveIntegerField(default=0)
z_order = models.BooleanField(default=False)
flipped = models.BooleanField(default=False)
Expand Down Expand Up @@ -81,6 +81,7 @@ class Segment(models.Model):
class Job(models.Model):
segment = models.ForeignKey(Segment, on_delete=models.CASCADE)
annotator = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
status = SafeCharField(max_length=32, default="annotation")
# TODO: add sub-issue number for the task

class Label(models.Model):
Expand Down
18 changes: 16 additions & 2 deletions cvat/apps/engine/static/engine/js/annotationUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,26 @@ function setupMenu(job, shapeCollectionModel, annotationParser, aamModel, player
})();

$('#statTaskName').text(job.slug);
$('#statTaskStatus').text(job.status);
$('#statFrames').text(`[${job.start}-${job.stop}]`);
$('#statOverlap').text(job.overlap);
$('#statZOrder').text(job.z_order);
$('#statFlipped').text(job.flipped);

$('#statTaskStatus').prop("value", job.status === "completed" ? "completed" : (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$('#statTaskStatus').prop("value", job.status === "completed" ? "completed" : (
$('#statTaskStatus').prop("value", job.status)

job.status === "validation" ? "validation" : "annotation"
)).on('change', (e) => {
$.ajax({
type: 'POST',
url: 'save/job/status',
data: JSON.stringify({
jid: window.cvat.job.id,
status: e.target.value
}),
contentType: "application/json; charset=utf-8",
error: (data) => {
showMessage(`Can not change job status. Code: ${data.status}. Message: ${data.responeText || data.statusText}`);
}
});
});

let shortkeys = window.cvat.config.shortkeys;
$('#helpButton').on('click', () => {
Expand Down
24 changes: 22 additions & 2 deletions cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get(tid):
job_indexes = [segment.job_set.first().id for segment in db_segments]

response = {
"status": db_task.status.capitalize(),
"status": db_task.status,
"spec": {
"labels": { db_label.id:db_label.name for db_label in db_labels },
"attributes": attributes
Expand All @@ -185,6 +185,26 @@ def get(tid):

return response

def save_job_status(jid, status, user):
db_job = models.Job.objects.select_related("segment__task").select_for_update().get(pk = jid)
db_task = db_job.segment.task
if status not in ["annotation", "validation", "completed"]:
raise Exception("Got unknown job status")
slogger.job[jid].info('changing job status from {} to {} by an user {}'.format(db_job.status, status, user))
db_job.status = status
db_job.save()
db_segments = list(db_task.segment_set.prefetch_related('job_set').select_for_update().all())
db_jobs = [db_segment.job_set.first() for db_segment in db_segments]

if len(list(filter(lambda x: x.status == "annotation", db_jobs))) > 0:
db_task.status = "annotation"
elif len(list(filter(lambda x: x.status == "validation", db_jobs))) > 0:
db_task.status = "validation"
else:
db_task.status = "completed"

db_task.save()

def get_job(jid):
"""Get the job as dictionary of attributes"""
db_job = models.Job.objects.select_related("segment__task").get(id=jid)
Expand All @@ -205,7 +225,7 @@ def get_job(jid):
attributes[db_label.id][db_attrspec.id] = db_attrspec.text

response = {
"status": db_task.status.capitalize(),
"status": db_job.status,
"labels": { db_label.id:db_label.name for db_label in db_labels },
"stop": db_segment.stop_frame,
"taskid": db_task.id,
Expand Down
12 changes: 10 additions & 2 deletions cvat/apps/engine/templates/engine/annotation.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@
</table>
</div>

<center> <button id="closeSettignsButton" class="regular h1" style="margin-top: 15px;"> Close </button> </center>
<center>
<button id="closeSettignsButton" class="regular h1" style="margin-top: 15px;"> Close </button>
</center>
</div>
</div>

Expand All @@ -325,7 +327,13 @@
<div style="float:left; width: 70%; height: 100%; text-align: left;" class="selectable">
<center>
<label id="statTaskName" class="semiBold h2"> </label> <br>
<label id="statTaskStatus" class="regular h2"> </label>
<center>
<select id="statTaskStatus" class="regular h2" style="outline: none; border-radius: 10px; background:#B0C4DE; border: 1px solid black;">
<option value="annotation"> annotation </option>
<option value="validation"> validation </option>
<option value="completed"> completed </option>
</select>
</center>
</center>
<center>
<table style="width: 100%">
Expand Down
3 changes: 2 additions & 1 deletion cvat/apps/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
path('save/annotation/task/<int:tid>', views.save_annotation_for_task),
path('get/annotation/job/<int:jid>', views.get_annotation),
path('get/username', views.get_username),
path('save/exception/<int:jid>', views.catch_client_exception)
path('save/exception/<int:jid>', views.catch_client_exception),
path('save/job/status', views.save_job_status),
]
17 changes: 17 additions & 0 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ def save_annotation_for_task(request, tid):

return HttpResponse()

@login_required
@permission_required(perm=['engine.view_task', 'engine.change_task'], raise_exception=True)
def save_job_status(request):
try:
data = json.loads(request.body.decode('utf-8'))
jid = data['jid']
status = data['status']
slogger.job[jid].info("changing job status request")
task.save_job_status(jid, status, request.user.username)
except Exception as e:
if jid:
slogger.job[jid].error("cannot change status", exc_info=True)
else:
slogger.glob.error("cannot change status", exc_info=True)
return HttpResponseBadRequest(str(e))
return HttpResponse()

@login_required
def get_username(request):
response = {'username': request.user.username}
Expand Down