当前位置: 首页>>代码示例>>Python>>正文


Python pydblite.Base类代码示例

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


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

示例1: generateWeights

def generateWeights(graph, weightFile, param):
    pdb = Base(weightFile)
    pdb.create('pair', 'node1', 'node2','TS02','TS05','TS08', 'JC')
    pdb.create_index('pair')
    
    sortedNodes = sorted(graph.nodes())
    for node in sortedNodes:
        others = sorted(set(n for n in sortedNodes if n > node))
        for other in others:
            if graph.has_edge(node, other):
                informations = list(edge for n1, n2, edge in graph.edges([node, other], data=True) if ((n1 == node and n2 == other) or (n1 == other and n2 == node)) )
                timesofLinks = []
                for info in informations:
                    timesofLinks.append(int(info['time']))
        
                
                bagNode1 = list(eval(edge['keywords']) for n1, n2, edge in graph.edges([node], data=True) if (n1 != other and n2 != other)  )
                bagNode2 = list(eval(edge['keywords']) for n1, n2, edge in graph.edges([other], data=True) if (n1 != node and n2 != node)  )
                
                
                total_publications = len(informations)   
                k =  int(param.t0_)  - max(timesofLinks)
                decayfunction02 = (1 - 0.2) ** k
                decayfunction05 = (1 - 0.5) ** k
                decayfunction08 = (1 - 0.8) ** k
                
                pdb.insert(str(node) + ';' + str(other),node,other,(total_publications * decayfunction02) , (total_publications * decayfunction05) , (total_publications * decayfunction08), get_jacard_domain(bagNode1, bagNode2) ) 
                 
    pdb.commit()            
    return pdb
开发者ID:AndersonChaves,项目名称:Predicao-de-Links,代码行数:30,代码来源:FullExecutionGraphRich.py

示例2: generateWeights

def generateWeights(graph, weightFile, param):
    pdb = Base(weightFile)
    pdb.create('pair', 'node1', 'node2','FTI01','FTI02','FTI03','FTI04','FTI05','FTI06','FTI07','FTI08','FTI09')
    pdb.create_index('pair')
    
    sortedNodes = sorted(graph.nodes())
    for node in sortedNodes:
        others = sorted(set(n for n in sortedNodes if n > node))
        for other in others:
            if graph.has_edge(node, other):
                informations = list(edge for n1, n2, edge in graph.edges([node, other], data=True) if ((n1 == node and n2 == other) or (n1 == other and n2 == node)) )
                timesofLinks = []
                for info in informations:
                    timesofLinks.append(int(info['time']))
                
                total_publications = len(informations)   
                k =  int(param.t0_)  - max(timesofLinks)
                FTI01 = total_publications * (0.1**k)
                FTI02 = total_publications * (0.2**k)
                FTI03 = total_publications * (0.3**k)
                FTI04 = total_publications * (0.4**k)
                FTI05 = total_publications * (0.5**k)
                FTI06 = total_publications * (0.6**k)
                FTI07 = total_publications * (0.7**k)
                FTI08 = total_publications * (0.8**k)
                FTI09 = total_publications * (0.9**k)
                 
                
 
                pdb.insert(str(node) + ';' + str(other),node,other, FTI01, FTI02, FTI03, FTI04, FTI05, FTI06, FTI07, FTI08, FTI09 ) 
                 
    pdb.commit()            
    return pdb
开发者ID:cptullio,项目名称:Predicao-de-Links,代码行数:33,代码来源:FullExecutionFTI.py

示例3: printdb

def printdb(dbpath): #Prints the contents of a PyDBLite database to the console
    db = Base(dbpath)
    if db.exists():
        db.open()
        retstr = ""
        for obj in db:
            retstr += str(obj)
            retstr += "\n"
        print retstr
        return retstr
    else:
        print "The database does not exist or is corrupt.\n"
开发者ID:magomez96,项目名称:AdamTestBot,代码行数:12,代码来源:utils.py

