Esempio n. 1
0
class MusicObject(sql_object.Model, BaseObject):

    __tablename__ = 'MusicObject'

    id = sql_object.Column(sql_object.String(32), primary_key=True)

    name = sql_object.Column(sql_object.String(128),
                             unique=False,
                             nullable=False)

    singer = sql_object.Column(sql_object.String(128),
                               nullable=True,
                               unique=False)

    def __init__(self, id, use_type, producer):
        BaseObject.__init__(self)
        self._set_data(id, use_type, producer)

    def _set_data(self, id, use_type, producer):
        self.id = id
        self.use_type = use_type
        self.producer = producer

    @classmethod
    def to_obj(cls, args_dict):
        for k in MusicObject.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_cam = MusicObject(args_dict[MusicObject.id.name],
                              args_dict[MusicObject.use_type.name],
                              args_dict[MusicObject.producer.name])
        return new_cam
Esempio n. 2
0
class User(sql_object.Model, BaseObject):

    __tablename__ = 'User'

    id = sql_object.Column(sql_object.Integer, primary_key=True)

    account = sql_object.Column(sql_object.String(32),
                                unique=True,
                                nullable=False)

    password = sql_object.Column(sql_object.String(128), nullable=False)

    nickname = sql_object.Column(sql_object.String(32),
                                 unique=True,
                                 nullable=False)

    # icon_id = Column(Integer, unique=True, default=-1, ForeignKey('ICon.id'))

    def __init__(self, account, password, nickname):
        BaseObject.__init__(self)
        self._set_data(account, password, nickname)

    def _set_data(self, account, password, nickname):
        self.account = account
        self.set_password(password)
        self.nickname = nickname

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def set_password(self, password):
        self.password = generate_password_hash(password)
        return True

    @classmethod
    def is_exist(cls, db_obj):
        id_ret = cls.query.filter(cls.id == db_obj.id).first()
        acc_ret = cls.query.filter(cls.account == db_obj.account).first()
        if id_ret is None and acc_ret is None:
            print("false----: %s" % db_obj.id)
            return False
        print("true----: %s" % db_obj.id)
        return True

    @classmethod
    def get_by_account(cls, account):
        return cls.query.filter(cls.account == account).first()

    @classmethod
    def get_by_nickname(cls, nickname):
        return cls.query.filter(cls.nickname == nickname).first()

    def to_dict(self, obj):
        pass

    @classmethod
    def to_obj(cls, package):
        dict_package = eval(package)
        print(">>>>>>", dict_package)
        # if isinstance(obj_class, User):
        req_msg = dict_package[OBJECT_DATA_N]
        new_obj = User(req_msg[ACCOUNT_N], req_msg[PASSWORD_N],
                       req_msg[NICKNAME_N])
        print(new_obj.id, new_obj.account, new_obj.password, new_obj.nickname)
        return new_obj
Esempio n. 3
0
class GenerateData(sql_object.Model, BaseObject):

    __tablename__ = 'GenerateData'

    id = sql_object.Column(sql_object.Integer, primary_key=True)

    robot_id = sql_object.Column(sql_object.String(32),
                                 sql_object.ForeignKey('Robot.id'),
                                 nullable=False)

    user_id = sql_object.Column(sql_object.Integer,
                                sql_object.ForeignKey('User.id'),
                                nullable=False)

    pic_date = sql_object.Column(sql_object.DateTime,
                                 nullable=True,
                                 unique=False)

    dh_date = sql_object.Column(sql_object.DateTime,
                                nullable=True,
                                unique=False)

    fb_date = sql_object.Column(sql_object.DateTime,
                                nullable=True,
                                unique=False)

    def __init__(self,
                 robot_id,
                 user_id,
                 pic_date=None,
                 dh_date=None,
                 fb_date=None):
        BaseObject.__init__(self)
        self.location_list = []
        self._set_data(robot_id, user_id, pic_date, dh_date, fb_date)

    def set_robot_id(self, robot_id):
        if not Robot.is_exist_id(robot_id):
            raise ObjectNotExist('%s is not exist which id is %s' %
                                 (Robot.__name__, robot_id))
        self.robot_id = robot_id

    def set_user_id(self, user_id):
        if not User.is_exist_id(user_id):
            raise ObjectNotExist('%s is not exist which id is %s' %
                                 (User.__name__, user_id))
        self.user_id = user_id

    def _set_data(self,
                  robot_id,
                  user_id,
                  pic_date=None,
                  dh_date=None,
                  fb_date=None):
        self.set_robot_id(robot_id)
        self.set_user_id(user_id)
        self.pic_date = pic_date
        self.dh_date = dh_date
        self.fb_date = fb_date

    # def _init_location(self):
    #     SingleCalibration.query.filter(self.id == SingleCalibration.g_id)
    @classmethod
    def to_obj(cls, args_dict):
        for k in GenerateData.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_cam = GenerateData(args_dict[GenerateData.robot_id.name],
                               args_dict[GenerateData.user_id.name],
                               args_dict[GenerateData.pic_date.name],
                               args_dict[GenerateData.dh_date.name],
                               args_dict[GenerateData.fb_date.name])
        return new_cam

    @classmethod
    def update_obj(cls, args_dict):
        if GenerateData.id.name not in args_dict:
            raise ObjectNotExist('GenerateData id is wrong')
        gen = GenerateData.get_by_id(args_dict[GenerateData.id.name])
        if gen is None:
            raise ObjectNotExist('GenerateData id is wrong')

        # add origin data which are not in req data
        for k in GenerateData.__table__.columns:
            if k.name in args_dict:
                if k.name == GenerateData.robot_id.name:
                    gen.set_robot_id(args_dict[k.name])
                elif k.name == GenerateData.user_id.name:
                    gen.set_user_id(args_dict[k.name])
                else:
                    setattr(gen, k.name, args_dict[k.name])
        return gen
