コード例 #1
0
ファイル: rdb_version.py プロジェクト: chenbk85/tphProjects
    def Do(self):
        '''
        Make rdb_version info 
        '''
        sqlcmd = '''
                drop table if exists rdb_version;
                CREATE TABLE rdb_version
                (
                  version_no varchar(512)
                );
                '''
        rdb_log.log(self.ItemName, 'Now create rdb_version...', 'info')
        if self.pg.execute2(sqlcmd) == -1:
            return -1
        else:
            self.pg.commit2()

        db_version = rdb_common.GetPath('version')

        sqlcmd = '''
                insert into rdb_version
                values(%s);
                '''
        rdb_log.log(self.ItemName, 'Now it is inserting to rdb_version...',
                    'info')
        db_version = "\'" + db_version + "\'"
        if self.pg.execute2(sqlcmd % (str(db_version), )) == -1:
            return -1
        else:
            self.pg.commit2()

        return 0
コード例 #2
0
ファイル: rdb_kind_code.py プロジェクト: chenbk85/tphProjects
 def Do(self):
     try :    
         stratify = rdb_common.Stratify()
         path = rdb_common.GetPath('kindcode')
         stratify.Open(path)
         kind_code_list = stratify.GetAllStratify() 
         sqlcmd = """
                  INSERT INTO temp_kind_code(
                                     kind_code
                                   , priority
                                   , name_type
                                   , kiwi_name
                                   , emg_code
                                   , emg_name
                                   , ni_code
                                   , ni_name
                                   , low_level
                                   , high_level
                                   , road_display_class)
                         VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
                  """
         for kind_code_recod in kind_code_list:
             if self.pg.execute2(sqlcmd, kind_code_recod) == -1:
                 rdb_log.log(self.ItemName, 'Fail to insert record into temp_kind_code', 'error')
                 break
         self.pg.commit2()
     except:
         rdb_log.log(self.ItemName, 'Fail make temp_kind_code', 'error')
         return -1
     
     return 0
コード例 #3
0
 def _CreatBinaryPath(self):
     '创建存放二进制数据图片的目录'
     picroot = rdb_common.GetPath('illust_binary')
     if picroot:
         self.binary_picroot = picroot
     else:
         picroot = rdb_common.GetPath('illust')
         self.binary_picroot = os.path.join(picroot, 'binary')
     
     try:
         if os.path.exists(self.binary_picroot):
             shutil.rmtree(self.binary_picroot)
     except:
         self.log.warning('fail to clear old pictures at %s.' % self.binary_picroot)
     
     if not os.path.exists(self.binary_picroot):
         os.makedirs(self.binary_picroot)
コード例 #4
0
 def _CreatBinaryPath(self):
     '创建存放二进制数据图片的目录'
     picroot = rdb_common.GetPath('illust')
     binary_picroot = os.path.join(picroot, 'binary')
     try:
         os.stat(binary_picroot)            # 测试文件路径存不存在
     except:
         os.makedirs(binary_picroot)        # 创建文件路径
     return binary_picroot
コード例 #5
0
 def __load_point_list(self):
     rdb_log.log(self.ItemName, 'Inserting record to temp_point_list...', 'info')
     
     ptroot = rdb_common.GetPath('pointlist')
     if ptroot:
         self.__loadPt(ptroot)
     
     self.pg.commit2()
     
     rdb_log.log(self.ItemName, 'insert record to temp_point_list end.', 'info')
コード例 #6
0
 def __load_illust_pic(self):
     rdb_log.log(self.ItemName, 'insert data to rdb_guideinfo_pic_blob_bytea ...', 'info')
     
     picroot = rdb_common.GetPath('illust')
     if picroot:
         self.__loadPic(picroot)
     
     self.pg.commit2()
     
     rdb_log.log(self.ItemName, 'insert data to rdb_guideinfo_pic_blob_bytea end.', 'info')
コード例 #7
0
ファイル: rdb_name.py プロジェクト: chenbk85/tphProjects
    def __init__(self):
        '''
        Constructor
        '''
        ItemBase.__init__(self, 'Name')
        text_filter_condition = rdb_common.GetPath('text_filter')
        self.temp_proj_name = rdb_common.GetPath('proj_name')
        self.temp_proj_country = rdb_common.GetPath('proj_country')
        temp_key = (self.temp_proj_name + "_" + self.temp_proj_country).upper()

        temp_dict = eval(text_filter_condition)
        if temp_dict is not None:
            cur_target_language_sort_condition = temp_dict[temp_key]

        self.__language_filter_dict = dict()
        if not self.__initialize_filter_condition(
                cur_target_language_sort_condition):
            self.log.error('make language filter condition error')

        self.__is_support_one_record_in_same_language = (
            rdb_common.GetPath('support_same_language_one_record')).split()
        self.__is_table_needs_one_record = True
