__init__.py 2.27 KB
Newer Older
Zixian Cai's avatar
Zixian Cai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Zixian Cai's avatar
Zixian Cai committed
16
from flask import Flask, render_template, request, flash, redirect, url_for
Zixian Cai's avatar
Zixian Cai committed
17
from mubench.conf import settings
Zixian Cai's avatar
Zixian Cai committed
18
from mubench.frontend.utils import group_stats_result
Zixian Cai's avatar
Zixian Cai committed
19
from mubench.frontend.web import changes, timeline
20
from mubench.frontend.web.storage import LocalStorage as storage
Zixian Cai's avatar
Zixian Cai committed
21
import click
Zixian Cai's avatar
Zixian Cai committed
22
import json
Zixian Cai's avatar
Zixian Cai committed
23 24 25

app = Flask(__name__)
app.config['SECRET_KEY'] = settings.WEB_SECRET
Zixian Cai's avatar
Zixian Cai committed
26
app.config['APPLICATION_ROOT'] = settings.WEB_APPLICATION_ROOT
Zixian Cai's avatar
Zixian Cai committed
27 28


29 30
@app.route("/visualize_file", methods=["POST"])
def visualize_file():
Zixian Cai's avatar
Zixian Cai committed
31 32 33 34 35
    if "logfile" not in request.files:
        flash("No log file uploaded")
        return redirect(url_for("index"))
    logfile = request.files["logfile"]
    result = json.loads(logfile.read())
Zixian Cai's avatar
Zixian Cai committed
36
    group_stats_result(result)
Zixian Cai's avatar
Zixian Cai committed
37
    return render_template("visualize.html", result=result)
Zixian Cai's avatar
Zixian Cai committed
38 39


Zixian Cai's avatar
Zixian Cai committed
40 41 42 43 44
@app.route("/tools")
def tools():
    return render_template("tools.html")


Zixian Cai's avatar
Zixian Cai committed
45 46
@app.route("/")
def index():
Zixian Cai's avatar
Zixian Cai committed
47 48 49
    repo, host = settings.WEB_POI_REPO, settings.WEB_POI_HOST
    result = storage.load_relative(repo, host, 0)
    result1 = storage.load_relative(repo, host, 1)
Zixian Cai's avatar
Zixian Cai committed
50
    result2 = storage.load_all(repo, host)
Zixian Cai's avatar
Zixian Cai committed
51
    tl, tl_revisions = timeline.make_timeline(result2)
Zixian Cai's avatar
Zixian Cai committed
52 53
    return render_template("index.html",
                           visualzing=result,
54
                           changes=changes.compare(result, result1),
Zixian Cai's avatar
Zixian Cai committed
55 56
                           timeline=tl,
                           timeline_revisions=tl_revisions)
Zixian Cai's avatar
Zixian Cai committed
57 58 59


@click.command()
Zixian Cai's avatar
Zixian Cai committed
60 61 62
@click.option("--host", default=settings.WEB_HOST)
@click.option("--port", default=settings.WEB_PORT, type=int)
@click.option("--debug", default=settings.WEB_DEBUG, is_flag=True)
Zixian Cai's avatar
Zixian Cai committed
63 64
def web(host, port, debug):
    app.run(host=host, port=port, debug=debug)