• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mapper.Mapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mapper.Mapper的典型用法代码示例。如果您正苦于以下问题:Python Mapper类的具体用法?Python Mapper怎么用?Python Mapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Mapper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: cards_to_database

def cards_to_database(database, cards_file):
    """
    put data in cards_file into database.
    """
    
    mapper = Mapper(configuration.map_file)
    conn = sqlite3.connect(database)
    cursor = conn.cursor()
    
    cursor.execute("DROP TABLE IF EXISTS cards")
    cursor.execute("""
                   CREATE TABLE IF NOT EXISTS cards
                  (posid TEXT,
                   time INTEGER,
                   statid TEXT)
                   """)
    cursor.execute("CREATE INDEX time_index ON cards(time)")
    cursor.execute("CREATE INDEX statid_index ON cards(statid)")
    cursor.execute("CREATE INDEX posid_index ON cards(posid)")
    with open(cards_file, 'r') as reader:
        for line in reader:
            parts = line.strip().split(',')
            assert len(parts) == 15
            if not mapper.has_statid(parts[9]):
                continue
            if parts[5].count(':') == 1:
                parts[5] = parts[5] + ":00"
            parts[5] = datetime.strptime(parts[5], "%Y/%m/%d %H:%M:%S")
            parts[5] = calendar.timegm(parts[5].utctimetuple())
            cursor.execute("INSERT INTO cards VALUES (?, ?, ?)",
                           (parts[3], parts[5], parts[9]))
            
    cursor.close()
    conn.commit()
    conn.close()
开发者ID:YunshengWei,项目名称:Route-Matching,代码行数:35,代码来源:data_process.py


示例2: MapperTests

class MapperTests(unittest.TestCase):
        
    def setUp(self):
        self.mapper = Mapper();
        self.utils = Utils();
        utils_for_tests = UtilsForTests();
        self.test_map_scale_to_white_keys = utils_for_tests.loadTestCorpus('test_corpus/test_to_white_keys_corpus');
        self.test_get_map = utils_for_tests.loadTestCorpus('test_corpus/test_get_map_corpus');
    
                
    def test_mapScaleToWhiteKeys(self):
        for case in self.test_map_scale_to_white_keys:
            mapped_scale = self.mapper.mapScaleToWhiteKeys(case[0]);
            self.assertDictEqual(mapped_scale, case[1]);
    
    def test_getMap(self):
        for case in self.test_get_map:
            map = self.mapper.getMap(case[0],case[1]);
            self.assertDictEqual(map, case[2]);
            
    @unittest.skip("Preformance test")        
    def test_TimeitGetMap(self):
        setup = "from utils import Utils; from mapper import Mapper; mapper = Mapper(); utils = Utils();"
        code_to_test = """
        for scale in utils.getAvailableScales():
            for note in utils.getNotes():
                mapper.getMap(note, scale);
        """
        result_first = timeit.repeat(code_to_test, setup = setup,repeat=100, number=100);
        result_avg = reduce(lambda x, y: x + y, result_first) / len(result_first)
        print("Result avg: " + str(result_avg));
开发者ID:doino-gretchenliev,项目名称:Mid-Magic,代码行数:31,代码来源:test_mapper.py


示例3: start_thememapper

def start_thememapper():
    global nav
    global mapper
    #initialize the necessary classes
    mapper = Mapper(get_settings())
    nav = Navigation()
    # Adds the ability to set config file and port through commandline
    p = optparse.OptionParser()
    p.add_option('--port', '-p', default=mapper.port,help='port thememapper should run at')
    p.add_option('--diazo', '-d', default=False,action="store_true",dest="diazo",help='force diazo server to run')
    p.add_option('--diazo_port', '-f', default=mapper.diazo_port,help='port diazo should run at')
    options = p.parse_args()[0]
    mapper.port = options.port
    mapper.diazo_port = options.diazo_port
    #start thememapper
    print "Starting thememapper on http://0.0.0.0:" + mapper.port
    HTTPServer(WSGIContainer(app)).listen(mapper.port)
    if options.diazo or mapper.diazo_run == 'True':
        try: 
            from thememapper.diazo import server
            print "Starting diazo on http://0.0.0.0:" + mapper.diazo_port
            HTTPServer(server.get_application(mapper)).listen(mapper.diazo_port)
        except ImportError: 
            print "You will need to install thememapper.diazo before being able to use this function." 
    ioloop = IOLoop.instance()
    autoreload.watch(os.path.join(os.path.dirname(__file__), 'settings.properties'))
    autoreload.add_reload_hook(reload)
    autoreload.start(ioloop)
    ioloop.start()
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:thememapper.core,代码行数:29,代码来源:main.py


