File size: 2,896 Bytes
2da7ed3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import uuid
from typing import List, Dict, Optional
from datetime import datetime
from pydantic import BaseModel, Field, PrivateAttr

import sys
# sys.path.append('/Users/benolojo/DCU/CA4/ca400_FinalYearProject/2024-ca400-olojob2-majdap2/src/backend/src/')

# from pydantic_mongo import ObjectIdField


''' Class for storing captions generated by SeamlessM4T'''
class UserCaptions(BaseModel):
    _id: uuid.UUID = PrivateAttr(default_factory=uuid.uuid4) # private attr not included in http calls
    author: str
    original_text: str
    translated_text: str
    timestamp: datetime = Field(default_factory=datetime.now)


'''Class for storing past call records from users'''
class UserCall(BaseModel):
    _id: uuid.UUID = PrivateAttr(default_factory=uuid.uuid4)
    call_id: Optional[str] = None
    caller_id: Optional[str] = None
    callee_id: Optional[str] = None
    creation_date: datetime = Field(default_factory=datetime.now, alias="date")
    duration: Optional[int] = None # milliseconds
    captions: Optional[List[UserCaptions]] = None
    # captions: List[Dict[str, str | float]]
    key_terms: Optional[List[str]] = None

    '''Implement validation check on transcript ID if in transcript records'''
        # @validator('transcript_id')
        # def check_transcript_id_transcripts_collection(cls,transcript_id):
        #    transcript_ids=['',''] # check transcript_ids in collection
        #    if transcript_id not in transcript_ids:
        #         raise ValueError(f'transcript ID must be in {transcript_ids}')
        #    return transcript_id
        
    class Config:
        populate_by_name = True
        json_schema_extra = {
            "example": {
                "call_id": "65eef930e9abd3b1e3506906",
                "caller_id": "65ede65b6d246e52aaba9d4f",
                "callee_id": "65edda944340ac84c1f00758",
                "duration": 360,
                "captions": [{"author": "shamzino", "original_text": "eng: This is original_text english text", "translated_text": "spa: este es el texto traducido al español", "timestamp": "2024-03-28T16:15:50.956055"},
                             {"author": "benjino", "original_text": "eng: This is source english text", "translated_text": "spa: este es el texto fuente al español",  "timestamp": "2024-03-28T16:16:20.34625"}],
                "key_terms": ["original_text", "source", "english", "text"]
            }
        }
 

''' Class for updating User Call record'''
class UpdateCall(BaseModel):
    call_id: Optional[str] = None
    caller_id: Optional[str] = None
    callee_id: Optional[str] = None
    duration: Optional[int] = None
    captions: Optional[List[UserCaptions]] = None
    key_terms: Optional[List[str]] = None

    class Config:
        populate_by_name = True
        json_schema_extra = {
            "example": {
                "duration": "500"
            }
        }