Esempio n. 4
0
class InverseTest(sql_object.Model, BaseObject):

    __tablename__ = 'InverseTest'

    id = sql_object.Column(sql_object.Integer, primary_key=True)

    opt_all_ik = sql_object.Column(sql_object.String(256),
                                   nullable=True,
                                   unique=False)

    ik_err = sql_object.Column(sql_object.String(256),
                               nullable=True,
                               unique=False)

    l_cam_img_pts = sql_object.Column(sql_object.String(256),
                                      nullable=True,
                                      unique=False)

    r_cam_img_pts = sql_object.Column(sql_object.String(256),
                                      nullable=True,
                                      unique=False)

    pixel_err = sql_object.Column(sql_object.Float(20, 10),
                                  nullable=True,
                                  unique=False)

    total_pixel_err = sql_object.Column(sql_object.Float(20, 10),
                                        nullable=True,
                                        unique=False)

    def __init__(self,
                 opt_all_ik=None,
                 ik_err=None,
                 l_cam_img_pts=None,
                 r_cam_img_pts=None,
                 pixel_err=None,
                 total_pixel_err=None,
                 loc_obj=None):

        BaseObject.__init__(self)
        self.set_location(loc_obj)
        self._set_data(opt_all_ik, ik_err, l_cam_img_pts, r_cam_img_pts,
                       pixel_err, total_pixel_err)

    def _set_data(self,
                  opt_all_ik=None,
                  ik_err=None,
                  l_cam_img_pts=None,
                  r_cam_img_pts=None,
                  pixel_err=None,
                  total_pixel_err=None):

        self.opt_all_ik = self.to_uri(opt_all_ik)
        self.ik_err = self.to_uri(ik_err)
        self.l_cam_img_pts = self.to_uri(l_cam_img_pts)
        self.r_cam_img_pts = self.to_uri(r_cam_img_pts)
        self.pixel_err = pixel_err
        self.total_pixel_err = total_pixel_err

    @classmethod
    def to_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')

        for k in InverseTest.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_dh = InverseTest(args_dict[InverseTest.opt_all_ik.name],
                             args_dict[InverseTest.ik_err.name],
                             args_dict[InverseTest.l_cam_img_pts.name],
                             args_dict[InverseTest.r_cam_img_pts.name],
                             args_dict[InverseTest.pixel_err.name],
                             args_dict[InverseTest.total_pixel_err.name],
                             location_obj)
        return new_dh

    @classmethod
    def update_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')
        if InverseTest.id.name not in args_dict:
            raise ObjectNotExist('InverseTest id is wrong')
        inv = InverseTest.get_by_id(args_dict[InverseTest.id.name])
        if inv is None:
            raise ObjectNotExist('InverseTest id is wrong')
        inv.set_location(location_obj)

        # add origin data which are not in req data
        for k in InverseTest.__table__.columns:
            if k.name in args_dict and args_dict[k.name] is not None:
                if k.name == cls.opt_all_ik.name or         \
                     k.name == cls.ik_err.name or           \
                     k.name == cls.l_cam_img_pts.name or    \
                     k.name == cls.r_cam_img_pts.name:
                    setattr(inv, k.name, inv.to_uri(args_dict[k.name]))
                else:
                    setattr(inv, k.name, args_dict[k.name])
        return inv

    def to_uri(self, filename):
        if filename is None:
            return None
        abs_path = self.location_obj.get_upload_path(
        ) + self.__class__.__name__ + '/' + filename
        if not os.path.exists(abs_path):
            print('set uri failed: ', abs_path)
            raise ObjectNotExist("%s file is not exist, please upload first" %
                                 filename)
        return DOWNLOAD_ROOT_URI + str(
            self.location_obj.id
        ) + '/' + self.__class__.__name__ + '/' + filename

    def set_location(self, loc_obj):
        self.location_obj = loc_obj