示例4: load_source

def load_source(source, action='load'):


    if source != None:
        db.session.query(Release).filter(Release.source_id == source.id).delete() 

    error_hash = {}
    mapper = Mapper(source)
    for release, error in  mapper.to_ocds():
        if error != None:
            if error[0] not in error_hash:
                error_hash[error[0]] = []
            error_hash[error[0]].append(error[1])
        else:
            load_ocds(release, type='dict', source=source)


    if len(error_hash) > 0:
        message = "Erreurs lors du chargement du fichier %s \n\n" % (source.url)
        message += "\n".join(["Erreur: %s pour les lignes: %s" % (error_type, lines) for error_type, lines in error_hash.items()])
        app.logger.error(message)
    else: 
        app.logger.info("Succès du chargement du fichier : %s" % (source.url))

    source.last_retrieve = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    db.session.commit()
开发者ID:fprieur,项目名称:ovc-vdm,代码行数:26,代码来源:manage.py


示例5: __init__

 def __init__(self, dbName, dictClasses=None):
     Mapper.__init__(self, dictClasses)
     self.__initObjDict()
     self.__initUpdateDict()
     try:
         self.db = SqliteObjectsDb(dbName)
     except Exception, ex:
         raise Exception("Error creating SqliteMapper, dbName: %s\n error: %s" % (dbName, ex))
开发者ID:denisfortun,项目名称:scipion,代码行数:8,代码来源:sqlite.py


示例6: test_given_an_image_with_no_points_a_point_map_returned

 def test_given_an_image_with_no_points_a_point_map_returned(self):
     img = cv2.imread(os.path.join(self.test_data_path,'SimpleTestImage5.png'),1)
     expected = [-1 for i in range(0,20)]
     colour = [255,255,255]
     threshold = 0
     mapper = Mapper(colour,threshold)
     actual = mapper.get_points(img)
     self.assertEquals(expected,actual)
开发者ID:MaxPRafferty,项目名称:ImageBuilder,代码行数:8,代码来源:tests.py


示例7: test_given_an_colour_image_and_specific_colour_a_point_map_returned

 def test_given_an_colour_image_and_specific_colour_a_point_map_returned(self):
     img = cv2.imread(os.path.join(self.test_data_path,'SimpleTestImage2.png'),1)
     expected = [i for i in range(0,20)]
     colour = [255,128,0]
     threshold = 0
     mapper = Mapper(colour,threshold)
     actual = mapper.get_points(img)
     self.assertEquals(expected,actual)
开发者ID:MaxPRafferty,项目名称:ImageBuilder,代码行数:8,代码来源:tests.py


示例8: test_given_a_threshold_items_in_threshold_work_for_blue

 def test_given_a_threshold_items_in_threshold_work_for_blue(self):
     img = cv2.imread(os.path.join(self.test_data_path,'BlueThresholdTest.png'),1)
     threshold = 20
     expected = [0,0,0,-1,-1] 
     colour = [128,128,128]
     mapper = Mapper(colour, threshold)
     actual = mapper.get_points(img)
     self.assertEquals(expected,actual)
开发者ID:MaxPRafferty,项目名称:ImageBuilder,代码行数:8,代码来源:tests.py


示例9: test_a_threshold_can_be_changed

 def test_a_threshold_can_be_changed(self):
     img = cv2.imread(os.path.join(self.test_data_path,'GreenThresholdTest.png'),1)
     initial_threshold = 20
     new_threshold = 21
     expected = [0,0,0,0,0] 
     colour = [128,128,128]
     mapper = Mapper(colour, initial_threshold)
     mapper.set_threshold(new_threshold)
     actual = mapper.get_points(img)
     self.assertEquals(expected,actual)
开发者ID:MaxPRafferty,项目名称:ImageBuilder,代码行数:10,代码来源:tests.py


示例10: TestMapper

