Ejemplo n.º 1
0
def create_plot(request, project_id):
    """ Create a new Plot.

    """
    project = get_object_or_404(Project, pk=project_id)
    form = PlotForm(request.POST or None)
    if form.is_valid():
        new_plot = form.save(commit=False) # returns unsaved instance
        new_plot.project = project
        new_plot.save() # real save to DB.
        messages.add_message(request, messages.SUCCESS, 'The plot has been successfully created.')
        return redirect(details_project, project_id=project_id)
    return render_to_response('form.html',
                              {'form'    : form,
                               'project' : project},
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def edit_plot(request, plot_id):
    """ Edit a plot.

    """
    plot = get_object_or_404(Plot, pk=plot_id)
    if request.method == "POST":
        form = PlotForm(request.POST, instance=plot)
    else:
        form = PlotForm(instance=plot)
    if form.is_valid(): # All validation rules pass
        form.save()
        messages.add_message(request, messages.INFO, 'The plot has been successfully modified.')
        return redirect(details_plot, plot_id=plot_id)

    return render_to_response('form.html',
                              {'form'    : form,
                               'project' : plot.project},
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
def create_plot(request, project_id):
    """ Create a new Plot.

    """
    project = get_object_or_404(Project, pk=project_id)
    form = PlotForm(request.POST or None)
    if form.is_valid():
        new_plot = form.save(commit=False)  # returns unsaved instance
        new_plot.project = project
        new_plot.save()  # real save to DB.
        messages.add_message(request, messages.SUCCESS,
                             'The plot has been successfully created.')
        return redirect(details_project, project_id=project_id)
    return render_to_response('form.html', {
        'form': form,
        'project': project
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def plot(request, conn=None, **kwargs):
    annotation_id = request.session['annotation_id']
    annotation = conn.getObject("Annotation",annotation_id)
    fpath = download_annotation(annotation)
    header_row = request.session['header']
    sheet = request.session['sheet']
    fname, fextension = os.path.splitext(fpath)
    cols,message,csv_path = parse_annotation(fpath,fextension,header_row,sheet)
    if request.POST:
        form = PlotForm(options=cols,data=request.POST.copy())
        if form.is_valid():
            title = annotation.getFile().getName()
            if form.cleaned_data['title']:
                title = form.cleaned_data['title']
            x = form.cleaned_data['x_data']
            y = form.cleaned_data['y_data']
            print 'first y',y
            xLabel = x
            if form.cleaned_data['x_Label']:
                xLabel = form.cleaned_data['x_Label']
            yLabel = y
            if form.cleaned_data['y_Label']:
                yLabel = form.cleaned_data['y_Label']
            #tick_size = form.cleaned_data['tick_size']
            plot_mode = form.cleaned_data['plot_mode']
            xdata = [floor(xd) for xd in get_column(fpath,fextension,x,header_row,sheet)]
            xmin = min(xdata)
            xmax = max(xdata)
            ydata = get_column(fpath,fextension,y,header_row,sheet)
            #graph = flot_data(xdata,ydata)
            #d3data = d3_data(xdata,ydata)
            rv = {'message': message,\
                  'title': title, 'x' : x, 'y' : y,\
                  'xLabel': xLabel, 'yLabel': yLabel,\
                  'xdata': xdata, 'ydata': ydata,\
                  'num_series': len(ydata),'plot_mode':plot_mode,\
                  'xmin': xmin, 'xmax': xmax,'csv_path': csv_path}
            data = json.dumps(rv)
            return HttpResponse(data, mimetype='application/json')
Ejemplo n.º 5
0
def form_prefill():
    form = PlotForm()
    parameters = Params()
    # transform to list by removing 'set' (doesn't work for python 2.7)
    parameters.lines = set(ast.literal_eval(request.args.get('lines')[3:]))
    parameters.R = ast.literal_eval(request.args.get('R'))
    parameters.ymin = ast.literal_eval(request.args.get('ymin'))
    parameters.K = ast.literal_eval(request.args.get('K'))
    parameters.highpt = ast.literal_eval(request.args.get('highpt'))
    parameters.narrowband = ast.literal_eval(request.args.get('narrowband'))
    # set the form values
    form.choice_lines.data = list(parameters.lines)
    form.choice_R.data = str(parameters.R)
    form.choice_rap.data = '%1.1f' % (parameters.ymin)
    form.choice_K.data = '%1.2f' % (parameters.K)
    if parameters.highpt:
        form.choice_ptbin.data = 'highpt'
    else:
        form.choice_ptbin.data = 'fullpt'
    if parameters.narrowband:
        form.choice_scalevar = 'correl'
    else:
        form.choice_scalevar = 'uncorrel'
    return render_template('index.html', form=form, params=parameters)
Ejemplo n.º 6
0
def main():
    form = PlotForm()
    parameters = Params()
    for line in all_lines:
        if line in form.choice_lines.data:
            parameters.lines.add(line)
        else:
            parameters.lines.discard(line)
    parameters.R = float(form.choice_R.data)
    parameters.ymin = float(form.choice_rap.data)
    parameters.K = float(form.choice_K.data)
    if form.choice_ptbin.data == 'highpt':
        parameters.highpt = True
    else:
        parameters.highpt = False
    if form.choice_scalevar.data == 'correl':
        parameters.narrowband = True
    else:
        parameters.narrowband = False
    return render_template('index.html', form=form, params=parameters)
Ejemplo n.º 7
0
def edit_plot(request, plot_id):
    """ Edit a plot.

    """
    plot = get_object_or_404(Plot, pk=plot_id)
    if request.method == "POST":
        form = PlotForm(request.POST, instance=plot)
    else:
        form = PlotForm(instance=plot)
    if form.is_valid():  # All validation rules pass
        form.save()
        messages.add_message(request, messages.INFO,
                             'The plot has been successfully modified.')
        return redirect(details_plot, plot_id=plot_id)

    return render_to_response('form.html', {
        'form': form,
        'project': plot.project
    },
                              context_instance=RequestContext(request))