Browse Source

Merge pull request #1432 from zanussbaum/master

Fixing Data Annotation Issues
pull/1520/head
Hiroki Nakayama 3 years ago
committed by GitHub
parent
commit
b2b87e4135
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions
  1. 16
      backend/api/models.py
  2. 6
      backend/api/tasks.py

16
backend/api/models.py

@ -1,6 +1,8 @@
import string
from typing import Literal
from django import db
from auto_labeling_pipeline.models import RequestModelFactory
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
@ -92,7 +94,7 @@ class ImageClassificationProject(Project):
class Label(models.Model):
text = models.CharField(max_length=100)
text = models.CharField(max_length=100, db_index=True)
prefix_key = models.CharField(
max_length=10,
blank=True,
@ -118,7 +120,7 @@ class Label(models.Model):
)
background_color = models.CharField(max_length=7, default='#209cee')
text_color = models.CharField(max_length=7, default='#ffffff')
created_at = models.DateTimeField(auto_now_add=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
@ -143,6 +145,7 @@ class Label(models.Model):
unique_together = (
('project', 'text'),
)
ordering = ['created_at']
class Example(models.Model):
@ -160,13 +163,16 @@ class Example(models.Model):
blank=True
)
text = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
@property
def comment_count(self):
return Comment.objects.filter(example=self.id).count()
class Meta:
ordering = ['created_at']
class ExampleState(models.Model):
example = models.ForeignKey(
@ -196,7 +202,7 @@ class Comment(models.Model):
on_delete=models.CASCADE,
null=True
)
created_at = models.DateTimeField(auto_now_add=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
@property
@ -204,7 +210,7 @@ class Comment(models.Model):
return self.user.username
class Meta:
ordering = ('-created_at', )
ordering = ['created_at']
class Tag(models.Model):

6
backend/api/tasks.py

@ -1,7 +1,8 @@
import datetime
import itertools
from celery import shared_task
from celery import shared_task
from celery.utils.log import get_task_logger
from django.conf import settings
from django.contrib.auth import get_user_model
from django.shortcuts import get_object_or_404
@ -14,7 +15,7 @@ from .views.upload.factory import (get_data_class, get_dataset_class,
get_label_class)
from .views.upload.utils import append_field
logger = get_task_logger(__name__)
class Buffer:
def __init__(self, buffer_size=settings.IMPORT_BATCH_SIZE):
@ -120,6 +121,7 @@ def injest_data(user_id, project_id, filenames, format: str, **kwargs):
factory.create(buffer.data, user, project)
buffer.clear()
if not buffer.is_empty():
logger.debug(f'BUFFER LEN {len(buffer)}')
factory.create(buffer.data, user, project)
buffer.clear()

Loading…
Cancel
Save