2023-11-30 11:19:06 +00:00
|
|
|
from django.db import models
|
2024-11-28 09:45:06 +00:00
|
|
|
from django.contrib.postgres.indexes import GinIndex
|
2023-11-30 11:19:06 +00:00
|
|
|
from fwd_api.constant.common import FileCategory
|
|
|
|
from fwd_api.models import SubscriptionRequest
|
|
|
|
from fwd_api.models.fields.EncryptedCharField import EncryptedCharField
|
|
|
|
from django.utils import timezone
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
class SubscriptionRequestFile(models.Model):
|
2023-12-14 03:54:03 +00:00
|
|
|
def gen_random_code():
|
|
|
|
return f"FIL{uuid.uuid4().hex}"
|
|
|
|
|
|
|
|
code = models.CharField(max_length=300, default=gen_random_code)
|
2024-01-17 09:28:50 +00:00
|
|
|
origin_name = models.CharField(max_length=300, default="")
|
2023-11-30 11:19:06 +00:00
|
|
|
file_name = models.CharField(max_length=300, default=None)
|
|
|
|
file_path = EncryptedCharField(max_length=500, default=None)
|
|
|
|
file_category = models.CharField(max_length=200, default=FileCategory.Origin.value)
|
|
|
|
request = models.ForeignKey(SubscriptionRequest, related_name="files", on_delete=models.CASCADE)
|
2024-01-17 09:28:50 +00:00
|
|
|
created_at = models.DateTimeField(default=timezone.now, db_index=True)
|
2023-11-30 11:19:06 +00:00
|
|
|
updated_at = models.DateTimeField(auto_now=True)
|
2024-01-17 09:28:50 +00:00
|
|
|
is_bad_image_quality = models.BooleanField(default=False)
|
2024-01-31 03:00:18 +00:00
|
|
|
doc_type = models.CharField(max_length=10, default="")
|
|
|
|
index_in_request = models.IntegerField(default=0) # by doc_type
|
|
|
|
processing_time = models.FloatField(default=-1) # in milisecond
|
2024-12-05 08:04:13 +00:00
|
|
|
reason = models.TextField(blank=True, db_index=True)
|
2024-01-24 07:14:33 +00:00
|
|
|
counter_measures = models.TextField(blank=True)
|
2024-05-17 12:39:31 +00:00
|
|
|
is_reviewed = models.BooleanField(default=False)
|
|
|
|
is_required = models.BooleanField(default=True)
|
2024-03-29 11:34:02 +00:00
|
|
|
# subsidiary = models.CharField(default="", null=True, max_length=200) # save already in SubscriptionRequest
|
2024-01-31 03:00:18 +00:00
|
|
|
|
|
|
|
predict_result = models.JSONField(null=True)
|
|
|
|
feedback_result = models.JSONField(null=True)
|
|
|
|
reviewed_result = models.JSONField(null=True)
|
|
|
|
|
|
|
|
feedback_accuracy = models.JSONField(null=True)
|
2024-02-18 14:52:23 +00:00
|
|
|
reviewed_accuracy = models.JSONField(null=True)
|
2024-11-04 07:11:09 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
indexes = [
|
|
|
|
models.Index(fields=['request', 'index_in_request', 'doc_type']), # For updating results
|
|
|
|
models.Index(fields=['request', 'file_name']), # for getting image files by AI
|
2024-11-28 09:45:06 +00:00
|
|
|
GinIndex(fields=['predict_result'], name='idx_gin_predict_result'),
|
|
|
|
GinIndex(fields=['feedback_result'], name='idx_gin_feedback_result'),
|
|
|
|
GinIndex(fields=['reviewed_result'], name='idx_gin_reviewed_result'),
|
2024-11-04 07:11:09 +00:00
|
|
|
]
|
|
|
|
|