當前位置: 首頁>>代碼示例>>Python>>正文


Python pymongo.DESCENDING屬性代碼示例

本文整理匯總了Python中pymongo.DESCENDING屬性的典型用法代碼示例。如果您正苦於以下問題:Python pymongo.DESCENDING屬性的具體用法?Python pymongo.DESCENDING怎麽用?Python pymongo.DESCENDING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在pymongo的用法示例。


在下文中一共展示了pymongo.DESCENDING屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def read(self, symbol, as_of=None):
        """
        Return current metadata saved for `symbol`

        Parameters
        ----------
        symbol : `str`
            symbol name for the item
        as_of : `datetime.datetime`
            return entry valid at given time

        Returns
        -------
        metadata
        """
        if as_of is not None:
            res = self.find_one({'symbol': symbol, 'start_time': {'$lte': as_of}},
                                sort=[('start_time', pymongo.DESCENDING)])
        else:
            res = self.find_one({'symbol': symbol}, sort=[('start_time', pymongo.DESCENDING)])
        return res['metadata'] if res is not None else None 
開發者ID:man-group,項目名稱:arctic,代碼行數:23,代碼來源:metadata_store.py

示例2: pop

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def pop(self, symbol):
        """
        Delete current metadata of `symbol`

        Parameters
        ----------
        symbol : `str`
            symbol name to delete

        Returns
        -------
        Deleted metadata
        """
        last_metadata = self.find_one({'symbol': symbol}, sort=[('start_time', pymongo.DESCENDING)])
        if last_metadata is None:
            raise NoDataFoundException('No metadata found for symbol {}'.format(symbol))

        self.find_one_and_delete({'symbol': symbol}, sort=[('start_time', pymongo.DESCENDING)])
        mongo_retry(self.find_one_and_update)({'symbol': symbol}, {'$unset': {'end_time': ''}},
                                              sort=[('start_time', pymongo.DESCENDING)])

        return last_metadata 
開發者ID:man-group,項目名稱:arctic,代碼行數:24,代碼來源:metadata_store.py

示例3: test_append_corrupted_new_version

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def test_append_corrupted_new_version(library, fw_pointers_cfg):
    with FwPointersCtx(fw_pointers_cfg):
        to_append = read_str_as_pandas("""  times | near
                          2012-11-09 17:06:11.040 |  30.0""")
        to_append_2 = read_str_as_pandas("""  times | near
                          2012-11-10 17:06:11.040 |  40.0""")
        library.write(symbol, ts1)
        # Append version
        library.append(symbol, to_append)
        # The append went wrong, and the new version document (written last), not available
        library._versions.find_one_and_delete({'symbol': symbol}, sort=[('version', pymongo.DESCENDING)])

        # Should still be able to append new data
        library.append(symbol, to_append_2, upsert=True)
        assert library.read(symbol).data['near'][-1] == 40.
        assert len(library.read(symbol).data) == len(ts1) + 1 
開發者ID:man-group,項目名稱:arctic,代碼行數:18,代碼來源:test_version_store.py

示例4: test_restore_append_overlapping_corrupts_old

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def test_restore_append_overlapping_corrupts_old(library, library_name):
    large_ts = create_test_data(size=2000, cols=100,
                                index=True, multiindex=False,
                                random_data=True, random_ids=True)
    library.write(symbol, large_ts[0:1000])
    library.snapshot('snap_write_a')

    library.append(symbol, large_ts[1000:1010])

    library.restore_version(symbol, as_of='snap_write_a', prune_previous_version=True)
    library.append(symbol, large_ts[1000:1009])

    last_v = library._versions.find_one(sort=[('version', pymongo.DESCENDING)])
    vsu.analyze_symbol(library, symbol, 0, last_v['version'] + 1)

    # Verify no versions have been corrupted
    for v in library._versions.find(sort=[('version', pymongo.DESCENDING)]):
        library.read(symbol, as_of=v['version']) 
開發者ID:man-group,項目名稱:arctic,代碼行數:20,代碼來源:test_version_store_corruption.py

示例5: test_restore_append_overlapping_corrupts_last

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def test_restore_append_overlapping_corrupts_last(library, library_name):
    large_ts = create_test_data(size=2000, cols=100,
                                index=True, multiindex=False,
                                random_data=True, random_ids=True)
    library.write(symbol, large_ts[0:1000])
    library.snapshot('snap_write_a')

    library.append(symbol, large_ts[1000:1010])

    library.restore_version(symbol, as_of='snap_write_a', prune_previous_version=True)
    library.append(symbol, large_ts[1000:1012])

    last_v = library._versions.find_one(sort=[('version', pymongo.DESCENDING)])
    vsu.analyze_symbol(library, symbol, 0, last_v['version'] + 1)

    # Verify no versions have been corrupted
    for v in library._versions.find(sort=[('version', pymongo.DESCENDING)]):
        library.read(symbol, as_of=v['version'])


# This is not necessary to fix, but the Exception thrown is quite confusing. 
開發者ID:man-group,項目名稱:arctic,代碼行數:23,代碼來源:test_version_store_corruption.py