class TestMapper(object):
    used = False

    def empty(self, *args, **kw):
        self.used = True

    def setUp(self):
        self.used = False
        self.opts = Opts()
        self.mapper = Mapper(self.opts)
        self.mapper.save_config = self.empty

    def parse_opts_test(self):
        self.opts.title = 'название 1'.decode('utf-8')
        self.mapper.prepare()
        assert (self.mapper.config['title'] == u'название 1')
        assert self.used

    def load_config_test(self):
        config = {'title': 'название 2'}
        f = NamedTemporaryFile()
        json.dump(config, f, encoding='utf-8')
        f.flush()
        self.opts.config = f.name
        self.mapper.prepare()
        assert (self.mapper.config['title'] == u'название 2')

    def get_pagesize_test(self):
        assert self.mapper.get_page_size('a4') == self.mapper.get_page_size('A4')
        x, y = self.mapper.get_page_size('a4')
        assert self.mapper.get_page_size('a4', True) == (y, x)
        assert self.mapper.get_page_size('a3', False) == (y, x * 2)

    def get_coords_test(self):
        assert self.mapper.get_coords('235,117.2') == [235., 117.2]
开发者ID:kdudkov,项目名称:mapper,代码行数:35,代码来源:test_mapper.py


示例11: __init__

 def __init__(self, dbName, dictClasses=None, tablePrefix=''):
     Mapper.__init__(self, dictClasses)
     self._objTemplate = None
     try:
         self.db = SqliteFlatDb(dbName, tablePrefix)
         self.doCreateTables = self.db.missingTables()
         
         if not self.doCreateTables:
             self.__loadObjDict()
     except Exception, ex:
         raise Exception('Error creating SqliteFlatMapper, dbName: %s, tablePrefix: %s\n error: %s' % (dbName, tablePrefix, ex))
开发者ID:azazellochg,项目名称:scipion,代码行数:11,代码来源:sqlite.py


示例12: Store

class Store(object):
    """Store.
       Required constructor parameters: path, block_size, hash_algorithm,
       umask, blockpool, mappool.
    """

    def __init__(self, **params):
        umask = params['umask']
        if umask is not None:
            os.umask(umask)

        path = params['path']
        if path and not os.path.exists(path):
            os.makedirs(path)
        if not os.path.isdir(path):
            raise RuntimeError("Cannot open path '%s'" % (path,))

        p = {'blocksize': params['block_size'],
             'blockpath': os.path.join(path + '/blocks'),
             'hashtype': params['hash_algorithm'],
             'blockpool': params['blockpool']}
        self.blocker = Blocker(**p)
        p = {'mappath': os.path.join(path + '/maps'),
             'namelen': self.blocker.hashlen,
             'mappool': params['mappool']}
        self.mapper = Mapper(**p)

    def map_get(self, name):
        return self.mapper.map_retr(name)

    def map_put(self, name, map):
        self.mapper.map_stor(name, map)

    def map_delete(self, name):
        pass

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data,))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)
开发者ID:apyrgio,项目名称:synnefo,代码行数:52,代码来源:store.py


示例13: Store

class Store(object):
    """Store.
       Required constructor parameters: path, block_size, hash_algorithm,
       blockpool, mappool.
    """

    def __init__(self, **params):
        pb = {'blocksize': params['block_size'],
              'hashtype': params['hash_algorithm'],
              'archipelago_cfile': params['archipelago_cfile'],
              }
        self.blocker = Blocker(**pb)
        pm = {'namelen': self.blocker.hashlen,
              'hashtype': params['hash_algorithm'],
              'archipelago_cfile': params['archipelago_cfile'],
              }
        self.mapper = Mapper(**pm)

    def map_get(self, name, size):
        return self.mapper.map_retr(name, size)

    def map_put(self, name, map, size, block_size):
        self.mapper.map_stor(name, map, size, block_size)

    def map_delete(self, name):
        pass

    def map_copy(self, dst, src, size):
        self.mapper.map_copy(dst, src, size)

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_get_archipelago(self, hash):
        blocks = self.blocker.block_retr_archipelago((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data,))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)
开发者ID:AthinaB,项目名称:synnefo,代码行数:52,代码来源:store.py


