-
Notifications
You must be signed in to change notification settings - Fork 25
/
dashboard.py
82 lines (56 loc) · 2.44 KB
/
dashboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import logging
import csv
import os
import StringIO
import urllib
from google.appengine.ext.webapp import RequestHandler
from .identity import can_control_experiments
from .cache import BingoCache
from .stats import describe_result_in_words
class Dashboard(RequestHandler):
def get(self):
if not can_control_experiments():
self.redirect("/")
return
path = os.path.join(os.path.dirname(__file__),
"templates/bootstrap.html")
f = None
try:
f = open(path, "r")
html = f.read()
finally:
if f:
f.close()
self.response.out.write(html)
class Export(RequestHandler):
def get(self):
if not can_control_experiments():
self.redirect("/")
return
bingo_cache = BingoCache.get()
canonical_name = self.request.get("canonical_name")
experiments, alternatives = bingo_cache.experiments_and_alternatives_from_canonical_name(canonical_name)
if not experiments:
raise Exception("No experiments matching canonical name: %s" % canonical_name)
f = StringIO.StringIO()
try:
writer = csv.writer(f, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["EXPERIMENT: %s" % canonical_name])
writer.writerow([])
writer.writerow([])
for experiment, alternatives in zip(experiments, alternatives):
writer.writerow(["CONVERSION NAME: %s" % experiment.conversion_name])
writer.writerow([])
writer.writerow(["ALTERNATIVE NUMBER", "CONTENT", "PARTICIPANTS", "CONVERSIONS", "CONVERSION RATE"])
for alternative in alternatives:
writer.writerow([alternative.number, alternative.content, alternative.participants, alternative.conversions, alternative.conversion_rate])
writer.writerow([])
writer.writerow(["SIGNIFICANCE TEST RESULTS: %s" % describe_result_in_words(alternatives)])
writer.writerow([])
writer.writerow([])
writer.writerow([])
self.response.headers["Content-Type"] = "text/csv"
self.response.headers["Content-Disposition"] = "attachment; filename=gae_bingo-%s.csv" % urllib.quote(canonical_name)
self.response.out.write(f.getvalue())
finally:
f.close()