コード例 #8
0
 def __load_illust_pic(self):
     rdb_log.log(self.ItemName, 'insert data to rdb_guideinfo_pic_blob_bytea ...', 'info')
     
     picroot = rdb_common.GetPath('illust')
     if os.path.isdir(picroot):
         for curDir,dirNames,fileNames in os.walk(picroot):
             for oneFile in fileNames:
                 exttype = os.path.splitext(oneFile)[1].lower()
                 if exttype in (".jpg", ".png", ".dat"):
                     self.__insertPic(os.path.join(curDir, oneFile))
         self.pg.commit2()
     else:
         strLogInfo = '''illust "%s" is not a directory, skipped loading illust.''' % picroot
         rdb_log.log(self.ItemName, strLogInfo , 'info')
     
     rdb_log.log(self.ItemName, 'insert data to rdb_guideinfo_pic_blob_bytea end.', 'info')
コード例 #9
0
 def DownLoadImageByID(self, Image_Id):
     '按照指定的image id, 下载图片。'
     if Image_Id is None:
         print 'Image ID is None, Please input a Image ID.'
         return -1
     
     picroot = rdb_common.GetPath('illust')
     sqlcmd = """
             SELECT gid, data, image_id
               FROM rdb_guideinfo_pic_blob_bytea
               where gid = %s;
             """
     self.pg.connect1()
     self.pg.execute1(sqlcmd, (Image_Id,))
     row  = self.pg.fetchone()
     while row:
         pic_name = os.path.join(picroot, str(row[0]))
         # 以二进制写方
         file_object= open(pic_name, 'wb')
         file_object.write(row[1])
         file_object.close()
         row = self.pg.fetchone()
     self.pg.close1()
     return 0
コード例 #10
0
ファイル: rdb_slope.py プロジェクト: chenbk85/tphProjects
    def Do(self):
        '''
        Make slope info 
        '''
        slope_data_status = rdb_common.GetPath('slope_data_support')
        if slope_data_status.lower() != 'true':
            return 0
        
        # step 1: insert info to temp_org_slope
        sqlcmd = """
            INSERT INTO temp_org_slope(
                rdb_link_id,
                org_link_id,
                slope_value,
                slope_shape,
                link_geom)
            (
                SELECT 
                    b.target_link_id,
                    a.link_id,
                    a.grad_value,    
                    st_transform( a.shape, 4326 ),
                    b.target_geom
                FROM (
                    SELECT 
                        link_id,
                        grad_value,
                        (ST_Dump(shape)).geom AS shape
                    FROM grad
                ) AS a
                INNER JOIN temp_link_org_rdb AS b
                ON a.link_id = b.org_link_id
            );
            """
        rdb_log.log(self.ItemName, 'Now it is inserting to temp_org_slope...', 'info')
        if self.pg.execute2(sqlcmd) == -1:
            return -1
        else:
            self.pg.commit2()
            
        # step 2: create rdb_slope info into temp_rdb_slope
        sqlcmd = """
            INSERT INTO temp_rdb_slope(
                rdb_link_id,
                link_pos_s, 
                link_pos_e,
                slope_value,
                slope_shape)           
            (
                SELECT 
                    rdb_link_id,
                    link_pos_s,
                    link_pos_e,
                    slope_value,
                    slope_shape                  
                FROM(            
                    SELECT 
                        rdb_link_id,
                        link_pos_s,
                        link_pos_e,
                        slope_value,
                        slope_shape,
                        abs(ST_X(slope_pt_s)-ST_X(link_pt_s)) AS dx_s,
                        abs(ST_Y(slope_pt_s)-ST_Y(link_pt_s)) AS dy_s,
                        abs(ST_X(slope_pt_e)-ST_X(link_pt_e)) AS dx_e,
                        abs(ST_Y(slope_pt_e)-ST_Y(link_pt_e)) AS dy_e                    
                    FROM(
                        SELECT 
                            rdb_link_id,
                            link_pos_s,
                            link_pos_e,
                            slope_value,
                            slope_shape,
                            link_pt_s,
                            link_pt_e,
                            ST_Line_Interpolate_Point(slope_shape, slope_pos_s) AS slope_pt_s,
                            ST_Line_Interpolate_Point(slope_shape, slope_pos_e) AS slope_pt_e
                        FROM(
                            SELECT 
                                rdb_link_id,
                                slope_value,
                                link_pos_s,
                                link_pos_e,
                                link_pt_s,
                                link_pt_e,
                                slope_shape,
                                ST_Line_Locate_Point(slope_shape, link_pt_s) AS slope_pos_s,
                                ST_Line_Locate_Point(slope_shape, link_pt_e) AS slope_pos_e
                            FROM(
                                SELECT  
                                    rdb_link_id,
                                    slope_value,
                                    link_pos_s,
                                    link_pos_e,
                                    slope_shape,
                                    ST_Line_Interpolate_Point(link_geom, link_pos_s) AS link_pt_s,
                                    ST_Line_Interpolate_Point(link_geom, link_pos_e) AS link_pt_e
                                FROM(
                                     SELECT  
                                        rdb_link_id,
                                        slope_value,
                                        slope_shape,
                                        link_geom,
                                        ST_Line_Locate_Point(link_geom, ST_startpoint(slope_shape)) AS link_pos_s,
                                        ST_Line_Locate_Point(link_geom, ST_endpoint(slope_shape))   AS link_pos_e
                                     FROM temp_org_slope AS a
                                ) AS b
                                WHERE link_pos_s <> link_pos_e
                            ) AS c
                        ) AS d
                    ) AS e
                ) AS f
                WHERE dx_s < CAST('0.0001' AS float) AND
                      dy_s < CAST('0.0001' AS float) AND
                      dx_e < CAST('0.0001' AS float) AND
                      dY_e < CAST('0.0001' AS float)
            );           
            """
        rdb_log.log(self.ItemName, 'Now it is insert slope info into temp_rdb_slope...', 'info')
        if self.pg.execute2(sqlcmd) == -1:
            return -1
        else:
            self.pg.commit2()
            
        # step 3: insert rdb_slope info into rdb_slope_tbl
        # 如果倾斜数据片段的形点顺序与link的形点顺序相反,既start_pt > end_pt,就交换一下首尾点的顺序。
        # 如果首尾点顺序发生交换,那么倾斜数值value也要同时取反,这一操作在函数rdb_cnv_slope_value()内完成。            
        sqlcmd = """    
            INSERT INTO rdb_slope_tbl(
                link_id,
                link_id_t,
                slope_pos_s, 
                slope_pos_e,
                slope_value)
            (
                SELECT 
                    rdb_link_id,
                    rdb_link_id >> 32 as link_id_t,
                    (CASE WHEN link_pos_s > link_pos_e THEN link_pos_e ELSE link_pos_s END),
                    (CASE WHEN link_pos_s > link_pos_e THEN link_pos_s ELSE link_pos_e END),
                    rdb_cnv_slope_value(slope_value, link_pos_s > link_pos_e)
                FROM temp_rdb_slope
            );
            """
        rdb_log.log(self.ItemName, 'Now it is insert slope info into rdb_slope_tbl...', 'info')
        if self.pg.execute2(sqlcmd) == -1:
            return -1
        else:
            self.pg.commit2()
            
        # Create Index for rdb_slope_tbl
        sqlcmd = """
             CREATE INDEX rdb_slope_tbl_link_id_idx 
                ON rdb_slope_tbl 
                USING btree
                (link_id);
             """
        rdb_log.log(self.ItemName, 'Now it is create Index for rdb_slope_tbl...', 'info')
        if self.pg.execute2(sqlcmd) == -1:
            return -1
        else:
            self.pg.commit2()
                               
        # step 4: update rdb_link 
        sqlcmd = """
             UPDATE rdb_link 
             SET tilt_flag = TRUE 
             FROM (
                 SELECT DISTINCT link_id
                 FROM rdb_slope_tbl        
             ) AS A
             WHERE rdb_link.link_id = A.link_id;
             """
        rdb_log.log(self.ItemName, 'Now it is update slope flag into rdb_link...', 'info')
        if self.pg.execute2(sqlcmd) == -1:
            return -1
        else:
            self.pg.commit2()

        return 0