sbt-idp/cope2n-api/fwd_api/models/SubscriptionRequest.py

49 lines
2.4 KiB
Python
Executable File

from django.db import models
from django.utils import timezone
from django.contrib.postgres.indexes import GinIndex
from fwd_api.models.Subscription import Subscription
class SubscriptionRequest(models.Model):
id = models.AutoField(primary_key=True)
pages: int = models.IntegerField()
pages_left: int = models.IntegerField(default=1)
doc_type: str = models.CharField(max_length=100, db_index=True)
request_id = models.CharField(max_length=200, db_index=True) # Change to request_id
redemption_id = models.CharField(max_length=200, null=True)
process_type = models.CharField(max_length=200) # driver/id/invoice
provider_code = models.CharField(max_length=200, default="Guest") # Request source FWD/CTel
predict_result = models.JSONField(null=True)
feedback_result = models.JSONField(null=True)
reviewed_result = models.JSONField(null=True)
status = models.IntegerField() # 1: Processing(Pending) 2: PredictCompleted 3: ReturnCompleted
subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE)
created_at = models.DateTimeField(default=timezone.now, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
is_test_request = models.BooleanField(default=False)
S3_uploaded = models.BooleanField(default=False)
feedback_accuracy = models.JSONField(null=True)
reviewed_accuracy = models.JSONField(null=True)
raw_accuracy = models.FloatField(default=None, null=True)
ai_inference_profile = models.JSONField(null=True)
preprocessing_time = models.FloatField(default=-1)
client_request_time = models.FloatField(default=-1)
ai_inference_start_time = models.FloatField(default=0)
ai_inference_time = models.FloatField(default=0)
cpu_percent = models.FloatField(default=-1)
gpu_percent = models.FloatField(default=-1)
used_memory = models.FloatField(default=-1)
total_memory = models.FloatField(default=-1)
gpu_stats = models.CharField(max_length=100, null=True)
is_reviewed = models.BooleanField(default=False)
is_required = models.BooleanField(default=True)
subsidiary = models.CharField(default="", null=True, max_length=200)
class Meta:
indexes = [
GinIndex(fields=['predict_result'], name='idx_gin_rq_predict_result'),
GinIndex(fields=['feedback_result'], name='idx_gin_rq_feedback_result'),
GinIndex(fields=['reviewed_result'], name='idx_gin_rq_reviewed_result'),
]