示例4: printdb

def printdb(dbpath):  # Prints the contents of a PyDBLite database to the console
    db = Base(dbpath)
    if db.exists():
        db.open()
        retstr = ""
        for obj in db:
            retstr += str(obj)
            retstr += "\n"
        encoded = retstr.encode("utf-8", errors="ignore")
        print(encoded)
    else:
        print("The database does not exist or is corrupt.\n")
开发者ID:agincel,项目名称:AdamTestBot,代码行数:12,代码来源:utils.py

示例5: generateDataForCalculate

 def generateDataForCalculate(self):
     if self.trainnigGraph == None:
         self.generating_Training_Graph()
     
     _nodes = sorted(self.trainnigGraph.nodes())
     adb = Base(self.filePathTrainingGraph + ".calc.pdl")
     adb.create('pairNodes', 'common', 'time', 'domain' )
     
     for node in sorted(_nodes):
         othernodes = set(n for n in _nodes if n > node)
         for other in othernodes:
             common =  set(networkx.common_neighbors(self.trainnigGraph, node, other))
             arestas = self.trainnigGraph.edges([node, other], True)
开发者ID:AndersonChaves,项目名称:Predicao-de-Links,代码行数:13,代码来源:Parameterization.py

示例6: __init__

 def __init__(self, database_name=None):
     print ("Opening " + database_name)
     db_r = Base(database_name)
     # Choose the DB of the Question Thread URL
     db_r.create('url', 'date', mode="open")
     # Check if the DB is empty or new
     if len(db_r)==0:
         print ("ERROR: Database not found or empty")
         sys.exit()
     else:
         print ("Database elements: " + str(len(db_r)))
         for r in db_r:
             self.url_to_scrape.append(UrlDate(r["url"], r["date"]))
         # Making a SET of the Database in order to delete duplicate URLS
         self.url_to_scrape = {x.url: x for x in self.url_to_scrape}.values()
         print ("Database elements after set operation: " + str(len(db_r)))
开发者ID:piercolella,项目名称:qa-scrapers,代码行数:16,代码来源:YahooScraper.py

示例7: open_spider

 def open_spider(self, spider):
     # Creation of DB
     self.db = Base(spider.database)
     self.db.create('uid', 'type', 'author', 'title', 'text', 'date_time',
                    'tags', 'views', 'answers', 'resolve', 'upvotes', 'url',
                    mode="override")
     dispatcher.connect(self.spider_closed, signals.spider_closed)
开发者ID:piercolella,项目名称:qa-scrapers,代码行数:7,代码来源:pipelines.py

示例8: do_Post

    def do_Post (self, result, request, args):
        def transfomType(x):
            if isinstance(x, unicode): return str(x)
            else: return x
    
        requestBody = args['requestContent']
        
        #######    Replace this section by your logic   #######
        vTestId = transfomType(json.loads(requestBody)['testId'])
        vTestMessage = transfomType(json.loads(requestBody)['testMessage'])
    
        responseCode = 200 #ResponseCode.Ok
 
       
        db = Base('database_service6.pdl')
        db.create('testId', 'testMessage', mode="open")
        db.insert(testId = vTestId, testMessage = vTestMessage)
        db.commit()

        result = []

        responseBody = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
        #######    Replace this section by your logic   #######


        request.setResponseCode(responseCode)
        resp = utils.serviceResponse(responseCode, responseBody)
        
        return resp
开发者ID:LucasFLima,项目名称:Mestrado,代码行数:29,代码来源:service6_srv.py

