File size: 1,710 Bytes
161d75f
f1a6252
a725af0
 
 
 
 
161d75f
 
f1a6252
161d75f
995b526
f1a6252
161d75f
 
 
f1a6252
161d75f
3ae828c
f1a6252
 
a725af0
161d75f
f1a6252
161d75f
a725af0
f1a6252
a725af0
161d75f
f1a6252
a725af0
f1a6252
 
a725af0
 
 
 
 
 
 
 
f1a6252
a725af0
f1a6252
 
161d75f
a725af0
 
86d2f2e
161d75f
ce5e1a3
 
 
a725af0
f1a6252
a725af0
f1a6252
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
from pydantic import BaseModel, Field
from typing import Optional, Union
import numpy as np
from PIL import Image
import io
import base64
import uuid

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


class Wounded(BaseModel):
    circumstances: Circumstances
    behaviors: Union[Behaviors, BehaviorsSimple]
    physical_anomalies: Union[PhysicalAnomalies, PhysicalAnomaliesSimple]
    follow_up_events: FollowUpEvents


class Dead(BaseModel):
    circumstances: Circumstances
    physical_anomalies: Union[PhysicalAnomalies, PhysicalAnomaliesSimple]
    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
    image_md5: str
    geolocalisation: Geolocalisation
    specie: Optional[str]
    number: Optional[int]
    comments: Optional[str]
    wounded_state: str
    wounded: Optional[Wounded] = None
    dead_state: str
    dead: Optional[Dead] = None