def find(idx: int) -> 'ImagesModel': with connection.cursor() as cursor: cursor.execute( 'SELECT * FROM `images` WHERE `idx` = %s', [idx], ) result = cursor.fetchone() try: idx: int = result['idx'] front_image_key: str = result['front_image_key'] side_image_key: str = result['side_image_key'] face_masked = result['face_masked'] front_image_width = result['front_image_width'] front_image_height = result['front_image_height'] side_image_width = result['side_image_width'] side_image_height = result['side_image_height'] except KeyError as e: raise UnknownException('KeyError', e) if not isinstance(idx, int): raise UnknownException('F**k') if not isinstance(front_image_key, str): raise UnknownException('F**k') if not isinstance(side_image_key, str): raise UnknownException('F**k') if not isinstance(face_masked, int): raise UnknownException('F**k') if not isinstance(front_image_width, float) and front_image_width is not None: raise UnknownException('F**k') if not isinstance(front_image_height, float) and front_image_height is not None: raise UnknownException('F**k') if not isinstance(side_image_width, float) and side_image_width is not None: raise UnknownException('F**k') if not isinstance(side_image_height, float) and side_image_height is not None: raise UnknownException('F**k') return ImagesModel( idx=idx, front_image_key=front_image_key, side_image_key=side_image_key, face_masked=face_masked, front_image_width=front_image_width, front_image_height=front_image_height, side_image_width=side_image_width, side_image_height=side_image_height, )
def save_error(self, error: ErrorModel): self.error = error with connection.cursor() as cursor: cursor.execute( "UPDATE `keypoints_tasks` SET `state` = %s, `error_code` = %s, `error_message` = %s WHERE `idx` = %s", [TaskState.ERROR.name, error.code, error.message, self.idx]) connection.commit() return self
def save_result(self, keypoints: KeypointsModel): self.keypoints_idx = keypoints.idx with connection.cursor() as cursor: cursor.execute( "UPDATE `keypoints_tasks` SET `state` = %s, `keypoints_idx` = %s WHERE `idx` = %s", [TaskState.SUCCESS.name, keypoints.idx, self.idx]) connection.commit() return self
def find(idx: int) -> 'KeypointsTaskModel': with connection.cursor() as cursor: cursor.execute( 'SELECT * FROM `keypoints_tasks` WHERE `idx` = %s', [idx], ) result = cursor.fetchone() idx: int = result['idx'] user_idx: int = result['user_idx'] images_idx: int = result['images_idx'] state_str: str = result['state'] keypoints_idx: Optional[int] = result['keypoints_idx'] error_code: Optional[str] = result['error_code'] error_message: Optional[str] = result['error_message'] if not isinstance(idx, int): raise UnknownException('F**k') if not isinstance(user_idx, int): raise UnknownException('F**k') if not isinstance(images_idx, int): raise UnknownException('F**k') if not isinstance(state_str, str): raise UnknownException('F**k') if not isinstance(keypoints_idx, int) and keypoints_idx is not None: raise UnknownException('F**k') if not isinstance(error_code, str) and error_code is not None: raise UnknownException('F**k') if not isinstance(error_message, str) and error_message is not None: raise UnknownException('F**k') if state_str not in TaskState.__members__: raise UnknownException('F**k: State is invalid') state: TaskState = TaskState(state_str) return KeypointsTaskModel( idx=idx, user_idx=user_idx, images_idx=images_idx, state=state, keypoints_idx=keypoints_idx, error_code=error_code, error_message=error_message, )
def save_result(self, bodysizes: BodysizesModel): self.bodysizes_idx = bodysizes.idx with connection.cursor() as cursor: cursor.execute( "UPDATE `bodysizes_tasks` SET `state` = %s, `bodysizes_idx` = %s WHERE `idx` = %s", [TaskState.SUCCESS.name, bodysizes.idx, self.idx]) connection.commit() return self
def create( neck_width: float, neck_girth: float, shoulder_width: float, chest_width: float, chest_girth: float, waist_width: float, waist_girth: float, hip_width: float, hip_girth: float, thigh_width: float, thigh_girth: float, calf_width: float, calf_girth: float, arm_width: float, arm_girth: float, sleeve_length: float, long_sleeve_length: float, outseam: float, inseam: float, cervical_height: float, torso_length: float, rise_length: float, ) -> 'BodysizesModel': with connection.cursor() as cursor: cursor.execute( 'INSERT INTO `bodysizes` (' ' `neck_width`,' ' `neck_girth`,' ' `shoulder_width`,' ' `chest_width`,' ' `chest_girth`,' ' `waist_width`,' ' `waist_girth`,' ' `hip_width`,' ' `hip_girth`,' ' `thigh_width`,' ' `thigh_girth`,' ' `calf_width`,' ' `calf_girth`,' ' `arm_width`,' ' `arm_girth`,' ' `sleeve_length`,' ' `long_sleeve_length`,' ' `outseam`,' ' `inseam`,' ' `cervical_height`,' ' `torso_length`,' ' `rise_length`' ') VALUES (' ' %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' ')', [ neck_width, neck_girth, shoulder_width, chest_width, chest_girth, waist_width, waist_girth, hip_width, hip_girth, thigh_width, thigh_girth, calf_width, calf_girth, arm_width, arm_girth, sleeve_length, long_sleeve_length, outseam, inseam, cervical_height, torso_length, rise_length, ]) idx = cursor.lastrowid connection.commit() return BodysizesModel( idx=idx, neck_width=neck_width, neck_girth=neck_girth, shoulder_width=shoulder_width, chest_width=chest_width, chest_girth=chest_girth, waist_width=waist_width, waist_girth=waist_girth, hip_width=hip_width, hip_girth=hip_girth, thigh_width=thigh_width, thigh_girth=thigh_girth, calf_width=calf_width, calf_girth=calf_girth, arm_width=arm_width, arm_girth=arm_girth, sleeve_length=sleeve_length, long_sleeve_length=long_sleeve_length, outseam=outseam, inseam=inseam, cervical_height=cervical_height, torso_length=torso_length, rise_length=rise_length, )
def find(idx: int) -> 'BodysizesModel': with connection.cursor() as cursor: cursor.execute( 'SELECT * FROM `bodysizes` WHERE `idx` = %s', [idx], ) result = cursor.fetchone() if 'idx' not in result: raise UnknownException('F**k') idx: int = result['idx'] if not isinstance(idx, int): raise UnknownException('F**k') for bodysizes_name in bodysizes_names: if bodysizes_name not in result: raise UnknownException('F**k') bodysize = result['bodysizes_name'] if not isinstance(bodysize, float): raise UnknownException('F**k') neck_width: float = result['neck_width'] neck_girth: float = result['neck_girth'] shoulder_width: float = result['shoulder_width'] chest_width: float = result['chest_width'] chest_girth: float = result['chest_girth'] waist_width: float = result['waist_width'] waist_girth: float = result['waist_girth'] hip_width: float = result['hip_width'] hip_girth: float = result['hip_girth'] thigh_width: float = result['thigh_width'] thigh_girth: float = result['thigh_girth'] calf_width: float = result['calf_width'] calf_girth: float = result['calf_girth'] arm_width: float = result['arm_width'] arm_girth: float = result['arm_girth'] sleeve_length: float = result['sleeve_length'] long_sleeve_length: float = result['long_sleeve_length'] outseam: float = result['outseam'] inseam: float = result['inseam'] cervical_height: float = result['cervical_height'] torso_length: float = result['torso_length'] rise_length: float = result['rise_length'] return BodysizesModel( idx=idx, neck_width=neck_width, neck_girth=neck_girth, shoulder_width=shoulder_width, chest_width=chest_width, chest_girth=chest_girth, waist_width=waist_width, waist_girth=waist_girth, hip_width=hip_width, hip_girth=hip_girth, thigh_width=thigh_width, thigh_girth=thigh_girth, calf_width=calf_width, calf_girth=calf_girth, arm_width=arm_width, arm_girth=arm_girth, sleeve_length=sleeve_length, long_sleeve_length=long_sleeve_length, outseam=outseam, inseam=inseam, cervical_height=cervical_height, torso_length=torso_length, rise_length=rise_length, )