@@ -123,69 +123,64 @@ def from_common(cls, rectangle: Rectangle,
123123
124124class NDFrameRectangle (BaseModel ):
125125 frame : int
126- # bbox: Bbox
126+ bbox : Bbox
127+
128+ #make a new class that has Frame as the base and then inherit from it
129+
130+ @classmethod
131+ def from_common (cls , frame : int , rectangle : Rectangle ):
132+ return cls (frame = frame ,
133+ bbox = Bbox (top = rectangle .start .y ,
134+ left = rectangle .start .x ,
135+ height = rectangle .end .y - rectangle .start .y ,
136+ width = rectangle .end .x - rectangle .start .x ))
127137
128138
129139class NDSegment (BaseModel ):
130140 keyframes : List [NDFrameRectangle ]
131141
142+ @staticmethod
143+ #lets make NDFrameObject as a method to call on similar to the other one
144+
145+ @classmethod
146+ def from_common (cls , segment ):
147+ NDFrameObject = {
148+ Rectangle : NDFrameRectangle
149+ }.get (type (segment [0 ].value ))
150+
151+ # for a in segment:
152+ # print("\nHELLO", a)
153+ b = cls (keyframes = [
154+ NDFrameObject .from_common (object_annotation .frame ,
155+ object_annotation .value )
156+ for object_annotation in segment
157+ ])
158+ # print("\n\n B AS DICT IS", b.dict(by_alias=True))
159+ return b
160+
132161
133162class NDSegments (NDBaseObject ):
134163 segments : List [NDSegment ]
135164
136- # uuid: str
137- # schema_id: str
138-
139- # def process_segment(self, segment: List[VideoObjectAnnotation]):
140- # """
141- # We only care about the annotation.value and frame once we make it here
142- # """
143- # # for annotation in segment:
144- # return [{
145- # "frame":
146- # annotation.frame,
147- # "bbox":
148- # Bbox(top=annotation.value.start.y,
149- # left=annotation.value.start.x,
150- # height=annotation.value.end.y - annotation.value.start.y,
151- # width=annotation.value.end.x - annotation.value.start.x)
152- # } for annotation in segment]
153-
154165 def to_common (self ):
155166 pass
156167
157168 @classmethod
158169 def from_common (cls , segments : List [VideoObjectAnnotation ], data : VideoData ,
159170 feature_schema_id : Cuid , extra : Dict [str ,
160171 Any ]) -> "NDSegments" :
161- # print(f"\nWE MADE IT HERE TO SEGMENTS\n")
162- # for segment in segments:
163- # print("\nSEGMENT\n", segment)
164- # processed_segment = cls.process_segment(cls, segment)
165-
166- # segments = [{
167- # "keyframes": [{
168- # "frame": 3,
169- # "bbox": Bbox(top=0, left=0, height=1, width=1)
170- # }]
171- # }, {
172- # "keyframes": [{
173- # "frame": 5,
174- # "bbox": Bbox(top=0, left=0, height=3, width=5)
175- # }]
176- # }]
177-
178- segments = [{"keyframes" : segment } for segment in segments ]
179-
180- print ("before class instantiatino\n " , segments [0 ],
181- "\n before class instantiatino" )
172+
173+ segments = [NDSegment .from_common (segment ) for segment in segments ]
174+
175+ # print("\nbefore class instantiation\n", segments,
176+ # "\nbefore class instantiation\n")
182177
183178 a = cls (segments = segments ,
184179 dataRow = DataRow (id = data .uid ),
185180 schema_id = feature_schema_id ,
186181 uuid = extra .get ('uuid' ))
187- print ("\n I am from_common ndsegments" , a ,
188- "\n I am from_common ndsegments\n " )
182+ # print("\nI am from_common ndsegments", a,
183+ # "\nI am from_common ndsegments\n")
189184 return a
190185
191186
0 commit comments