本文整理汇总了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
示例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
示例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
示例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'])
示例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.
示例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'])
示例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)
示例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
示例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}})
示例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)
示例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!')
示例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
示例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
示例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
示例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})