ability to cache images on hard drive added
diff --git a/chart/charts.py b/chart/charts.py
index d4ecfae..ec2a86f 100644
--- a/chart/charts.py
+++ b/chart/charts.py
@@ -111,7 +111,6 @@
line.color(*COLORS[:len(legend)])
line.size(width, height)
- import pdb;pdb.set_trace()
img_name = hashlib.md5(str(line)).hexdigest() + ".png"
img_path = os.path.join(CHARTS_IMG_PATH, img_name)
diff --git a/config.py b/config.py
index 3ee6f20..b92385e 100644
--- a/config.py
+++ b/config.py
@@ -8,4 +8,4 @@
DEFAULT_FILE_PATH = "test.json"
OUTPUT_FILE = "output.json"
TEST_PATH = os.environ.get("TEST_PATH", os.path.dirname(__file__) + "/test_results")
-CHARTS_IMG_PATH = "images"
+CHARTS_IMG_PATH = "static/images"
diff --git a/web_app/__init__.py b/web_app/__init__.py
index 00c1084..ad2fe42 100644
--- a/web_app/__init__.py
+++ b/web_app/__init__.py
@@ -1,5 +1,5 @@
from urlparse import urlparse
-from flask import Flask, render_template, url_for, request, g
+from flask import Flask, render_template, url_for, request, g, make_response
from flask_bootstrap import Bootstrap
from config import TEST_PATH
from report import build_vertical_bar, build_lines_chart
@@ -8,6 +8,7 @@
import json
import os.path
+import math
from web_app.keystone import KeystoneAuth
app = Flask(__name__)
@@ -50,6 +51,25 @@
return result
+def mean(l):
+ n = len(l)
+
+ return sum(l) / n
+
+
+def stdev(l):
+ m = mean(l)
+ return math.sqrt(sum(map(lambda x: (x - m) ** 2, l)))
+
+
+def prepare_build_data(build):
+ for item in build.items():
+ if type(item[1]) is list:
+ m = mean(item[1])
+ s = stdev(item[1])
+ build[item[0]] = [m, s]
+
+
def collect_builds():
builds = []
build_set = set()
@@ -63,6 +83,9 @@
build_set.add(build["type"])
builds.append(build)
+ for build in builds:
+ prepare_build_data(build)
+
return builds
@@ -169,6 +192,18 @@
return render_template("index.html", tests=data)
+@app.route("/images/<image_name>")
+def get_image(image_name):
+ with open("static/images/" + image_name, 'rb') as f:
+ image_binary = f.read()
+
+ response = make_response(image_binary)
+ response.headers['Content-Type'] = 'image/png'
+ response.headers['Content-Disposition'] = 'attachment; filename=img.png'
+
+ return response
+
+
@app.route("/tests/<test_name>", methods=['GET'])
def render_test(test_name):
tests = []
@@ -197,6 +232,9 @@
bars = build_vertical_bar(results)
lines = build_lines_chart(results)
urls = bars + lines
+
+ urls = [url_for("get_image", image_name=os.path.basename(url)) if not url.startswith('http') else url for url in urls]
+
if len(tests) > 0:
sorted_keys = sorted(tests[0].keys())