def composite_df(df): """ composite indicators(columns) of entity in df :param df: """ drawer = Drawer(main_df=df) drawer.draw_pie(show=True)
def show_industry_composition(entity_ids, timestamp): block_df = Block.query_data(provider='eastmoney', filters=[Block.category == 'industry'], index='entity_id') block_ids = block_df.index.tolist() block_df = BlockStock.query_data(entity_ids=block_ids, filters=[BlockStock.stock_id.in_(entity_ids)]) s = block_df['name'].value_counts() cycle_df = pd.DataFrame(columns=s.index, data=[s.tolist()]) cycle_df['entity_id'] = 'stock_cn_industry' cycle_df['timestamp'] = timestamp drawer = Drawer(main_df=cycle_df) drawer.draw_pie(show=True)
def composite_all(data_schema, column, timestamp, entity_ids=None, filters=None): if type(column) is not str: column = column.name if filters: filters.append([data_schema.timestamp == to_pd_timestamp(timestamp)]) else: filters = [data_schema.timestamp == to_pd_timestamp(timestamp)] df = data_schema.query_data(entity_ids=entity_ids, columns=['entity_id', 'timestamp', column], filters=filters, index='entity_id') entity_type, exchange, _ = decode_entity_id(df['entity_id'].iloc[0]) pie_df = pd.DataFrame(columns=df.index, data=[df[column].tolist()]) pie_df['entity_id'] = f'{entity_type}_{exchange}_{column}' pie_df['timestamp'] = timestamp drawer = Drawer(main_df=pie_df) drawer.draw_pie(show=True)
def show_industry_composition(entity_ids, timestamp): block_df = Block.query_data(provider="eastmoney", filters=[Block.category == "industry"], index="entity_id") block_ids = block_df.index.tolist() block_df = BlockStock.query_data( entity_ids=block_ids, filters=[BlockStock.stock_id.in_(entity_ids)]) s = block_df["name"].value_counts() cycle_df = pd.DataFrame(columns=s.index, data=[s.tolist()]) cycle_df["entity_id"] = "stock_cn_industry" cycle_df["timestamp"] = timestamp drawer = Drawer(main_df=cycle_df) drawer.draw_pie(show=True)
def composite(entity_id, data_schema, columns, filters=None): columns = ["entity_id", "timestamp"] + columns df = data_schema.query_data(entity_id=entity_id, columns=columns, filters=filters) drawer = Drawer(main_df=df) drawer.draw_pie(show=True)