def update_factor_details(factor, entity_type, code, levels): if factor and entity_type and code and levels: if type(levels) is list and len(levels) >= 2: levels.sort() drawers = [] for level in levels: drawers.append(zvt_context.factor_cls_registry[factor]( entity_schema=zvt_context.entity_schema_map[entity_type], level=level, codes=[code]).drawer()) stacked = StackedDrawer(*drawers) return dcc.Graph(id=f'{factor}-{entity_type}-{code}', figure=stacked.draw_kline(show=False, height=900)) else: if type(levels) is list: level = levels[0] else: level = levels return dcc.Graph( id=f'{factor}-{entity_type}-{code}', figure=zvt_context.factor_cls_registry[factor]( entity_schema=zvt_context.entity_schema_map[entity_type], level=level, codes=[code]).draw(show=False, height=600)) raise dash.PreventUpdate()
def update_factor_details(region: Region, factor, entity_type, entity, levels, columns, trader_index, schema_name): if factor and entity_type and entity and levels: sub_df = None # add sub graph if columns: if type(columns) == str: columns = [columns] columns = columns + ['entity_id', 'timestamp'] schema: Mixin = get_schema_by_name(name=schema_name) sub_df = schema.query_data(region=region, entity_id=entity, columns=columns) # add trading signals as annotation annotation_df = None if trader_index is not None: order_reader = order_readers[trader_index] annotation_df = order_reader.data_df.copy() annotation_df = annotation_df[annotation_df.entity_id == entity].copy() if pd_is_not_null(annotation_df): annotation_df['value'] = annotation_df['order_price'] annotation_df['flag'] = annotation_df['order_type'].apply( lambda x: order_type_flag(x)) annotation_df['color'] = annotation_df['order_type'].apply( lambda x: order_type_color(x)) print(annotation_df.tail()) if type(levels) is list and len(levels) >= 2: levels.sort() drawers = [] for level in levels: drawers.append(zvt_context.factor_cls_registry[factor]( entity_schema=zvt_context.entity_schema_map[entity_type], level=level, entity_ids=[entity]).drawer()) stacked = StackedDrawer(*drawers) return dcc.Graph(id=f'{factor}-{entity_type}-{entity}', figure=stacked.draw_kline(show=False, height=900)) else: if type(levels) is list: level = levels[0] else: level = levels drawer = zvt_context.factor_cls_registry[factor]( entity_schema=zvt_context.entity_schema_map[entity_type], level=level, entity_ids=[entity], need_persist=False).drawer() if pd_is_not_null(sub_df): drawer.add_sub_df(sub_df) if pd_is_not_null(annotation_df): drawer.annotation_df = annotation_df return dcc.Graph(id=f'{factor}-{entity_type}-{entity}', figure=drawer.draw_kline(show=False, height=800)) raise dash.PreventUpdate()
def update_factor_details(factor, entity_type, code, levels, columns, schema_name): if factor and entity_type and code and levels: sub_df = None if columns: if type(columns) == str: columns = [columns] columns = columns + ['entity_id', 'timestamp'] schema: Mixin = get_schema_by_name(name=schema_name) sub_df = schema.query_data(code=code, columns=columns) if type(levels) is list and len(levels) >= 2: levels.sort() drawers = [] for level in levels: drawers.append(zvt_context.factor_cls_registry[factor]( entity_schema=zvt_context.entity_schema_map[entity_type], level=level, codes=[code]).drawer()) stacked = StackedDrawer(*drawers) return dcc.Graph(id=f'{factor}-{entity_type}-{code}', figure=stacked.draw_kline(show=False, height=900)) else: if type(levels) is list: level = levels[0] else: level = levels drawer = zvt_context.factor_cls_registry[factor]( entity_schema=zvt_context.entity_schema_map[entity_type], level=level, codes=[code], need_persist=False).drawer() if pd_is_not_null(sub_df): drawer.add_sub_df(sub_df) return dcc.Graph(id=f'{factor}-{entity_type}-{code}', figure=drawer.draw_kline(show=False, height=800)) raise dash.PreventUpdate()