示例9: do_Delete

    def do_Delete (self, result, request, args):
        def transfomType(x):
            if isinstance(x, unicode): return str(x)
            else: return x
    
        #######    Replace this section by your logic   #######
        db = Base('database_service6.pdl')
        db.create('testId', 'testMessage', mode="open")
        result = db(testId = int(args['testId']))
        
        if len(result) == 0:
            responseCode = 404 #ResponseCode.Ok
            responseBody = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
        else:
            responseCode = 200 #ResponseCode.Ok
            responseBody = json.dumps(result[0], sort_keys=True, indent=4, separators=(',', ': '))
            db.delete(result[0])
            db.commit()
        #######    Replace this section by your logic   #######


        request.setResponseCode(responseCode)
        resp = utils.serviceResponse(responseCode, responseBody)
        
        return resp
开发者ID:LucasFLima,项目名称:Mestrado,代码行数:25,代码来源:service6_srv.py

示例10: do_Get

    def do_Get (self, result, request, args):
 
        #######    Replace this section by your logic   #######
        db = Base('database_service6.pdl')
        db.create('testId', 'testMessage', mode="open")
        result = db(testId = int(args['testId']))
        
        if len(result) == 0:
            responseCode = 404 #ResponseCode.Ok
            responseBody = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
        else:
            responseCode = 200 #ResponseCode.Ok
            responseBody = json.dumps(result[0], sort_keys=True, indent=4, separators=(',', ': '))
        #######    Replace this section by your logic   #######


        request.setResponseCode(responseCode)
        resp = utils.serviceResponse(responseCode, responseBody)
        
        return resp
开发者ID:LucasFLima,项目名称:Mestrado,代码行数:20,代码来源:service6_srv.py

示例11: checkCondition

 def checkCondition(cls, result):
     if result == "error":
         return "erro"
     else:
         
         db = Base('database_service1.pdl')
         db.create('cod', 'message', mode="open")
         db.insert(cod='1', message='valid')
         db.insert(cod='2', message='not valid')
         db.commit()
         #for rec in (db("age") > 30):
         for rec in db:
             print rec["cod"] +' '+ rec["message"]
         
         
         
         return "ok"
开发者ID:LucasFLima,项目名称:Mestrado,代码行数:17,代码来源:tmp.py

示例12: get_gbq_query_results

def get_gbq_query_results(gbq_service, query, prj_id='ace-amplifier-455', index_col=None,
                          col_order=None, cache=True, cache_path='', db=None):
    
    # set_trace()
    if cache:
        if db is None:
            db = Base(cache_path).create('query', 'result_df', mode='open')
            # db.create_index('query')
        final_df = extract(db, query)
        if len(final_df) > 0:
            # print 'extracted from cache ' + db.path
            return final_df

    df = gbq.read_gbq(query, prj_id)

    if cache:
        db.insert(query, df)
        db.commit()
        print 'saved to cache ' + db.path

    return df
开发者ID:sergey-linio,项目名称:weekly_reports,代码行数:21,代码来源:auth_to_gbq2.py

示例13: __init__

class Posts:
    def __init__(self, filename, erase_db):
        self.db = Base(filename)
        self.db.create('author', 'content', 'date', mode="override" if erase_db else "open")

    def addPost(self, post):
        """ Persist a Post object in db and returns auto-generated id. """
        post.id = self.db.insert(author = post.author, content = post.content, date = post.date)
        self.db.commit()
        return post.id

    def getPost(self, id):
        """ Get a post by its id. Returns a Post object or None if id is not found. """
        db_entry = self.db[id] if id in self.db else None
        return self.__createPost(db_entry) if db_entry is not None else None

    def getPosts(self, from_date = None, to_date = None, author = None):
        """ Get all posts matching optionally provided conditions. Returns a list (can be empty). """
        iterator = self.db.filter()
        if from_date is not None:
            iterator = iterator & (self.db("date") > from_date)
        if to_date is not None:
            iterator = iterator & (self.db("date") < to_date)
        if author is not None:
            iterator = iterator & (self.db("author") == author)

        return [self.__createPost(db_entry) for db_entry in iterator]

    def getPostsCount(self):
        """ Get total number of posts in db. """
        return len(self.db)

    def __createPost(self, db_entry):
        return Post(db_entry['author'], db_entry['content'], db_entry['date'], db_entry['__id__'])