示例6: test_append_fail_after_delete_noupsert

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def test_append_fail_after_delete_noupsert(library, library_name):
    large_ts = create_test_data(size=2000, cols=100,
                                index=True, multiindex=False,
                                random_data=True, random_ids=True)
    library.write(symbol, large_ts[0:1000])  #v1
    library.snapshot('snap_a')
    library.append(symbol, large_ts[1000:1010])  #v2
    library.snapshot('snap_b')
    library.append(symbol, large_ts[1010:1020])  #v3
    library.snapshot('snap_c')

    library.append(symbol, large_ts[1030:1040])  #v4

    library.delete(symbol) #v5

    library.append(symbol, large_ts[1040:1050], upsert=False)  # v6

    last_v = library._versions.find_one(sort=[('version', pymongo.DESCENDING)])
    vsu.analyze_symbol(library, symbol, 0, last_v['version'] + 1)

    # Verify no versions have been corrupted
    for v in library._versions.find(sort=[('version', pymongo.DESCENDING)]):
        library.read(symbol, as_of=v['version']) 
開發者ID:man-group,項目名稱:arctic,代碼行數:25,代碼來源:test_version_store_corruption.py

示例7: get_api_exceptions

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def get_api_exceptions(result_limit=50):
    """
    Retrieve the most recent logged exceptions.

    Args:
        result_limit: the maximum number of exceptions to return.

    Returns:
        list of exception dicts

    """
    db = api.db.get_conn()
    results = (
        db.exceptions.find({"visible": True}, {"_id": 0})
        .sort([("time", pymongo.DESCENDING)])
        .limit(result_limit)
    )
    return list(results) 
開發者ID:picoCTF,項目名稱:picoCTF,代碼行數:20,代碼來源:logger.py

示例8: insert

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def insert(self):
        import pymongo.errors

        if self.overwrite:
            return self.save()

        autoinc_key = self.run_entry.get("_id") is None
        while True:
            if autoinc_key:
                c = self.runs.find({}, {"_id": 1})
                c = c.sort("_id", pymongo.DESCENDING).limit(1)
                self.run_entry["_id"] = (
                    c.next()["_id"] + 1 if self.runs.count_documents({}, limit=1) else 1
                )
            try:
                self.runs.insert_one(self.run_entry)
                return
            except pymongo.errors.InvalidDocument as e:
                raise ObserverError(
                    "Run contained an unserializable entry."
                    "(most likely in the info)\n{}".format(e)
                )
            except pymongo.errors.DuplicateKeyError:
                if not autoinc_key:
                    raise 
開發者ID:IDSIA,項目名稱:sacred,代碼行數:27,代碼來源:mongo.py

示例9: store_wallet_message

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def store_wallet_message(msg, msg_data, decorate=True):
    wallet_message = messages.decorate_message_for_feed(msg, msg_data=msg_data) if decorate else msg

    # use "optimistic loop" pattern to insert a new messages with an incrementing seq
    while True:
        last_seq = config.mongo_db.wallet_messages.find_one(sort=[("_id", pymongo.DESCENDING)])['_id']
        new_seq = last_seq + 1
        try:
            config.mongo_db.wallet_messages.insert({
                '_id': new_seq,
                'when': calendar.timegm(time.gmtime()),
                'message': wallet_message,
            })
        except pymongo.errors.DuplicateKeyError:
            continue
        else:
            logger.debug("store_wallet_message: stored {}".format(new_seq))
            if config.state['cw_last_message_seq'] < new_seq:
                config.state['cw_last_message_seq'] = new_seq
            break

    # every so often, trim up the table
    if new_seq % 20 == 0:  # for performance, don't do this every iteration
        if config.mongo_db.wallet_messages.count() > FUZZY_MAX_WALLET_MESSAGES_STORED:
            config.mongo_db.wallet_messages.remove({'_id': {'$lte': new_seq - FUZZY_MAX_WALLET_MESSAGES_STORED}}) 
開發者ID:CounterpartyXCP,項目名稱:counterblock,代碼行數:27,代碼來源:counterwallet.py

示例10: get_block_indexes_for_dates

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def get_block_indexes_for_dates(start_dt=None, end_dt=None):
    """Returns a 2 tuple (start_block, end_block) result for the block range that encompasses the given start_date
    and end_date unix timestamps"""
    if start_dt is None:
        start_block_index = config.BLOCK_FIRST
    else:
        start_block = config.mongo_db.processed_blocks.find_one({"block_time": {"$lte": start_dt}}, sort=[("block_time", pymongo.DESCENDING)])
        start_block_index = config.BLOCK_FIRST if not start_block else start_block['block_index']

    if end_dt is None:
        end_block_index = config.state['my_latest_block']['block_index']
    else:
        end_block = config.mongo_db.processed_blocks.find_one({"block_time": {"$gte": end_dt}}, sort=[("block_time", pymongo.ASCENDING)])
        if not end_block:
            end_block_index = config.mongo_db.processed_blocks.find_one(sort=[("block_index", pymongo.DESCENDING)])['block_index']
        else:
            end_block_index = end_block['block_index']
    return (start_block_index, end_block_index) 
