diff --git a/backend/django/core/migrations/0080_irrlog_time_to_label.py b/backend/django/core/migrations/0080_irrlog_time_to_label.py new file mode 100644 index 00000000..2e30ddcf --- /dev/null +++ b/backend/django/core/migrations/0080_irrlog_time_to_label.py @@ -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), + ), + ] diff --git a/backend/django/core/models.py b/backend/django/core/models.py index fb187cfa..1121559a 100644 --- a/backend/django/core/models.py +++ b/backend/django/core/models.py @@ -293,6 +293,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): diff --git a/backend/django/core/utils/utils_annotate.py b/backend/django/core/utils/utils_annotate.py index 70266866..8a80f343 100644 --- a/backend/django/core/utils/utils_annotate.py +++ b/backend/django/core/utils/utils_annotate.py @@ -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 @@ -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: @@ -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(): diff --git a/backend/django/core/views/api.py b/backend/django/core/views/api.py index 0a5acc43..755bd8d3 100644 --- a/backend/django/core/views/api.py +++ b/backend/django/core/views/api.py @@ -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" @@ -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.upload_id, + log.data.text, + label_name, + log.profile.user, + log.timestamp, + log.time_to_label, + ] ) return response diff --git a/backend/django/core/views/api_annotate.py b/backend/django/core/views/api_annotate.py index 98de28d6..d5b7d785 100644 --- a/backend/django/core/views/api_annotate.py +++ b/backend/django/core/views/api_annotate.py @@ -344,7 +344,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 @@ -410,7 +414,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() @@ -631,7 +639,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