Esempio n. 1
0
def QA_fetch_stock_block_adv(code=None, blockname=None, collections=DATABASE.stock_block):
    '''
    返回板块 ❌
    :param code:
    :param blockname:
    :param collections: 默认数据库 stock_block
    :return: QA_DataStruct_Stock_block
    '''
    if code is not None and blockname is None:
        # 返回这个股票代码所属的板块
        data = pd.DataFrame([item for item in collections.find(
            {'code': {'$in': code}})])
        data = data.drop(['_id'], axis=1)

        return QA_DataStruct_Stock_block(data.set_index(['blockname', 'code'], drop=True).drop_duplicates())
    elif blockname is not None and code is None:
        #
        # 🛠 todo fnished 返回 这个板块所有的股票
        # 返回该板块所属的股票
        # print("QA Error blockname is Not none code none, return all code from its block name have not implemented yet !")

        items_from_collections = [item for item in collections.find(
            {'blockname': re.compile(blockname)})]
        data = pd.DataFrame(items_from_collections).drop(['_id'], axis=1)
        data_set_index = data.set_index(['blockname', 'code'], drop=True)
        return QA_DataStruct_Stock_block(data_set_index)

    else:
        # 🛠 todo 返回 判断 这个股票是否和属于该板块
        data = pd.DataFrame(
            [item for item in collections.find()]).drop(['_id'], axis=1)
        data_set_index = data.set_index(['blockname', 'code'], drop=True)
        return QA_DataStruct_Stock_block(data_set_index)
Esempio n. 2
0
def QA_fetch_stock_block_adv(code=None,
                             blockname=None,
                             collections=DATABASE.stock_block):
    '''
    返回板块
    :param code:
    :param blockname:
    :param collections: 默认数据库 stock_block
    :return:
    '''
    if code is not None and blockname is None:
        # 根据代码 和 板块名称 查找
        data = pd.DataFrame(
            [item for item in collections.find({'code': code})]).drop(['_id'],
                                                                      axis=1)
        return QA_DataStruct_Stock_block(
            data.set_index('code', drop=False).drop_duplicates())
    elif blockname is not None and code is None:
        # 板块名称 查找
        data = pd.DataFrame([
            item
            for item in collections.find({'blockname': re.compile(blockname)})
        ]).drop(['_id'], axis=1)
    else:
        # ??
        data = pd.DataFrame([item
                             for item in collections.find()]).drop(['_id'],
                                                                   axis=1)
        return QA_DataStruct_Stock_block(
            data.set_index('code', drop=False).drop_duplicates())
Esempio n. 3
0
def QA_fetch_stock_block_adv(code=None,
                             blockname=None,
                             collections=DATABASE.stock_block):
    """返回板块

    Keyword Arguments:
        code {[type]} -- [description] (default: {None})
        blockname {[type]} -- [descrioption] (default : {None})
        collections {[type]} -- [description] (default: {DATABASE})

    Returns:
        [type] -- [description]
    """

    if code is not None and blockname is None:
        data = pd.DataFrame(
            [item for item in collections.find({'code': code})]).drop(['_id'],
                                                                      axis=1)
        return QA_DataStruct_Stock_block(
            data.set_index('code', drop=False).drop_duplicates())
    elif blockname is not None and code is None:

        data = pd.DataFrame([
            item
            for item in collections.find({'blockname': re.compile(blockname)})
        ]).drop(['_id'], axis=1)
    else:
        data = pd.DataFrame([item
                             for item in collections.find()]).drop(['_id'],
                                                                   axis=1)
        return QA_DataStruct_Stock_block(
            data.set_index('code', drop=False).drop_duplicates())
Esempio n. 4
0
def QA_fetch_stock_block_adv(code=None, collections=QA_Setting.client.quantaxis.stock_block):
    if code is not None:
        data = pd.DataFrame([item for item in collections.find(
            {'code': code})]).drop(['_id'], axis=1)
        return QA_DataStruct_Stock_block(data.set_index('code', drop=False).drop_duplicates())
    else:
        data = pd.DataFrame([item for item in collections.find()]).drop(['_id'], axis=1)
        return QA_DataStruct_Stock_block(data.set_index('code', drop=False).drop_duplicates())
Esempio n. 5
0
def QA_fetch_stock_block_adv(code=None,
                             blockname=None,
                             collections=DATABASE.stock_block):
    '''
    返回板块 ❌
    :param code:
    :param blockname: 为list时模糊查询多版块交集
    :param collections: 默认数据库 stock_block
    :return: QA_DataStruct_Stock_block
    '''
    if isinstance(blockname, (list, )) and len(blockname) > 0:
        reg_join = "|".join(blockname)
        df = DataFrame([i for i in collections.aggregate([ \
            {"$match": {"blockname": {"$regex": reg_join}}}, \
            {"$group": {"_id": "$code", "count": {"$sum": 1}, "blockname": {"$push": "$blockname"}}}, \
            {"$match": {"count": {"$gte": len(blockname)}}}, \
            {"$project": {"code": "$_id", "blockname": 1, "_id": 0, }}, \
            ])])
        df.blockname = df.blockname.apply(lambda x: ",".join(x))
        return QA_DataStruct_Stock_block(
            df.set_index(["blockname", "code"], drop=False))
    elif code is not None and blockname is None:
        # 返回这个股票代码所属的板块
        data = pd.DataFrame(
            [item for item in collections.find({'code': {
                '$in': code
            }})])
        data = data.drop(['_id'], axis=1)

        return QA_DataStruct_Stock_block(
            data.set_index(['blockname', 'code'], drop=True).drop_duplicates())
    elif blockname is not None and code is None:
        #
        # 🛠 todo fnished 返回 这个板块所有的股票
        # 返回该板块所属的股票
        # print("QA Error blockname is Not none code none, return all code from its block name have not implemented yet !")

        items_from_collections = [
            item
            for item in collections.find({'blockname': re.compile(blockname)})
        ]
        data = pd.DataFrame(items_from_collections).drop(['_id'], axis=1)
        data_set_index = data.set_index(['blockname', 'code'], drop=True)
        return QA_DataStruct_Stock_block(data_set_index)

    else:
        # 🛠 todo 返回 判断 这个股票是否和属于该板块
        data = pd.DataFrame([item
                             for item in collections.find()]).drop(['_id'],
                                                                   axis=1)
        data_set_index = data.set_index(['blockname', 'code'], drop=True)
        return QA_DataStruct_Stock_block(data_set_index)