示例14: test_a_colour_can_be_changed

    def test_a_colour_can_be_changed(self):
        img = cv2.imread(os.path.join(self.test_data_path,'GreenThresholdTest.png'),1)
        threshold = 20
        initial_expected = [0,0,0,-1,-1] 
        initial_colour = [128,128,128]
        new_expected = [-1,-1,-1,-1,-1]
        new_colour = [64,64,64]
        mapper = Mapper(initial_colour, threshold)
        initial_result = mapper.get_points(img)
        self.assertEquals(initial_expected,initial_result)

        mapper.set_colour(new_colour)
        new_result = mapper.get_points(img)
        self.assertEquals(new_expected,new_result)
开发者ID:MaxPRafferty,项目名称:ImageBuilder,代码行数:14,代码来源:tests.py


示例15: __init__

 def __init__(self, lcg, map_size):
     self.current_player_index = None
     self.game_started = False
     self._players = []
     self.lcg = lcg
     self.handlers = Handlers(self)
     self.mapper = Mapper(self, *map_size)
开发者ID:Namek,项目名称:lets-code-game,代码行数:7,代码来源:overseer.py


示例16: __init__

 def __init__(self, connection_config):
     self.connection_config = connection_config
     provider_name = self.connection_config['cloud_provider_name']
     provider_name = transfer_cloud_provider_name(provider_name)
     from mapper import Mapper
     self.mapper = Mapper(provider_name)
     self.driver = self.mapper.connect(self.connection_config)
开发者ID:carriercomm,项目名称:cloudify-libcloud-provider,代码行数:7,代码来源:cloudify_libcloud.py


示例17: __init__

    def __init__(self, outputRepo, inputRepos=None):
        """Construct a Butler to manage an output (read/write) repository,
        attaching zero or more input (read-only) repositories."""

        self.mapper = Mapper.create(outputRepo, inputRepos)
        self.registryPath = self.mapper.registryPath
        self.provenance = []
开发者ID:jonathansick-shadow,项目名称:daf_butler,代码行数:7,代码来源:butler.py


示例18: map_result

def map_result():
    
    if request.method == 'POST':
        rdf = request.form['data']
        try:
            gg = Graph()
            rdf_content = StringIO.StringIO(rdf.encode('utf-8'))
            gg.parse(rdf_content,  format="xml")
            mapper = Mapper(gg)
            #TODO-remove this test block after release
            batch_json = open("test_mapper_batch.json","r").read()
            result = mapper.mapping(batch_json)
            #End TODO-remove this test block after release
            return Response(result, mimetype='application/rdf+xml') 
        except:
            pass
开发者ID:FengPu,项目名称:x2r-me,代码行数:16,代码来源:x2r-me.py


示例19: job

def job(grouperNum, chunksQueue, listSaveStateNameGrouper, listListLastCallNum):
    print 'Starting worker ' + str(grouperNum)      
    while True:
        # Get new chunck to process
        chunk = chunksQueue.get()         
        # Work
        print 'Worker ' + str(grouperNum) + ' mapping chunk ' + str(chunk)
        MapIterator = MapChunkIterator(mapChunksNameGenerator(chunk)) # Iterator to iterate through the chunck        
        theContext = MapContext(groupChunksNameGenerator(chunk),MapIterator)        
        Mapper.map(theContext)
        print 'Worker ' + str(grouperNum) + ' grouping locally chunck ' + str(chunk)        
        idx = listListLastCallNum[grouperNum]+1        
        theGrouper = Grouper(grouperNum,idx,idx-1,directory);        
        listSaveStateNameGrouper[grouperNum] = theGrouper.group(theContext)
        listListLastCallNum[grouperNum] = idx ;      
        # "Close" chunk
        chunksQueue.task_done()
开发者ID:neosky2142,项目名称:PyMR,代码行数:17,代码来源:Dispatcher.py


示例20: __init__

 def __init__(self):
     #may want to enhance this with a pre-load file to prepopulate the DB
     self.db = {}                   # dictionary of DNSClassifierEntrys
     self.mapper = Mapper()
     self.new_callbacks = []        # For each new entry
     self.update_callbacks = []     # For each time an entry is updated
     self.all_callbacks = []        # When entry is updated or new
     self.class_callbacks = {}      # Dictionary of lists of callbacks per
开发者ID:sdonovan1985,项目名称:netassay,代码行数:8,代码来源:dnsclassify.py



注:本文中的mapper.Mapper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python file.FileCache类代码示例发布时间:2022-05-27
下一篇:
Python mapper.device函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap