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


Python pymongo.ASCENDING属性代码示例

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


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

示例1: _get_collection

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def _get_collection(self, collection_name=None):
        if collection_name:
            if collection_name in self.allowed_collections:
                coins = self.client.ratesx[collection_name]
            else:
                raise KeyError("Not allowed collection name: %s" % collection_name)
        else:
            coins = self.coins

        if collection_name \
            and collection_name not in self.client.ratesx.collection_names():

            if collection_name.startswith('coins_'):
                coins.create_index([('symbol', ASCENDING)], unique=False)
                coins.create_index([('timestamp', ASCENDING)], unique=False)
                coins.create_index([('symbol', ASCENDING),
                                    ('timestamp', ASCENDING)], unique=True)

            if collection_name.startswith('currencies_'):
                coins.create_index([('timestamp', ASCENDING)], unique=False)

        return coins 
开发者ID:chubin,项目名称:rate.sx,代码行数:24,代码来源:mng.py

示例2: _ensure_index

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def _ensure_index(collection):
        try:
            collection.create_index([('symbol', pymongo.HASHED)], background=True)
            # We keep it only for its uniqueness
            collection.create_index([('symbol', pymongo.ASCENDING),
                                     ('sha', pymongo.ASCENDING)], unique=True, background=True)
            # TODO: When/if we remove the segments->versions pointers implementation and keep only the forward pointers,
            #       we can remove the 'parent' from the index.
            collection.create_index([('symbol', pymongo.ASCENDING),
                                     ('parent', pymongo.ASCENDING),
                                     ('segment', pymongo.ASCENDING)], unique=True, background=True)
            # Used for efficient SHA-based read queries that have index ranges
            collection.create_index([('symbol', pymongo.ASCENDING),
                                     ('sha', pymongo.ASCENDING),
                                     ('segment', pymongo.ASCENDING)], unique=True, background=True)
        except OperationFailure as e:
            if "can't use unique indexes" in str(e):
                return
            raise 
开发者ID:man-group,项目名称:arctic,代码行数:21,代码来源:_ndarray_store.py

示例3: test_rename

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def test_rename(chunkstore_lib):
    df = create_test_data(size=10, cols=5)

    chunkstore_lib.write('test', df, chunk_size='D')
    assert_frame_equal(chunkstore_lib.read('test'), df)
    chunkstore_lib.rename('test', 'new_name')
    assert_frame_equal(chunkstore_lib.read('new_name'), df)

    with pytest.raises(Exception) as e:
        chunkstore_lib.rename('new_name', 'new_name')
    assert('already exists' in str(e.value))

    with pytest.raises(NoDataFoundException) as e:
        chunkstore_lib.rename('doesnt_exist', 'temp')
    assert('No data found for doesnt_exist' in str(e.value))

    assert('test' not in chunkstore_lib.list_symbols())

    # read out all chunks that have symbol set to 'test'. List should be empty
    chunks = []
    for x in chunkstore_lib._collection.find({SYMBOL: 'test'}, sort=[(START, pymongo.ASCENDING)],):
        chunks.append(x)

    assert(len(chunks) == 0) 
开发者ID:man-group,项目名称:arctic,代码行数:26,代码来源:test_chunkstore.py

示例4: list

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def list(self, request):
        await require(request, Permissions.view)
        possible_fields = [k.name for k in self._schema.keys]
        q = validate_query(request.query, possible_fields)
        paging = calc_pagination(q, self._primary_key)

        filters = q.get('_filters')
        query = {}
        if filters:
            query = create_filter(filters, self._schema)

        sort_direction = ASCENDING if paging.sort_dir == ASC else DESCENDING

        cursor = (self._collection.find(query)
                  .skip(paging.offset)
                  .limit(paging.limit)
                  .sort(paging.sort_field, sort_direction))

        entities = await cursor.to_list(paging.limit)
        count = await self._collection.count_documents(query)
        headers = {'X-Total-Count': str(count)}
        return json_response(entities, headers=headers) 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:24,代码来源:mongo.py