开发者ID:aragornis,项目名称:vdm-ws,代码行数:34,代码来源:repository.py

示例14: likes

def likes(currentMessage):
    try:
        db = Base('chatStorage/likes/likes.pdl') #The path to the database
        db.create('userID', 'likes', 'dislikes', 'history', 'liked', mode="open") #Create a new DB if one doesn't exist. If it does, open it
        sentMyKarma = False
        try:
            likes = 0
            dislikes = 0
            if int(currentMessage.reply_to_message.from_user.id) == int(117924410): #is replying to bot message with /likes
                for user in db:
                    if int(user['userID']) == 117924410:
                        likes = int(user['likes'])
                        dislikes = int(user[dislikes])
                karma = int(likes) - int(dislikes)
                response = "Since you asked, I have " + str(likes) + " likes and " + str(dislikes) + " dislikes, for a total of " + str(karma) + " karma. "
                if karma > 0:
                    response += "\xF0\x9F\x98\x83".decode("utf-8") #smiley
                else:
                    response += "\xF0\x9F\x98\xAD".decode("utf-8") #crying
                return response
                sentMyKarma = True
        except Exception:
            print traceback.format_exc()

        if not sentMyKarma:
            userWasFound = False
            for user in db:
                if(int(user['userID']) == int(currentMessage.from_user.id)):
                    userWasFound = True
                    likes = int(user['likes'])
                    dislikes = int(user['dislikes'])

            if userWasFound:
                return currentMessage.from_user.first_name + ", you have " + str(likes) + " likes and " + str(dislikes) + " dislikes, for a total of " + str(int(likes) - int(dislikes)) + " karma."
            else:
                return "No like data found!"
    except Exception:
        print traceback.format_exc()
        return ""
开发者ID:agincel,项目名称:AdamTestBot,代码行数:39,代码来源:atbLikesDB.py

示例15: get_results_db

def get_results_db(clear_cache=False, skip=[]):
    cache_file = 'cache/results.pdl'
    db = Base(cache_file)

    if clear_cache or not db.exists() or os.path.getmtime(cache_file) < os.path.getmtime(results_dir):
        warnings.warn('Rebuilding results cache...')
        columns = set()
        rows = []
        p = pathlib.Path(results_dir)
        for config_file in p.glob('*.config'):
            with config_file.open() as config_fh:
                settings_hash = config_file.stem
                row = json.loads(config_fh.read())
            if settings_hash in skip:
                continue
            row['hash'] = settings_hash
            tests_count = analyze.count(config_file.parent, settings_hash)
            row['iostat_cpu'], len_cpu_values = analyze.iostat_cpu(config_file.parent, settings_hash)
            row['iperf_result'], len_iperf_values = getattr(analyze, row['iperf_name'])(config_file.parent, settings_hash, row)
            if tests_count != len_cpu_values or tests_count != len_iperf_values:
                raise analyze.AnalysisException('For test {}, mismatch in cardinality of tests between count ({}), iostat ({}) and iperf ({})'.format(settings_hash, tests_count, len_cpu_values, len_iperf_values), settings_hash)
            if len_iperf_values > 0:
                min_fairness = row['iperf_result']['fairness'][0] - row['iperf_result']['fairness'][1]
                if min_fairness < (1 - 1 / (2 * row['parallelism'])):
                    warnings.warn('For test {}, fairness has a critical value: {}.'.format(settings_hash, row['iperf_result']['fairness']), RuntimeWarning)
            columns = columns | set(row.keys())
            rows.append(row)

        db.create(*columns, mode='override')
        for r in rows:
            db.insert(**r)
        db.commit()
        warnings.warn('Results cache built.')
    else:
        warnings.warn('Reusing results cache.')
        db.open()

    return db
开发者ID:serl,项目名称:topoblocktest,代码行数:38,代码来源:test_master.py


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