22from pydantic import BaseModel , field_validator , Field
33import json
44
5- class CreateCamera (BaseModel ):
6- title : str
7- source : str
8- image_width : int
9- image_height : int
10- calib : Any
11- latitude : float
12- longitude : float
5+ # class CreateCamera(BaseModel):
6+ # title: str
7+ # source: str
8+ # image_width: int
9+ # image_height: int
10+ # calib: Any
11+ # latitude: float
12+ # longitude: float
1313
14- @field_validator ('title' )
15- @classmethod
16- def validate_title (cls , title ):
17- if len (title ) < 1 or len (title ) > 200 :
18- raise ValueError (f"Invalid camera title: { title } " )
19- return title
14+ # @field_validator('title')
15+ # @classmethod
16+ # def validate_title(cls, title):
17+ # if len(title) < 1 or len(title) > 200:
18+ # raise ValueError(f"Invalid camera title: {title}")
19+ # return title
2020
21- @field_validator ('source' )
22- @classmethod
23- def validate_source (cls , source ):
24- return source
21+ # @field_validator('source')
22+ # @classmethod
23+ # def validate_source(cls, source):
24+ # return source
2525
26- @field_validator ('latitude' )
27- @classmethod
28- def validate_latitude (cls , latitude ):
29- if latitude > 90 or latitude < - 90 :
30- raise ValueError (f"Invalid latitude value: { latitude } " )
31- return latitude
26+ # @field_validator('latitude')
27+ # @classmethod
28+ # def validate_latitude(cls, latitude):
29+ # if latitude > 90 or latitude < -90:
30+ # raise ValueError(f"Invalid latitude value: {latitude}")
31+ # return latitude
3232
33- @field_validator ('longitude' )
34- @classmethod
35- def validate_longitude (cls , longitude ):
36- if longitude > 180 or longitude < - 180 :
37- raise ValueError (f"Invalid longitude value: { longitude } " )
38- return longitude
33+ # @field_validator('longitude')
34+ # @classmethod
35+ # def validate_longitude(cls, longitude):
36+ # if longitude > 180 or longitude < -180:
37+ # raise ValueError(f"Invalid longitude value: {longitude}")
38+ # return longitude
3939
40- @field_validator ('image_width' )
41- @classmethod
42- def validate_image_width (cls , image_width ):
43- if image_width <= 0 :
44- raise ValueError (f"Invalid image_width value: { image_width } " )
45- return image_width
40+ # @field_validator('image_width')
41+ # @classmethod
42+ # def validate_image_width(cls, image_width):
43+ # if image_width <= 0:
44+ # raise ValueError(f"Invalid image_width value: {image_width}")
45+ # return image_width
4646
47- @field_validator ('image_height' )
48- @classmethod
49- def validate_image_height (cls , image_height ):
50- if image_height <= 0 :
51- raise ValueError (f"Invalid image_height value: { image_height } " )
52- return image_height
47+ # @field_validator('image_height')
48+ # @classmethod
49+ # def validate_image_height(cls, image_height):
50+ # if image_height <= 0:
51+ # raise ValueError(f"Invalid image_height value: {image_height}")
52+ # return image_height
5353
54+ # @field_validator('calib')
55+ # @classmethod
56+ # def validate_calib(cls, calib):
57+ # if calib is not None:
58+ # try:
59+ # json.dumps(calib)
60+ # except:
61+ # raise ValueError(f"Invalid calibration data")
62+ # return calib
63+
64+ class CameraBase (BaseModel ):
65+ title : Optional [str ] = Field (None , min_length = 3 , max_length = 120 )
66+ source : Optional [str ] = Field (None , max_length = 250 )
67+ image_width : Optional [int ] = Field (None , gt = 0 )
68+ image_height : Optional [int ] = Field (None , gt = 0 )
69+ calib : Any
70+ latitude : Optional [float ] = Field (None , ge = - 90 , le = 90 )
71+ longitude : Optional [float ] = Field (None , ge = - 180 , le = 180 )
72+
5473 @field_validator ('calib' )
5574 @classmethod
5675 def validate_calib (cls , calib ):
@@ -60,6 +79,15 @@ def validate_calib(cls, calib):
6079 except :
6180 raise ValueError (f"Invalid calibration data" )
6281 return calib
82+
83+ class CreateCamera (CameraBase ):
84+ title : str = Field (min_length = 3 , max_length = 120 )
85+ source : str = Field (max_length = 250 )
86+ image_width : int = Field (gt = 0 )
87+ image_height : int = Field (gt = 0 )
88+ calib : Any
89+ latitude : float = Field (ge = - 90 , le = 90 )
90+ longitude : float = Field (ge = - 180 , le = 180 )
6391
6492class Point (BaseModel ):
6593 latitude : float = Field (ge = - 90 , le = 90 )
0 commit comments