def test_china_stock_reader(): data_reader = DataReader(codes=['002572', '000338'], data_schema=Stock1dKdata, provider='joinquant', start_timestamp='2019-01-01', end_timestamp='2019-06-10') categories = data_reader.get_categories() df = data_reader.get_data_df() assert 'stock_sz_002572' in categories assert 'stock_sz_000338' in categories assert ('stock_sz_002572', '2019-01-02') in df.index assert ('stock_sz_000338', '2019-01-02') in df.index assert ('stock_sz_002572', '2019-06-10') in df.index assert ('stock_sz_000338', '2019-06-10') in df.index for timestamp in iterate_timestamps(entity_type='stock', exchange='sz', level=IntervalLevel.LEVEL_1DAY, start_timestamp='2019-06-11', end_timestamp='2019-06-14'): data_reader.move_on(to_timestamp=timestamp, timeout=0) df = data_reader.get_data_df() assert ('stock_sz_002572', timestamp) in df.index assert ('stock_sz_000338', to_time_str(timestamp)) in df.index data_reader.data_drawer().draw_table() data_reader.data_drawer().draw_kline()
def update_data_table(n_clicks, provider, schema_name, columns, codes: str, start_date, end_date): if n_clicks and provider and columns and schema_name: # TODO:better way to get time_field if has_report_period(schema_name=schema_name): time_field = 'report_date' else: time_field = 'timestamp' data_reader = DataReader(data_schema=get_schema_by_name(schema_name), provider=provider, codes=codes, columns=columns, start_timestamp=start_date, end_timestamp=end_date, time_field=time_field) if data_reader.is_empty(): return 'no data,please reselect!', '', [{'label': 'compare_self', 'value': 'compare_self'}], 'compare_self' data_table = data_reader.data_drawer().draw_data_table(id='data_table_content') intents = data_reader.normal_data.get_intents() intent_options = [ {'label': intent.value, 'value': intent.value} for intent in intents ] intent_value = intents[0].value return data_table, data_reader.normal_data.get_table_type(), intent_options, intent_value raise dash.exceptions.PreventUpdate()
def update_table_and_graph(page_current, page_size, filter, chart, provider, schema_name, columns, codes, start_date, end_date): if provider and columns and schema_name and chart: if has_report_period(schema_name=schema_name): time_field = 'report_date' else: time_field = 'timestamp' schema = get_schema_by_name(schema_name) # <class 'list'>: ['{report_period} = year'] filters = None if filter: filters = [] print(filter) filtering_expressions = filter.split(' && ') for filter_part in filtering_expressions: col_name, operator, filter_value = split_filter_part(filter_part) s = f'schema.{col_name} {operator} "{filter_value}"' filter = eval(s) filters.append(filter) data_reader = DataReader(data_schema=schema, provider=provider, codes=codes, columns=columns, start_timestamp=start_date, end_timestamp=end_date, time_field=time_field, filters=filters) dff = data_reader.data_df.reset_index() graph_data, graph_layout = data_reader.data_drawer().draw(chart=chart, render=None) return dff.to_dict('records'), dcc.Graph( id='chart-content', figure={ 'data': graph_data, 'layout': graph_layout } ) raise dash.exceptions.PreventUpdate()
def test_reader_draw(): data_reader = DataReader(codes=['002572', '000338'], data_schema=Stock1dKdata, provider='joinquant', start_timestamp='2019-01-01', end_timestamp='2019-06-14') data_reader.data_drawer().draw_table() data_reader.data_drawer().draw_kline()