File size: 1,394 Bytes
20bdfba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pydantic import BaseModel, Field
from typing import Optional
import numpy as np
from PIL import Image
import io
import base64
import uuid

from behavior.class_behavior import Behaviors
from circumstances.class_circumstance import Circumstances
from physical.class_physical import PhysicalAnomalies
from follow_up.class_follow_up import FollowUpEvents
from geolocalisation.class_geolocalisation import Geolocalisation

class Wounded(BaseModel):
    circumstances: Circumstances
    behaviors: Behaviors
    physical_anomalies: PhysicalAnomalies
    follow_up_events: FollowUpEvents

class Dead(BaseModel):
    circumstances: Circumstances
    physical_anomalies: PhysicalAnomalies
    follow_up_events: FollowUpEvents

class ImageBase64(BaseModel):
    image: str  
    @classmethod
    def to_base64(cls, pixel_data: list):
        img_array = np.array(pixel_data, dtype=np.uint8)
        img = Image.fromarray(img_array)
        # Save the image to a bytes buffer
        buffer = io.BytesIO()
        img.save(buffer, format="PNG")
        buffer.seek(0)
        base64_str = base64.b64encode(buffer.read()).decode('utf-8')
        return cls(image=base64_str)
    
class Report(BaseModel):
    identifier: str
    image: ImageBase64
    geolocalisation: Geolocalisation
    wounded_state: str
    wounded: Optional[Wounded] = None  
    dead_state: str
    dead: Optional[Dead] = None