開發者ID:CounterpartyXCP,項目名稱:counterblock,代碼行數:20,代碼來源:database.py

示例11: get_mongos

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def get_mongos(self, force=False):
        if not force and self.mongos_db:
            return self.mongos_db
        elif self.db.is_mongos():
            return self.db
        else:
            db = self.connection['config']
            for doc in db.mongos.find().sort('ping', DESCENDING):
                try:
                    mongos_uri = MongoUri(doc['_id'])
                    logging.debug("Found cluster mongos: %s" % mongos_uri)
                    self.mongos_db = DB(mongos_uri, self.config, False, 'nearest')
                    logging.info("Connected to cluster mongos: %s" % mongos_uri)
                    return self.mongos_db
                except DBConnectionError:
                    logging.debug("Failed to connect to mongos: %s, trying next available mongos" % mongos_uri)
            raise OperationError('Could not connect to any mongos!') 
開發者ID:Percona-Lab,項目名稱:mongodb_consistent_backup,代碼行數:19,代碼來源:Sharding.py

示例12: _getTradeDaysByRelativeZero

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def _getTradeDaysByRelativeZero(self, baseDate):
        """ 基準日期向前找到第一個交易日 """

        baseDateSave = baseDate

        collection = self._getTradeDayTableCollection()

        baseDate = datetime.strptime(baseDate, '%Y-%m-%d')
        flt = {'datetime':{'$lte':baseDate}}

        try:
            cursor = collection.find(flt).sort('datetime', pymongo.DESCENDING)
        except Exception as ex:
            self._info.print("MongoDB Exception({0}): @_getTradeDaysByRelativeZero({1})".format(str(ex) + ', ' + str(ex.details), baseDateSave),
                             DyLogData.error)
            return None

        for d in cursor:
            if d['tradeDay']:
                return [d]

        return None 
開發者ID:moyuanz,項目名稱:DevilYuan,代碼行數:24,代碼來源:DyStockMongoDbEngine.py

示例13: _getCodeDay

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def _getCodeDay(self, code, baseDate, name=None):
        """ 得到個股的當日交易日, 向前貪婪 """
        collection = self._getStockDaysDb()[code]

        date = datetime.strptime(baseDate + ' 23:00:00', '%Y-%m-%d %H:%M:%S')
        flt = {'datetime': {'$lt': date}}

        sortMode = pymongo.DESCENDING

        try:
            cursor = collection.find(flt).sort('datetime', sortMode).limit(1)
        except Exception as ex:
            self._info.print("MongoDB Exception({0}): @_findOneCodeDaysByZeroRelative{1}:{2}, [{3}, {4}]日線數據".format(str(ex) + ', ' + str(ex.details),
                                                                                                                    code, name,
                                                                                                                    baseDate, n),
                             DyLogData.error)
            return None

        for d in cursor:
            return d['datetime'].strftime('%Y-%m-%d')
        
        return None 
開發者ID:moyuanz,項目名稱:DevilYuan,代碼行數:24,代碼來源:DyStockMongoDbEngine.py

示例14: getAdjFactor

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def getAdjFactor(self, code, date, name=None):
        collection = self._getStockDaysDb()[code]

        dateEnd = datetime.strptime(date + ' 23:00:00', '%Y-%m-%d %H:%M:%S')

        flt = {'datetime':{'$lt':dateEnd}}

        try:
            cursor = collection.find(flt).sort('datetime', pymongo.DESCENDING).limit(1)
        except Exception as ex:
            self._info.print("MongoDB 異常({0}): 獲取{1}:{2}, {3}複權因子".format(str(ex) + ', ' + str(ex.details),
                                                                                code, name,
                                                                                date),
                             DyLogData.error)
            return None

        # get adjust factor
        for d in cursor:
            return d['adjfactor']

        return None 
開發者ID:moyuanz,項目名稱:DevilYuan,代碼行數:23,代碼來源:DyStockMongoDbEngine.py

示例15: index

# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import DESCENDING [as 別名]
def index(self):
        """Get the list of objects.

        .. :quickref: File; Get the list of objects

        Response is paginated and will only contain 25 results. The most recent
        objects appear first.

        :query page: page number.
        :type page: int

        :>json list files: list of files (see :http:get:`/files/(id)` for details on the format of a file).
        """
        page = int(request.args.get('page', 1))

        files = current_user.files.find().sort('_id', DESCENDING).limit(PER_PAGE).skip((page - 1) * PER_PAGE)
        pagination = Pagination(page=page, per_page=PER_PAGE, total=files.count(), css_framework='bootstrap3')
        files = {'files': clean_files(list(files))}

        return render(files, 'files/index.html', ctx={'data': files, 'pagination': pagination}) 
開發者ID:certsocietegenerale,項目名稱:fame,代碼行數:22,代碼來源:files.py


注:本文中的pymongo.DESCENDING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。