コード例 #1
0
def visualize():
    """
    Visualize route
    """

    if request.method == "GET":
        choose_data = config.get_datafiles()
        return render_template("visualize.html", choose_data=choose_data)
    elif request.method == "POST":
        try:
            shutil.rmtree("static/visualize")
            print(">>> Removed folder: visualized")
        except Exception as e:
            print("No such folder: ", e)

        data_for_timeline = collections.OrderedDict()
        month_names = []
        hotspots = []
        hotspot = {}
        conflevel = request.form["setupConfidenceLevel"]

        months = calendar.month_name
        dates = [
            "", "2014-01", "2014-02", "2014-03", "2014-04", "2014-05",
            "2014-06", "2014-07", "2014-08", "2014-09", "2014-10", "2014-11",
            "2014-12"
        ]
        empty_hotspots = []
        splitted_months = functions.split_csv(request.form["setupData"])
        for mon in range(1, 13):
            hotspot = Visual(request.form["setupData"], months[mon], conflevel,
                             units)
            hotspot.getis, hotspot.conf_levels = functions.calculate_hotspot(
                hotspot, splitted_months[mon - 1]["data"], "getis")

            data_for_timeline[months[mon]] = hotspot.getis

            functions.save_csv(hotspot.getis, "static/visualize/",
                               hotspot.title, ".csv")
            # Creates the getis hotspot
            getis_hotspot = functions.create_hotspot(hotspot, "getis_visual",
                                                     hotspot.pvalue)
            # Save getis hotspot as png
            functions.save_figure(getis_hotspot, "static/visualize/",
                                  hotspot.title, ".png")

            month_names.append(months[mon])
            # hotspots.append(hotspot)

        # Timeline takes a list of dataFrames
        timeline = Timeline(data_for_timeline)
        timeline.calculate_total()
        timeline.calculate_percentage()
        timeline_result = timeline.create_timeline()

        functions.save_figure(timeline_result, "static/visualize/", "timeline",
                              ".png")

        return render_template("visualize.html",
                               months=month_names,
                               csvfile=request.form["setupData"],
                               conf=conflevel,
                               time="?" + str(time.time()))