Skip to content

Commit

Permalink
add time to label to irr log
Browse files Browse the repository at this point in the history
  • Loading branch information
AstridKery committed Sep 4, 2024
1 parent e457b8d commit 2281106
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
18 changes: 18 additions & 0 deletions backend/django/core/migrations/0080_irrlog_time_to_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-09-04 21:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0079_rename_name_category_field_name_and_more"),
]

operations = [
migrations.AddField(
model_name="irrlog",
name="time_to_label",
field=models.IntegerField(default=None, null=True),
),
]
1 change: 1 addition & 0 deletions backend/django/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class Meta:
profile = models.ForeignKey("Profile", on_delete=models.CASCADE)
label = models.ForeignKey("Label", null=True, on_delete=models.CASCADE)
timestamp = models.DateTimeField(null=True, default=None)
time_to_label = models.IntegerField(null=True, default=None)


class DataLabel(models.Model):
Expand Down
20 changes: 17 additions & 3 deletions backend/django/core/utils/utils_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ def skip_data(datum, profile):
project = datum.project

IRRLog.objects.create(
data=datum, profile=profile, label=None, timestamp=timezone.now()
data=datum,
profile=profile,
label=None,
timestamp=timezone.now(),
time_to_label=None,
)
num_history = IRRLog.objects.filter(data=datum).count()
# if the datum is irr or processed irr, dont add to admin queue yet
Expand Down Expand Up @@ -195,7 +199,11 @@ def label_data(label, datum, profile, time):
# already processed so just add this label to the history.
if num_history >= datum.project.num_users_irr:
IRRLog.objects.create(
data=datum, profile=profile, label=label, timestamp=timezone.now()
data=datum,
profile=profile,
label=label,
timestamp=timezone.now(),
time_to_label=time,
)
DataLabel.objects.get(data=datum, profile=profile).delete()
else:
Expand All @@ -220,7 +228,13 @@ def process_irr_label(data, label):
if (labeled.count() + skipped.count()) >= project.num_users_irr:
# add all labels to IRRLog
history_list = [
IRRLog(data=data, profile=d.profile, label=d.label, timestamp=d.timestamp)
IRRLog(
data=data,
profile=d.profile,
label=d.label,
timestamp=d.timestamp,
time_to_label=d.time_to_label,
)
for d in labeled
]
with transaction.atomic():
Expand Down
11 changes: 9 additions & 2 deletions backend/django/core/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def download_irr_log(request, project_pk):
)

writer = csv.writer(response)
writer.writerow(["id", "text", "label", "username", "timestamp"])
writer.writerow(["id", "text", "label", "username", "timestamp", "time_to_label"])

logs = IRRLog.objects.filter(data__project_id=project_pk).select_related(
"data", "profile", "label"
Expand All @@ -156,7 +156,14 @@ def download_irr_log(request, project_pk):
for log in logs:
label_name = log.label.name if log.label else ""
writer.writerow(
[log.data.pk, log.data.text, label_name, log.profile.user, log.timestamp]
[
log.data.pk,
log.data.text,
label_name,
log.profile.user,
log.timestamp,
log.time_to_label,
]
)

return response
Expand Down
19 changes: 16 additions & 3 deletions backend/django/core/views/api_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ def skip_data(request, data_pk):

# log the data and check IRR but don't put in admin queue yet
IRRLog.objects.create(
data=data, profile=profile, label=None, timestamp=timezone.now()
data=data,
profile=profile,
label=None,
timestamp=timezone.now(),
time_to_label=None,
)
# if the IRR history has more than the needed number of labels , it is
# already processed so don't do anything else
Expand Down Expand Up @@ -393,7 +397,11 @@ def annotate_data(request, data_pk):
# if the IRR history has more than the needed number of labels , it is
# already processed so just add this label to the history.
IRRLog.objects.create(
data=data, profile=profile, label=label, timestamp=timezone.now()
data=data,
profile=profile,
label=label,
timestamp=timezone.now(),
time_to_label=labeling_time,
)
assignment = AssignedData.objects.get(data=data, profile=profile)
assignment.delete()
Expand Down Expand Up @@ -614,7 +622,11 @@ def modify_label_to_skip(request, data_pk):
# if it was irr, add it to the log
if len(IRRLog.objects.filter(data=data, profile=profile)) == 0:
IRRLog.objects.create(
data=data, profile=profile, label=None, timestamp=timezone.now()
data=data,
profile=profile,
label=None,
timestamp=timezone.now(),
time_to_label=None,
)
else:
# if it's not irr, add it to the admin queue immediately
Expand Down Expand Up @@ -720,6 +732,7 @@ def data_unlabeled_table(request, project_pk):
]
return Response({"data": data})


@api_view(["POST"])
@permission_classes([AllowAny])
def embeddings_calculations(request):
Expand Down

0 comments on commit 2281106

Please sign in to comment.