Exemplo n.º 1
0
def plot_cluster():
    """
    Generate the Cluster plot as a PNG

    Parameters
    ----------
    job_id: str
    x_axis: str
        Name of column from user dataset to be used for the x axis of the plot
    y_axis: str
        Name of column from user dataset to be used for the y axis of the plot

    Returns
    -------
    image/png
    """
    job_id = request.args.get('job_id')
    x_axis = request.args.get('x_axis')
    y_axis = request.args.get('y_axis')
    show_ticks = request.args.get('show_ticks', 'True') == 'True'
    min_members = int(request.args.get('min_members', None))
    plot_best = request.args.get('plot_best', 'True') == 'True'
    if job_id is None or x_axis is None or y_axis is None:
        return None
    best_tasks = tasks_to_best_results(job_id, min_members)
    viz_columns = [x_axis, y_axis]
    data = job_to_data(job_id)
    fig = plot_cluster_fig(data, viz_columns, best_tasks, show_ticks)
    cluster_plot = fig_to_png(fig)
    response = make_response(cluster_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 2
0
def plot_task():
    """
    Generate the Cluster plot with visualization options for a single task.

    Parameters
    ----------
    job_id: str
    task_id: str
    x_axis: str - column from the dataset to be used for plotting
    y_axis: str - column from the dataset to be used for plotting
    show_ticks: boolean
    Returns
    -------
    html
    """
    job_id = request.args.get('job_id')
    task_id = int(request.args.get('task_id'))
    x_axis = request.args.get('x_axis')
    y_axis = request.args.get('y_axis')
    show_ticks = request.args.get('show_ticks', 'True') == 'True'
    if job_id is None or task_id is None:
        return None
    data = job_to_data(job_id)
    task = db.session.query(Task).filter_by(job_id=job_id,
                                            task_id=task_id).first()
    viz_columns = get_viz_columns(
        db.session.query(Job).filter_by(job_id=job_id).first(), x_axis, y_axis)
    fig = plot_single_cluster_fig(data, viz_columns, task.labels, task.bic,
                                  task.k, show_ticks)
    cluster_plot = fig_to_png(fig)
    response = make_response(cluster_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 3
0
def plot_count():
    """
    Generate the Count plot as a PNG

    Parameters
    ----------
    job_id: str
    min_members: int, optional
        Minimum number of members required in all clusters in an experiment to consider the experiment for the report.

    Returns
    -------
    image/png
    """
    job_id = request.args.get('job_id', None)
    min_members = int(request.args.get('min_members', None))
    if job_id is None:
        return None
    tasks = mongo_get_tasks(job_id)
    if min_members is not None:
        tasks = filter_by_min_members(tasks, min_members)
    fig = plot_count_fig(tasks)
    count_plot = fig_to_png(fig)
    response = make_response(count_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 4
0
def plot_cluster():
    """
    Generate the Cluster plot as a PNG

    Parameters
    ----------
    job_id: str
    x_axis: str
        Name of column from user dataset to be used for the x axis of the plot
    y_axis: str
        Name of column from user dataset to be used for the y axis of the plot

    Returns
    -------
    image/png
    """
    job_id = request.args.get('job_id')
    x_axis = request.args.get('x_axis')
    y_axis = request.args.get('y_axis')
    show_ticks = request.args.get('show_ticks', 'True') == 'True'
    min_members = int(request.args.get('min_members', None))
    if job_id is None or x_axis is None or y_axis is None:
        return None

    job = mongo_get_job(job_id)
    tasks = mongo_get_tasks(job_id)

    if min_members is not None:
        tasks = filter_by_min_members(tasks, min_members)
    covar_types, covar_tieds, ks, labels, bics, task_ids = tasks_to_best_results(tasks)
    s3_file_key = job['s3_file_key']
    viz_columns = [x_axis, y_axis]
    data = s3_to_df(s3_file_key)
    fig = plot_cluster_fig(data, viz_columns, zip(covar_types, covar_tieds, labels, ks, bics), show_ticks)
    cluster_plot = fig_to_png(fig)
    response = make_response(cluster_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 5
0
def plot_correlation():
    """
    Generate the Correlation heat map as a PNG

    Parameters
    ----------
    job_id: str

    Returns
    -------
    image/png
    """

    job_id = request.args.get('job_id')
    if job_id is None:
        return None
    job = db.session.query(Job).filter_by(job_id=job_id).first()
    s3_file_key = job.s3_file_key
    data = s3_to_df(s3_file_key)
    fig = plot_correlation_fig(data)
    correlation_plot = fig_to_png(fig)
    response = make_response(correlation_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 6
0
def plot_count():
    """
    Generate the Count plot as a PNG

    Parameters
    ----------
    job_id: str
    min_members: int, optional
        Minimum number of members required in all clusters in an experiment to
        consider the experiment for the report.

    Returns
    -------
    image/png
    """
    job_id = request.args.get('job_id', None)
    if job_id is None:
        return None
    # TODO Compute min_members and save in the DB as a field.
    fig = plot_count_fig(job_id)
    count_plot = fig_to_png(fig)
    response = make_response(count_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 7
0
def plot_aic_bic():
    """
    Generate the AIC-BIC plot as a PNG

    Parameters
    ----------
    job_id: str
    min_members: int, optional
        Minimum number of members required in all clusters in an experiment to
        consider the experiment for the report.

    Returns
    -------
    image/png
    """
    job_id = request.args.get('job_id', None)
    if job_id is None:
        return None
    # TODO save min members for each task in the DB
    fig = plot_aic_bic_fig(job_id)
    aic_bic_plot = fig_to_png(fig)
    response = make_response(aic_bic_plot.getvalue())
    response.mimetype = 'image/png'
    return response
Exemplo n.º 8
0
def plot_correlation():
    """
    Generate the Correlation heat map as a PNG

    Parameters
    ----------
    job_id: str

    Returns
    -------
    image/png
    """

    job_id = request.args.get('job_id')
    if job_id is None:
        return None
    job = mongo_get_job(job_id)
    s3_file_key = job['s3_file_key']
    data = s3_to_df(s3_file_key)
    fig = plot_correlation_fig(data)
    correlation_plot = fig_to_png(fig)
    response = make_response(correlation_plot.getvalue())
    response.mimetype = 'image/png'
    return response