Esempio n. 5
0
class DH_Optimised(sql_object.Model, BaseObject):

    __tablename__ = 'DH_Optimised'

    id = sql_object.Column(sql_object.Integer, primary_key=True)

    model = sql_object.Column(sql_object.Enum(DH_Model),
                              nullable=False,
                              unique=False)

    angle_offset_full = sql_object.Column(sql_object.String(256),
                                          nullable=True,
                                          unique=False)

    joint_scale_factor = sql_object.Column(sql_object.String(256),
                                           nullable=True,
                                           unique=False)

    refine_pixel_err = sql_object.Column(sql_object.String(256),
                                         nullable=True,
                                         unique=False)

    robot_param = sql_object.Column(sql_object.String(256),
                                    nullable=True,
                                    unique=False)

    tot = sql_object.Column(sql_object.String(256),
                            nullable=True,
                            unique=False)

    trc = sql_object.Column(sql_object.String(256),
                            nullable=True,
                            unique=False)

    a_offset_six_param = sql_object.Column(sql_object.Float(20, 10),
                                           nullable=True,
                                           unique=False)

    c_offset_six_param = sql_object.Column(sql_object.Float(20, 10),
                                           nullable=True,
                                           unique=False)

    def __init__(self,
                 model,
                 angle_offset_full=None,
                 joint_scale_factor=None,
                 refine_pixel_err=None,
                 robot_param=None,
                 tot=None,
                 trc=None,
                 a_offset_six_param=None,
                 c_offset_six_param=None,
                 loc_obj=None):

        BaseObject.__init__(self)
        self.set_location(loc_obj)
        self._set_data(model, angle_offset_full, joint_scale_factor,
                       refine_pixel_err, robot_param, tot, trc,
                       a_offset_six_param, c_offset_six_param)

    def _set_data(self,
                  model,
                  angle_offset_full=None,
                  joint_scale_factor=None,
                  refine_pixel_err=None,
                  robot_param=None,
                  tot=None,
                  trc=None,
                  a_offset_six_param=None,
                  c_offset_six_param=None):

        self.set_model(model)
        self.angle_offset_full = self.to_uri(angle_offset_full)
        self.joint_scale_factor = self.to_uri(joint_scale_factor)
        self.refine_pixel_err = self.to_uri(refine_pixel_err)
        self.robot_param = self.to_uri(robot_param)
        self.tot = self.to_uri(tot)
        self.trc = self.to_uri(trc)
        self.a_offset_six_param = self.to_uri(a_offset_six_param)
        self.c_offset_six_param = self.to_uri(c_offset_six_param)

    def to_uri(self, filename):
        if filename is None:
            return None
        abs_path = self.location_obj.get_upload_path(
        ) + self.__class__.__name__ + '/' + filename
        if not os.path.exists(abs_path):
            print('set uri failed: ', abs_path)
            raise ObjectNotExist("%s file is not exist, please upload first" %
                                 filename)
        return DOWNLOAD_ROOT_URI + str(
            self.location_obj.id
        ) + '/' + self.__class__.__name__ + '/' + filename

    def set_location(self, loc_obj):
        self.location_obj = loc_obj

    def set_model(self, model):
        if model not in DH_Model.__dict__.keys():
            raise ObjectNotExist("mode should be one of %s" % list(DH_Model))
        self.model = model

    @classmethod
    def to_obj(cls, args_dict, location_obj):
        for k in DH_Optimised.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_dh = DH_Optimised(args_dict[DH_Optimised.model.name],
                              args_dict[DH_Optimised.angle_offset_full.name],
                              args_dict[DH_Optimised.joint_scale_factor.name],
                              args_dict[DH_Optimised.refine_pixel_err.name],
                              args_dict[DH_Optimised.robot_param.name],
                              args_dict[DH_Optimised.tot.name],
                              args_dict[DH_Optimised.trc.name],
                              args_dict[DH_Optimised.a_offset_six_param.name],
                              args_dict[DH_Optimised.c_offset_six_param.name],
                              location_obj)
        return new_dh

    @classmethod
    def update_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')
        if DH_Optimised.id.name not in args_dict:
            raise ObjectNotExist('DH_Optimised id is wrong')
        dh_obj = DH_Optimised.get_by_id(args_dict[DH_Optimised.id.name])
        if dh_obj is None:
            raise ObjectNotExist('DH_Optimised id is wrong')
        dh_obj.set_location(location_obj)
        # add origin data which are not in req data
        for k in DH_Optimised.__table__.columns:
            if k.name in args_dict and args_dict[k.name] is not None:
                if k.name == cls.model.name:
                    dh_obj.set_model(args_dict[k.name])
                elif k.name == cls.angle_offset_full.name or    \
                     k.name == cls.joint_scale_factor.name or   \
                     k.name == cls.refine_pixel_err.name or     \
                     k.name == cls.robot_param.name or          \
                     k.name == cls.tot.name or                  \
                     k.name == cls.trc.name:
                    setattr(dh_obj, k.name, dh_obj.to_uri(args_dict[k.name]))
                else:
                    setattr(dh_obj, k.name, args_dict[k.name])
        return dh_obj
