Exemplo n.º 1
0
def graph(request):
    if request.GET:
        x_data = json.loads(request.GET.get("x"))
        y_data = json.loads(request.GET.get("y"))
    else:
        x_data, y_data = ([1, 2, 3, 4], [10, 1, 5, 3])

    graph_data = [x_data, y_data]
    graph_content = scatter_to_base64(graph_data)
    object = {"image_source": graph_content}
    generate_and_save_graph_image.delay(graph_data)
    return HttpResponse(json.dumps(object), content_type="application/json")
Exemplo n.º 2
0
def graph_view(request):
    if request.GET:
        x_data = json.loads(request.GET.get("x"))
        y_data = json.loads(request.GET.get("y"))
    else:
        x_data, y_data = ([1, 2, 3, 4], [10, 1, 5, 3])

    graph_data = [x_data, y_data]

    graph = Graph.objects.filter(data=str(graph_data))
    if not graph:
        graph_content = scatter_to_base64(graph_data)
        generate_and_save_graph_image.delay(graph_data)
    else:
        graph_content = graph.get().content

    return render_to_response("base.html", {"graph": graph_content})
Exemplo n.º 3
0
def graph_view_matplot_lib(request):
    graph_one = scatter_to_base64(([1, 2, 3, 4], [10, 1, 5, 3]))
    graph_two = scatter_to_base64(([1, 2, 3, 4], [1, 1, 1, 5]))
    return render_to_response("base.html", {"graph_one": graph_one, "graph_two": graph_two})
Exemplo n.º 4
0
def generate_and_save_graph_image(data):
    time.sleep(10)
    base64_string = scatter_to_base64(data)
    Graph.objects.create(content=base64_string, data=str(data))
    return True