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

Dev fix history unlabeled #318

Merged
merged 7 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions backend/django/core/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,25 +773,25 @@ def get_unlabelled_data_objs(project_id: int) -> int:
WHERE cd.project_id = %s AND cdl.label_id IS NULL
),
queue_ids AS (
SELECT cdq.id
SELECT cdq.id, cdq.data_id
FROM core_dataqueue cdq
LEFT JOIN core_queue cq ON cdq.queue_id = cq.id
WHERE cq.project_id = %s AND cq.type = 'admin'
),
irr_log_ids AS (
SELECT ci.id
SELECT ci.id, ci.data_id
FROM core_irrlog ci
LEFT JOIN core_data cd ON ci.data_id = cd.id
WHERE cd.project_id = %s
),
assigned_ids AS (
SELECT ca.id
SELECT ca.id, ca.data_id
FROM core_assigneddata ca
LEFT JOIN core_data cd ON ca.data_id = cd.id
WHERE cd.project_id = %s
),
recycle_ids AS (
SELECT cr.id
SELECT cr.id, cr.data_id
FROM core_recyclebin cr
LEFT JOIN core_data cd ON cr.data_id = cd.id
WHERE cd.project_id = %s
Expand All @@ -800,10 +800,10 @@ def get_unlabelled_data_objs(project_id: int) -> int:
FROM (
SELECT p.id
FROM project_ids p
LEFT JOIN queue_ids q ON p.id = q.id
LEFT JOIN irr_log_ids irr ON p.id = irr.id
LEFT JOIN assigned_ids a ON p.id = a.id
LEFT JOIN recycle_ids r ON p.id = r.id
LEFT JOIN queue_ids q ON p.id = q.data_id
LEFT JOIN irr_log_ids irr ON p.id = irr.data_id
LEFT JOIN assigned_ids a ON p.id = a.data_id
LEFT JOIN recycle_ids r ON p.id = r.data_id
WHERE q.id IS NULL
AND irr.id IS NULL
AND a.id IS NULL
Expand Down
14 changes: 11 additions & 3 deletions backend/django/core/utils/utils_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,23 @@ def process_irr_label(data, label):
def get_unlabeled_data(project_pk):
project = Project.objects.get(pk=project_pk)

stuff_in_queue = DataQueue.objects.filter(queue__project=project)
queued_ids = [queued.data.id for queued in stuff_in_queue]
stuff_in_queue = DataQueue.objects.filter(
queue__project=project, queue__type="admin"
)
in_admin_queue_ids = [queued.data.id for queued in stuff_in_queue]

recycle_ids = RecycleBin.objects.filter(data__project=project).values_list(
"data__pk", flat=True
)

assigned_ids = AssignedData.objects.filter(data__project=project).values_list(
"data__pk", flat=True
)

unlabeled_data = (
project.data_set.filter(datalabel__isnull=True)
.exclude(id__in=queued_ids)
.exclude(id__in=in_admin_queue_ids)
.exclude(id__in=assigned_ids)
.exclude(id__in=recycle_ids)
.exclude(irr_ind=True)
)
Expand Down
22 changes: 22 additions & 0 deletions backend/django/core/views/api_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def modify_label(request, data_pk):
profile = request.user.profile
response = {}
project = data.project
normal_queue = Queue.objects.get(project=project, type="normal")

label = Label.objects.get(pk=request.data["labelID"])

Expand All @@ -468,6 +469,9 @@ def modify_label(request, data_pk):
and not DataLabel.objects.filter(data=data).exists()
):
current_training_set = project.get_current_training_set()
data_in_normal_queue = DataQueue.objects.filter(
data=data, queue=normal_queue
).exists()
with transaction.atomic():
DataLabel.objects.create(
data=data,
Expand All @@ -478,6 +482,14 @@ def modify_label(request, data_pk):
training_set=current_training_set,
pre_loaded=False,
)
if data_in_normal_queue:
DataQueue.objects.get(data=data, queue=normal_queue).delete()

if data_in_normal_queue:
settings.REDIS.srem(
redis_serialize_set(normal_queue), redis_serialize_data(data)
)

elif "oldLabelID" in request.data:
old_label = Label.objects.get(pk=request.data["oldLabelID"])
with transaction.atomic():
Expand Down Expand Up @@ -842,6 +854,7 @@ def label_skew_label(request, data_pk):
label = Label.objects.get(pk=request.data["labelID"])
profile = request.user.profile
update_last_action(project, profile)
normal_queue = Queue.objects.get(project=project, type="normal")
response = {}

# check if they have the admin lock still.
Expand All @@ -857,6 +870,9 @@ def label_skew_label(request, data_pk):

current_training_set = project.get_current_training_set()
if project_extras.proj_permission_level(datum.project, profile) >= 2:
data_in_normal_queue = DataQueue.objects.filter(
data=datum, queue=normal_queue
).exists()
with transaction.atomic():
dl = DataLabel.objects.create(
data=datum,
Expand All @@ -866,9 +882,15 @@ def label_skew_label(request, data_pk):
time_to_label=None,
timestamp=timezone.now(),
)
if data_in_normal_queue:
DataQueue.objects.get(data=datum, queue=normal_queue).delete()
VerifiedDataLabel.objects.create(
data_label=dl, verified_timestamp=timezone.now(), verified_by=profile
)
if data_in_normal_queue:
settings.REDIS.srem(
redis_serialize_set(normal_queue), redis_serialize_data(datum)
)

else:
response["error"] = "Invalid permission. Must be an admin."
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/History/HistoryTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const HistoryTable = () => {
<p>
Toggle the checkbox below to show/hide unlabeled data:
</p>
<i>NOTE: Data assigned to someone in the Annotate Data tab will not be returned. Admin can go to the Unassign Coder tab on the Admin page to un-assign data from individual coders.</i>
<Form.Label className="d-flex m-0 p-0">
<Form.Check
className="p-0"
Expand Down
Loading