Esempio n. 6
0
class SingleCalibration(sql_object.Model, BaseObject):

    __tablename__ = 'SingleCalibration'

    id = sql_object.Column(sql_object.Integer, primary_key=True)

    camera_id = sql_object.Column(sql_object.String(32), sql_object.ForeignKey('Camera.id'), nullable=False)

    n_camera_args = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    p_camera_args = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    n_distortion_args = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    p_distortion_args = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    n_toc = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    p_toc = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    n_projection_err = sql_object.Column(sql_object.Float(20, 10), nullable=True, unique=False)

    p_projection_err = sql_object.Column(sql_object.Float(20, 10), nullable=True, unique=False)

    found_mask = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    img_pts = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    img_size = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    obj_pts = sql_object.Column(sql_object.String(256), nullable=True, unique=False)

    def __init__(self, camera_id, n_camera_args=None, p_camera_args=None, n_distortion_args=None,
                 p_distortion_args=None, n_toc=None, p_toc=None, n_projection_err=None, p_projection_err=None,
                 found_mask=None, img_pts=None, img_size=None, obj_pts=None, location_obj=None):

        BaseObject.__init__(self)
        self.set_location(location_obj)
        self._set_data(camera_id, n_camera_args, p_camera_args, n_distortion_args, p_distortion_args, n_toc,
                       p_toc, n_projection_err, p_projection_err, found_mask, img_pts, img_size, obj_pts)

    def _set_data(self, camera_id, n_camera_args=None, p_camera_args=None, n_distortion_args=None,
                  p_distortion_args=None, n_toc=None, p_toc=None, n_projection_err=None, p_projection_err=None,
                  found_mask=None, img_pts=None, img_size=None, obj_pts=None):

        self.set_cam(camera_id)
        self.n_camera_args = self.to_uri(n_camera_args)
        self.p_camera_args = self.to_uri(p_camera_args)
        self.n_distortion_args = self.to_uri(n_distortion_args)
        self.p_distortion_args = self.to_uri(p_distortion_args)
        self.n_toc = self.to_uri(n_toc)
        self.p_toc = self.to_uri(p_toc)
        self.n_projection_err = n_projection_err
        self.p_projection_err = p_projection_err
        self.found_mask = self.to_uri(found_mask)
        self.img_pts = self.to_uri(img_pts)
        self.set_size(img_size)
        self.obj_pts = self.to_uri(obj_pts)

    def to_uri(self, filename):
        if filename is None:
            return None
        abs_path = self.location_obj.get_upload_path() + self.__class__.__name__ + '/' + filename
        if not os.path.exists(abs_path):
            print('set uri failed: ', abs_path)
            raise ObjectNotExist("%s file is not exist, please upload first" % filename)
        return DOWNLOAD_ROOT_URI + str(self.location_obj.id) + '/' + self.__class__.__name__ + '/' + filename

    def set_cam(self, cam_id):
        if not Camera.is_exist_id(cam_id):
            raise ObjectNotExist("camera is not exits which id is %s" % cam_id)
        self.camera_id = cam_id

    def set_size(self, size_arr):
        self.img_size = str(size_arr)

    def set_location(self, loc_obj):
        self.location_obj = loc_obj

    @classmethod
    def to_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')
        for k in SingleCalibration.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_single = SingleCalibration(args_dict[SingleCalibration.camera_id.name],
                                       args_dict[SingleCalibration.n_camera_args.name],
                                       args_dict[SingleCalibration.p_camera_args.name],
                                       args_dict[SingleCalibration.n_distortion_args.name],
                                       args_dict[SingleCalibration.p_distortion_args.name],
                                       args_dict[SingleCalibration.n_toc.name],
                                       args_dict[SingleCalibration.p_toc.name],
                                       args_dict[SingleCalibration.n_projection_err.name],
                                       args_dict[SingleCalibration.p_projection_err.name],
                                       args_dict[SingleCalibration.found_mask.name],
                                       args_dict[SingleCalibration.img_pts.name],
                                       args_dict[SingleCalibration.img_size.name],
                                       args_dict[SingleCalibration.obj_pts.name],
                                       location_obj
                                       )
        return new_single

    @classmethod
    def update_obj(cls, args_dict, loc_obj):

        if SingleCalibration.id.name not in args_dict:
            raise ObjectNotExist('SingleCalibration id is wrong')
        sin = SingleCalibration.get_by_id(args_dict[SingleCalibration.id.name])
        if sin is None:
            raise ObjectNotExist('SingleCalibration id is wrong')
        sin.set_location(loc_obj)
        # add origin data which are not in req data
        for k in SingleCalibration.__table__.columns:
            if k.name in args_dict and args_dict[k.name] is not None:
                if k.name == cls.camera_id.name:
                    sin.set_cam(args_dict[k.name])
                elif k.name == cls.img_size.name:
                    sin.set_size(args_dict[k.name])
                elif k.name == cls.n_camera_args.name or        \
                     k.name == cls.p_camera_args.name or        \
                     k.name == cls.n_distortion_args.name or    \
                     k.name == cls.p_distortion_args.name or    \
                     k.name == cls.n_toc.name or                \
                     k.name == cls.p_toc.name or                \
                     k.name == cls.found_mask.name or           \
                     k.name == cls.img_pts.name or              \
                     k.name == cls.obj_pts.name:
                    setattr(sin, k.name, sin.to_uri(args_dict[k.name]))
                else:
                    setattr(sin, k.name, args_dict[k.name])
        return sin