示例5: get_block_indexes_for_dates

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [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

示例6: updateTradeDays

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def updateTradeDays(self, dates):
        collection = self._getTradeDayTableCollection()

        # create index
        collection.create_index([('datetime', pymongo.ASCENDING)], unique=True)

        # update into DB
        try:
            for date in dates:
                flt = {'datetime': date['datetime']}
                result = collection.update_one(flt, {'$set':{'tradeDay': date['tradeDay']}}, upsert=True)
                if not (result.acknowledged and (result.matched_count == 1 or result.upserted_id is not None)):
                    self._info.print("更新交易日数据到MongoDB失败: date={}, raw_result={}".format(date, result.raw_result), DyLogData.error)
                    return False
        except Exception as ex:
            self._info.print("更新交易日数据到MongoDB异常: {}".format(str(ex) + ', ' + str(ex.details)), DyLogData.error)
            return False

        return True 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:21,代码来源:DyStockMongoDbEngine.py

示例7: updateStockCodes

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def updateStockCodes(self, codes):
        collection = self._getCodeTableCollection()

        # create index
        collection.create_index([('code', pymongo.ASCENDING)], unique=True)

        # update into DB
        try:
            for code in codes:
                flt = {'code': code['code']}
                collection.update_one(flt, {'$set':{'name': code['name']}}, upsert=True)

        except Exception as ex:
            self._info.print("更新股票代码数据到MongoDB异常:{0}".format(str(ex) + ', ' + str(ex.details)), DyLogData.error)
            return False

        return True 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:19,代码来源:DyStockMongoDbEngine.py

示例8: getStockMarketDate

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def getStockMarketDate(self, code, name=None):
        """
            获取个股上市日期
            由于数据库的数据限制,有可能是个股数据在数据库里的最早信息
        """
        collection = self._getStockDaysDb()[code]

        flt = {'datetime': {'$lt':datetime.now()}}

        try:
            cursor = collection.find(flt).sort('datetime', pymongo.ASCENDING).limit(1)
        except Exception as ex:
            self._info.print("MongoDB Exception({0}): @getStockMarketDate{1}:{2}, 日线数据".format(str(ex) + ', ' + str(ex.details),
                                                                                                    code, name),
                             DyLogData.error)
            return None

        for d in cursor:
            return d['datetime'].strftime('%Y-%m-%d')
        
        return None 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:23,代码来源:DyStockMongoDbEngine.py

示例9: updateSectorStockCodes

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def updateSectorStockCodes(self, sectorCode, date, codes):
        collection = self._client[self.sectorCodeDbMap[sectorCode]][date]

        # create index
        collection.create_index([('code', pymongo.ASCENDING)], unique=True)

        # update into DB
        try:
            for code in codes:
                flt = {'code': code['code']}
                collection.update_one(flt, {'$set': {'name': code['name']}}, upsert=True)

        except Exception as ex:
            self._info.print("更新[{0}]股票代码数据[{1}]到MongoDB异常:{2}".format(DyStockCommon.sectors[sectorCode], date, str(ex) + ', ' + str(ex.details)), DyLogData.error)
            return False

        return True 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:19,代码来源:DyStockMongoDbEngine.py

示例10: save_position

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def save_position(message, collection=DATABASE.positions):
    """save account

    Arguments:
        message {[type]} -- [description]

    Keyword Arguments:
        collection {[type]} -- [description] (default: {DATABASE})
    """
    try:
        collection.create_index(
            [("account_cookie", ASCENDING), ("portfolio_cookie", ASCENDING), ("user_cookie", ASCENDING), ("position_id", ASCENDING)], unique=True)
    except:
        pass
    collection.update(
        {'account_cookie': message['account_cookie'], 'position_id': message['position_id'],
            'portfolio_cookie': message['portfolio_cookie'], 'user_cookie': message['user_cookie']},
        {'$set': message},
        upsert=True
    ) 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:22,代码来源:save_position.py

示例11: save_account

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def save_account(message, collection=DATABASE.account):
    """save account

    Arguments:
        message {[type]} -- [description]

    Keyword Arguments:
        collection {[type]} -- [description] (default: {DATABASE})
    """
    try:
        collection.create_index(
            [("account_cookie", ASCENDING), ("user_cookie", ASCENDING), ("portfolio_cookie", ASCENDING)], unique=True)
    except:
        pass
    collection.update(
        {'account_cookie': message['account_cookie'], 'portfolio_cookie':
            message['portfolio_cookie'], 'user_cookie': message['user_cookie']},
        {'$set': message},
        upsert=True
    ) 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:22,代码来源:save_account.py

示例12: extract

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def extract(self): # TODO : Should be an exporter plugin
        graph = {
            'meta': {},  # self.__meta,
            'properties': {}  # self.__properties
        }

        graph['nodes'] = list()
        for v in self.__vertices.find().sort('id', pymongo.ASCENDING):
            v.pop("_id")  # Remove MongoDB document ID
            graph['nodes'].append(v)

        graph['edges'] = list()
        for e in self.__edges.find().sort("src", pymongo.ASCENDING):
            e.pop("_id")  # Remove MongoDB document ID
            graph['edges'].append(e)

        graph['tokens'] = list();
        for t in self.__tokens.find().sort('id', pymongo.ASCENDING):
            t.pop("_id")  # Remove MongoDB document ID
            t['id'] = str(t['id'])
            t['ts'] = time.mktime(t['ts'].timetuple())
            graph['tokens'].append(t)

        return graph 
开发者ID:opendns,项目名称:og-miner,代码行数:26,代码来源:mongo.py

示例13: get_data

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def get_data(self, symbol, start, end, symbol_in_column=True):
        """
        Returns a dataframe of the symbol data requested.
        """
        from pymongo import ASCENDING
        symbol = str(symbol).upper()
        results = self.database[symbol].find({'_id': \
                              {'$gte': start, '$lte': end}}\
                              ).sort('datetime', ASCENDING)
        ret = pd.DataFrame.from_dict(list(results))
        if len(ret) < 1:
            raise NoDataException()
        ret.rename(columns={'open': 'Open', \
                            'high': 'High', \
                            'low': 'Low', \
                            'close': 'Close', \
                            'volume': 'Volume', \
                            'adj_close': 'Adj Close', \
                            '_id': 'Date'}, \
                           inplace=True)
        ret = ret.set_index('Date')
        if symbol_in_column:
            ret.rename(columns=lambda name: '%s_%s' %(symbol, name), inplace=True)
        return ret 
开发者ID:edouardpoitras,项目名称:NowTrade,代码行数:26,代码来源:data_connection.py

示例14: _ensure_index

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def _ensure_index(self):
        collection = self._collection
        collection.create_index([(SYMBOL, pymongo.ASCENDING),
                                 (START, pymongo.ASCENDING)], background=True)
        collection.create_index([(START, pymongo.ASCENDING)], background=True)

        self._metadata.create_index([(SYMBOL, pymongo.ASCENDING)], background=True, unique=True) 
开发者ID:man-group,项目名称:arctic,代码行数:9,代码来源:tickstore.py

示例15: min_date

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import ASCENDING [as 别名]
def min_date(self, symbol):
        """
        Return the minimum datetime stored for a particular symbol

        Parameters
        ----------
        symbol : `str`
            symbol name for the item
        """
        res = self._collection.find_one({SYMBOL: symbol}, projection={ID: 0, START: 1},
                                        sort=[(START, pymongo.ASCENDING)])
        if res is None:
            raise NoDataFoundException("No Data found for {}".format(symbol))
        return utc_dt_to_local_dt(res[START]) 
开发者ID:man-group,项目名称:arctic,代码行数:16,代码来源:tickstore.py


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