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


Python Model.query方法代码示例

本文整理汇总了Python中model.Model.query方法的典型用法代码示例。如果您正苦于以下问题:Python Model.query方法的具体用法?Python Model.query怎么用?Python Model.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Model的用法示例。


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

示例1: get

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import query [as 别名]
    def get(self):

        #path param 1  = total number of data store writes
        #path param 2  = batch size used for multi-writes
        #path param3  = batch size used for page fetch
        #path param4  = number of writes to do using the task queue

        #E.g. http://localhost:8080/?writetotal=1000&writebatch=1000&fetchbatch=1000&taskwrite=1

        path = re.sub('^/', '', self.request.path)
        path = re.sub('/$', '', path)

                
        split = path.split('/')

        logging.info(split)
                 
        countDataStoreWriteTotalParam = 0
        countDataStoreWriteBatchParam = 1000
        countDataStoreFetchBatchParam = 1000
        taskQueueWrites = 0;

        temp = self.request.get("writetotal")
        if temp != '':
            countDataStoreWriteTotalParam = int(temp)

        temp = self.request.get("writebatch")
        if temp != '':
            countDataStoreWriteBatchParam = int(temp)

        temp = self.request.get("fetchbatch")
        if temp != '':
            countDataStoreFetchBatchParam = int(temp)

        temp = self.request.get("taskwrite")
        if temp != '':
            taskQueueWrites = int(temp)

        processing_start = datetime.datetime.now()
        responseMsg = '<p>Data store test starting (timestamp = %s).....countDataStoreWriteTotalParam = %d, countDataStoreWriteBatchParam = %d, countDataStoreFetchBatchParam = %d, taskQueueWrites = %d' % (str(processing_start), countDataStoreWriteTotalParam, countDataStoreWriteBatchParam, countDataStoreFetchBatchParam, taskQueueWrites)
        if True:
            #1 batch put to the datastore
            
            entity_write_count = countDataStoreWriteTotalParam
            entity_write_batch_size = countDataStoreWriteBatchParam
            responseMsg += '<p>#1 starting datastore writes %d in batch size of %d' % (entity_write_count, entity_write_batch_size)
            

            start = datetime.datetime.now()
            if True:
                WriteRecords(entity_write_count, entity_write_batch_size, 'ur')

            end = datetime.datetime.now()
            responseMsg += '<p style="text-indent: 2em;">data store writes processing time (mS) = %s' % str((end-start).total_seconds() * 1000)
            
        
        if False:

            #2 read all keys using single fetch
            responseMsg += '<p>#2 starting datastore read all keys using single fetch'
            
            start = datetime.datetime.now()
            keys = Model.query().fetch(keys_only=True)
            entity_count = len(keys)        

            end = datetime.datetime.now()
            responseMsg += '<p style="text-indent: 2em;">entity count %i, processing time (mS) = %s' % (entity_count, str((end-start).total_seconds() * 1000))


        

        key_in_dataset = None
        if False:
            #3 read all keys from data store using paged fetch

            fetch_page_size = countDataStoreFetchBatchParam
            if fetch_page_size <= 0:
                fetch_page_size = 1000

            responseMsg += '<p>#3 starting datastore read all keys using paged fetch using batch size of ' + str(fetch_page_size)
            
            start = datetime.datetime.now()
            pages_fetched = 0
            entities_fetched = 0

            #for the while loop
            has_more = True
            cursor = None
            while has_more:
                entities, cursor, more = Model.query().fetch_page(fetch_page_size,
                                                    start_cursor=cursor, keys_only=True)
                pages_fetched += 1
                entities_fetched += len(entities)        
                has_more = cursor and more

                if has_more == False:
                    key_in_dataset = entities[0]

            end = datetime.datetime.now()
            responseMsg += '<p style="text-indent: 2em;">Fetch page called %i times, entities fetched %i, processing time (mS) = %s' % (pages_fetched, entities_fetched, str((end-start).total_seconds() * 1000))      
#.........这里部分代码省略.........
开发者ID:neilmca,项目名称:gc_datastore_performance_test,代码行数:103,代码来源:datastoretest.py