Esempio n. 7
0
class StereoCalibration(sql_object.Model, BaseObject):

    __tablename__ = 'StereoCalibration'

    id = sql_object.Column(sql_object.Integer, primary_key=True)

    l_camera_id = sql_object.Column(sql_object.String(32),
                                    sql_object.ForeignKey('Camera.id'),
                                    nullable=True)

    r_camera_id = sql_object.Column(sql_object.String(32),
                                    sql_object.ForeignKey('Camera.id'),
                                    nullable=True)

    l_cam_matrix = sql_object.Column(sql_object.String(256),
                                     nullable=True,
                                     unique=False)

    r_cam_matrix = sql_object.Column(sql_object.String(256),
                                     nullable=True,
                                     unique=False)

    l_dist_coeffs = sql_object.Column(sql_object.String(256),
                                      nullable=True,
                                      unique=False)

    r_dist_coeffs = sql_object.Column(sql_object.String(256),
                                      nullable=True,
                                      unique=False)

    rt_cam_a2_cam_b = sql_object.Column(sql_object.String(256),
                                        nullable=True,
                                        unique=False)

    stereo_E = sql_object.Column(sql_object.String(256),
                                 nullable=True,
                                 unique=False)

    stereo_F = sql_object.Column(sql_object.String(256),
                                 nullable=True,
                                 unique=False)

    stereo_R = sql_object.Column(sql_object.String(256),
                                 nullable=True,
                                 unique=False)

    pixel_err = sql_object.Column(sql_object.Float(20, 10),
                                  nullable=True,
                                  unique=False)

    def __init__(self,
                 l_camera_id,
                 r_camera_id,
                 l_cam_matrix=None,
                 r_cam_matrix=None,
                 l_dist_coeffs=None,
                 r_dist_coeffs=None,
                 rt_cam_a2_cam_b=None,
                 stereo_e=None,
                 stereo_f=None,
                 stereo_r=None,
                 pixel_err=None,
                 loc_obj=None):

        BaseObject.__init__(self)
        self.set_location(loc_obj)
        self._set_data(l_camera_id, r_camera_id, l_cam_matrix, r_cam_matrix,
                       l_dist_coeffs, r_dist_coeffs, rt_cam_a2_cam_b, stereo_e,
                       stereo_f, stereo_r, pixel_err, loc_obj)

    def _set_data(self,
                  l_camera_id,
                  r_camera_id,
                  l_cam_matrix=None,
                  r_cam_matrix=None,
                  l_dist_coeffs=None,
                  r_dist_coeffs=None,
                  rt_cam_a2_cam_b=None,
                  stereo_e=None,
                  stereo_f=None,
                  stereo_r=None,
                  pixel_err=None,
                  loc_obj=None):

        self.set_left_cam(l_camera_id)
        self.set_right_cam(r_camera_id)
        if loc_obj is not None:
            self.l_cam_matrix = self.to_uri(l_cam_matrix)
            self.r_cam_matrix = self.to_uri(r_cam_matrix)
            self.l_dist_coeffs = self.to_uri(l_dist_coeffs)
            self.r_dist_coeffs = self.to_uri(r_dist_coeffs)
            self.rt_cam_a2_cam_b = self.to_uri(rt_cam_a2_cam_b)
            self.stereo_E = self.to_uri(stereo_e)
            self.stereo_F = self.to_uri(stereo_f)
            self.stereo_R = self.to_uri(stereo_r)
            self.pixel_err = pixel_err

    def to_uri(self, filename):
        if filename is None:
            return None
        abs_path = self.location_obj.get_upload_path(
        ) + self.__class__.__name__ + '/' + filename
        if not os.path.exists(abs_path):
            print('set uri failed: ', abs_path)
            raise ObjectNotExist("%s file is not exist, please upload first" %
                                 filename)
        return DOWNLOAD_ROOT_URI + str(
            self.location_obj.id
        ) + '/' + self.__class__.__name__ + '/' + filename

    def set_left_cam(self, cam_id):
        if not Camera.is_exist_id(cam_id):
            raise ObjectNotExist("camera is not exits which id is %s" % cam_id)
        self.l_camera_id = cam_id

    def set_right_cam(self, cam_id):
        if not Camera.is_exist_id(cam_id):
            raise ObjectNotExist("camera is not exits which id is %s" % cam_id)
        self.r_camera_id = cam_id

    def set_location(self, loc_obj):
        self.location_obj = loc_obj

    @classmethod
    def to_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')

        for k in StereoCalibration.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_stereo = StereoCalibration(
            args_dict[StereoCalibration.l_camera_id.name],
            args_dict[StereoCalibration.r_camera_id.name],
            args_dict[StereoCalibration.l_cam_matrix.name],
            args_dict[StereoCalibration.r_cam_matrix.name],
            args_dict[StereoCalibration.l_dist_coeffs.name],
            args_dict[StereoCalibration.r_dist_coeffs.name],
            args_dict[StereoCalibration.rt_cam_a2_cam_b.name],
            args_dict[StereoCalibration.stereo_E.name],
            args_dict[StereoCalibration.stereo_F.name],
            args_dict[StereoCalibration.stereo_R.name],
            args_dict[StereoCalibration.pixel_err.name], location_obj)
        return new_stereo

    @classmethod
    def update_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')
        if StereoCalibration.id.name not in args_dict:
            raise ObjectNotExist('StereoCalibration id is wrong')
        ste = StereoCalibration.get_by_id(args_dict[StereoCalibration.id.name])
        if ste is None:
            raise ObjectNotExist('StereoCalibration id is wrong')
        ste.set_location(location_obj)
        # add origin data which are not in req data
        for k in StereoCalibration.__table__.columns:
            if k.name in args_dict and args_dict[k.name] is not None:
                if k.name == cls.l_camera_id.name:
                    ste.set_left_cam(args_dict[k.name])
                elif k.name == cls.r_camera_id.name:
                    ste.set_right_cam(args_dict[k.name])
                elif k.name == cls.l_cam_matrix.name or     \
                     k.name == cls.r_cam_matrix.name or     \
                     k.name == cls.l_dist_coeffs.name or    \
                     k.name == cls.r_dist_coeffs.name or    \
                     k.name == cls.rt_cam_a2_cam_b.name or  \
                     k.name == cls.stereo_E.name or         \
                     k.name == cls.stereo_F.name or         \
                     k.name == cls.stereo_R.name:
                    setattr(ste, k.name, ste.to_uri(args_dict[k.name]))
                else:
                    setattr(ste, k.name, args_dict[k.name])
        return ste