Ejemplo n.º 1
0
def test_make_timeout_request():
    class MockProcess(object):
        def __init__(self, target=None, args=None, kwargs=None):
            pass

        def start(self):
            pass

        def join(self, timeout=None):
            pass

        def is_alive(self):
            return True

        def terminate(self):
            pass

    with mock.patch('dtale.utils.Process', mock.Mock(side_effect=MockProcess)):
        with pytest.raises(Exception) as error:
            utils.make_timeout_request(utils.dict_merge, args=({}, {}))
    print(str(error.value))
    assert str(error.value).endswith('Request took longer than 60 seconds. Please try adding additional filtering...')
Ejemplo n.º 2
0
def build_chart(data_id=None, **inputs):
    """
    Factory method that forks off into the different chart building methods (heatmaps are handled separately)
        - line
        - bar
        - scatter
        - pie
        - wordcloud
        - 3D scatter
        - surface

    :param data_id: identifier of data to build axis configurations against
    :type data_id: str
    :param inputs: Optional keyword arguments containing the following information:
        - x: column to be used as x-axis of chart
        - y: column to be used as y-axis of chart
        - z: column to use for the Z-Axis
        - agg: points to a specific function that can be applied to :func: pandas.core.groupby.DataFrameGroupBy
    :return: plotly chart object(s)
    :rtype: type of (:dash:`dash_core_components.Graph <dash-core-components/graph>`, dict)
    """
    try:
        if inputs.get('chart_type') == 'heatmap':
            data = make_timeout_request(threaded_heatmap_builder,
                                        kwargs=dict_merge(
                                            dict(data_id=data_id), inputs))
            data = data.pop()
            return data, None

        data = make_timeout_request(threaded_build_figure_data,
                                    kwargs=dict_merge(dict(data_id=data_id),
                                                      inputs))
        data = data.pop()
        if data is None:
            return None, None

        if 'error' in data:
            return build_error(data['error'], data['traceback']), None

        range_data = dict(min=data['min'], max=data['max'])
        axis_inputs = inputs.get('yaxis', {})
        chart_builder = chart_wrapper(data_id, data, inputs)
        chart_type, x, y, z, agg = (
            inputs.get(p) for p in ['chart_type', 'x', 'y', 'z', 'agg'])
        z = z if chart_type in ZAXIS_CHARTS else None
        chart_inputs = {
            k: v
            for k, v in inputs.items()
            if k not in ['chart_type', 'x', 'y', 'z', 'group']
        }

        if chart_type == 'wordcloud':
            return (chart_builder(
                dash_components.Wordcloud(id='wc',
                                          data=data,
                                          y=y,
                                          group=inputs.get('group'))),
                    range_data)

        axes_builder = build_axes(data_id,
                                  x,
                                  axis_inputs,
                                  data['min'],
                                  data['max'],
                                  z=z,
                                  agg=agg)
        if chart_type == 'scatter':
            if inputs['cpg']:
                scatter_charts = flatten_lists([
                    scatter_builder(data,
                                    x,
                                    y,
                                    axes_builder,
                                    chart_builder,
                                    group=group,
                                    agg=agg) for group in data['data']
                ])
            else:
                scatter_charts = scatter_builder(data,
                                                 x,
                                                 y,
                                                 axes_builder,
                                                 chart_builder,
                                                 agg=agg)
            return cpg_chunker(scatter_charts), range_data

        if chart_type == '3d_scatter':
            return scatter_builder(data,
                                   x,
                                   y,
                                   axes_builder,
                                   chart_builder,
                                   z=z,
                                   agg=agg), range_data

        if chart_type == 'surface':
            return surface_builder(data,
                                   x,
                                   y,
                                   z,
                                   axes_builder,
                                   chart_builder,
                                   agg=agg), range_data

        if chart_type == 'bar':
            return bar_builder(data, x, y, axes_builder, chart_builder,
                               **chart_inputs), range_data

        if chart_type == 'line':
            return line_builder(data, x, y, axes_builder, chart_builder,
                                **chart_inputs), range_data

        if chart_type == 'pie':
            return pie_builder(data, x, y, chart_builder,
                               **chart_inputs), range_data
        raise NotImplementedError('chart type: {}'.format(chart_type))
    except BaseException as e:
        return build_error(str(e), str(traceback.format_exc())), None