示例2: MTV

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import query [as 别名]
class MTV(object):

    def __init__(self, D, initial_C=[], k=DEFAULT_K, m=DEFAULT_M, s=DEFAULT_S, z=DEFAULT_Z, v=DEFAULT_V, q=DEFAULT_Q, add_negated=DEFAULT_ADD_NEGATED, greedy=DEFAULT_GREEDY, headers=None):
        super(MTV, self).__init__()

        # Mine up to k itemsets
        self.k = k

        # Maximum itemset size
        self.m = m

        # Support
        self.s = s

        # Constraint on max model size
        self.q = q
        # If q is set, we will black list singletons from models
        # having reached the max size
        self.black_list_singletons = set()

        # Be verbose
        self.v = v

        # Header strings for attributes
        self.headers = headers

        # If set to True, MTV will also produce negated patterns
        self.add_negated = add_negated

        # If true FindBestItemset will be more greedy
        self.greedy = greedy

        # Number of candidate itemsets FindBestItemSet should search for
        # Will result in a list of top-z highest heuristics
        self.z = z

        # Dataset, is it right to always remove empty rows?
        tmp = []
        for i in D:
            if i != 0:
                tmp.append(i)
        self.D = tmp

        # Singletons
        self.I = itemsets.singletons(self.D)

        if self.add_negated:
            self.D  = dataset_with_negations(self.D, self.I)
            self.I = itemsets.singletons(self.D)


        # Cached frequency counts in D
        self.fr_cache = {}

        # Global summary
        self.C = list()

        self.union_of_C = itemsets.union_of_itemsets(self.C)

        self.BIC_scores = {}
        self.heuristics = {}

        # Create a model for holding all singletons
        # Singletons not used by model in the graph
        # will be in this model
        self.singleton_model = Model(self)
        self.singleton_model.I = self.I.copy()
        self.singleton_model.iterative_scaling()

        # Cached queries
        self.query_cache = {}

        # List to track history of disjoint components
        self.independent_components = []

        # List to track history of C size
        self.summary_sizes = []

        # List to track how large a search space was searched
        self.search_space = []

        # List to track history of timings of a loop in mtv
        self.loop_times = []

        # Initialize Graph of independent models
        self.graph = Graph()
        self.__init_graph(initial_C)

        self.BIC_scores['initial_score'] = self.score()


    def mtv(self):
        """
        Run the mtv algorithm
        """

        timer_stopwatch('run')

        # Added 0 loop_times for seeded itemsets
        for X in self.C:
#.........这里部分代码省略.........
开发者ID:AndersHqst,项目名称:PyMTV,代码行数:103,代码来源:mtv.py

示例3: Controller

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import query [as 别名]
class Controller(TabbedPanel):
    
    def __init__(self, **kwargs):
        super(Controller, self).__init__(**kwargs)
        self.model = Model()
        self.menu = self.buildMenu()
        self.panels = self.buildPanels()
        self.buildCallbacks()
        self.configureController()
    
    def buildMenu(self):
        menu = MenuScreen(controller = self)
        self.add_widget(menu)
        
        return menu
    
    def buildPanels(self):
        panels = []
        
        for i in range(4):
            panel = Panel()
            panels.append(panel)
        
        for panel in panels:
            self.add_widget(panel)
            
        return panels
        
    def configureController(self):
        # TODO
        # dynamically assign mat and EventID
        self.mat = 1
        self.EventID = 1
        
        self.default_tab = self.menu
        
        self.add_widget(SyncButton(controller = self))
        
    def listen(self, caller):
        print "listen heard an event"
        for value in caller.value:
            if (value in self.callbacks):
                print 'callback available {}'.format(value)
                self.callbacks[value]()
            else:
                print "no callbacks available for this call: {}".format(value)
    
    def buildCallbacks(self):
        self.callbacks = {
                          'sync':self.syncCurrentPanel,
                          'get brackets':self.getBrackets
                          }
        
    def syncCurrentPanel(self):
        print 'syncCurrentPanel: message received'
        
        # check if attempting to sync menu
        
        # ask to verify sync
        
        # query model to store division info
        
        # set panel content to null
        
        # remove panel widget
    
    def getBrackets(self):
        if not (self.isPanelReady()):
            return False
        
        divisions = self.getDivisions()
        for division in divisions:
            print "Division ready to run: {}".format(division["DivisionID"])
            
            fighters = self.getFighters(division)    
            bracket = self.getBracket(fighters)
            self.setBracketToPanel(bracket)
    
    def isPanelReady(self):    
        for panel in self.panels:
            if (panel.ready):
                return True
            
    def getDivisions(self):
        divisions = self.model.query("SELECT DivisionID FROM Mat WHERE Mat = ? AND EventID = ? AND State = ? ", self.mat, self.EventID, "Not Running")
        return divisions
    
    def getFighters(self, division):
        fighters = []
        curs = self.model.query("SELECT FighterID,FirstName,LastName,Gym FROM Entry JOIN Fighter USING ( FighterID ) WHERE DivisionID = ? AND EventID = ?", division["DivisionID"], self.EventID)
        
        for fighter in curs:
            entry = dict(FirstName=fighter["FirstName"],
                         LastName=fighter["LastName"],
                         Gym=fighter["Gym"]
                         )
            fighters.append(entry)
        return fighters
    
    def getBracketSize(self, fighters):
#.........这里部分代码省略.........
开发者ID:jonoco,项目名称:bracketeer,代码行数:103,代码来源:main.py


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