r87800 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87799‎ | r87800 | r87801 >
Date:00:12, 10 May 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
- add comment functionality
- autogen method for generating reports
Modified paths:
  • /trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/tests/urls.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/tests/views.py (modified) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/tests/views.py
@@ -1,4 +1,4 @@
2 -from django.shortcuts import render_to_response
 2+from django.shortcuts import render_to_response, redirect
33 from django.http import Http404
44 from django.shortcuts import render_to_response, get_object_or_404
55 from django.template import RequestContext
@@ -6,38 +6,38 @@
77 from django.core.urlresolvers import reverse
88
99 import sys
10 -# sys.path.append('/home/rfaulkner/trunk/projects/')
11 -# sys.path.append('/home/rfaulkner/trunk/projects/Fundraiser_Tools/classes')
12 -
1310 import math
1411 import os
 12+import getopt
 13+import re
 14+import datetime
1515
1616 import Fundraiser_Tools.classes.Helper as Hlp
1717 import Fundraiser_Tools.classes.DataLoader as DL
 18+import Fundraiser_Tools.classes.DataReporting as DR
 19+import Fundraiser_Tools.classes.FundraiserDataHandler as FDH
1820 import Fundraiser_Tools.classes.TimestampProcessor as TP
1921 import Fundraiser_Tools.settings as projSet
20 -import Fundraiser_Tools.build_report as br
2122 import operator
2223
2324
2425 """
25 - <description>
 26+ Index page for tests ... lists all existing tests and allows a new test to be run
 27+"""
 28+def index(request):
2629
27 - INPUT:
 30+ ttl = DL.TestTableLoader()
 31+ test_rows = ttl.get_all_test_rows()
2832
29 - RETURN:
 33+ return render_to_response('tests/index.html', {'test_rows' : test_rows}, context_instance=RequestContext(request))
3034
31 -"""
32 -def index(request):
33 - return render_to_response('tests/index.html', context_instance=RequestContext(request))
3435
 36+
 37+
 38+
3539 """
36 - <description>
 40+ Executes a test, builds a report, and adds it to the test table
3741
38 - INPUT:
39 -
40 - RETURN:
41 -
4242 """
4343 def test(request):
4444
@@ -51,18 +51,30 @@
5252 utm_campaign_var = request.POST['utm_campaign']
5353 start_time_var = request.POST['start_time']
5454 end_time_var = request.POST['end_time']
55 - test_type = request.POST['test_type']
5655
57 - labels = request.POST['artifacts'][1:-1].split(',')
 56+ try:
 57+ test_type_var = request.POST['test_type']
 58+ labels = request.POST['artifacts']
 59+
 60+
 61+ except KeyError as e:
 62+
 63+ os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/classes')
 64+ test_type_var, labels = FDH.get_test_type(utm_campaign_var, start_time_var, end_time_var)
 65+ os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/web_reporting')
 66+
 67+ labels = labels.__str__()
 68+
 69+ labels = labels[1:-1].split(',')
5870 label_dict = dict()
59 -
 71+
6072 for i in range(len(labels)):
6173 label = labels[i].split('\'')[1]
6274 label = label.strip()
6375 label_dict[label] = label
64 -
65 - except:
6676
 77+ except KeyError as e:
 78+ """ flag an error here for the user """
6779 return HttpResponseRedirect(reverse('tests.views.index'))
6880 # pass
6981
@@ -81,22 +93,22 @@
8294
8395 os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/web_reporting')
8496
85 - metric_names = Hlp.get_test_type_metrics(test_type)
 97+ metric_types = FDH.get_test_type_metrics(test_type_var)
8698
87 - if test_type == 'banner':
 99+ if test_type_var == FDH._TESTTYPE_BANNER_:
88100
89 - winner_dpi, percent_win_dpi, conf_dpi, winner_api, percent_win_api, conf_api = br.auto_gen(test_name=test_name_var, start_time_var, end_time_var, utm_campaign_var, label_dict, 2, test_interval)
 101+ winner_dpi, percent_win_dpi, conf_dpi, winner_api, percent_win_api, conf_api = auto_gen(test_name_var, start_time_var, end_time_var, utm_campaign_var, label_dict, 2, test_interval, test_type_var, metric_types)
90102
91 - html = render_to_response('tests/results.html', {'winner' : winner_dpi, 'percent_win_dpi' : '%.2f' % percent_win_dpi, 'percent_win_api' : '%.2f' % percent_win_api, 'conf_dpi' : conf_dpi, 'conf_api' : conf_api, 'utm_campaign' : utm_campaign_var, \
92 - 'metric_names' : metric_names})
93 - elif test_type == 'LP':
 103+ html = render_to_response('tests/results_' + FDH._TESTTYPE_BANNER_ + '.html', {'winner' : winner_dpi, 'percent_win_dpi' : '%.2f' % percent_win_dpi, 'percent_win_api' : '%.2f' % percent_win_api, 'conf_dpi' : conf_dpi, 'conf_api' : conf_api, 'utm_campaign' : utm_campaign_var, \
 104+ 'metric_names' : metric_types}, context_instance=RequestContext(request))
 105+ elif test_type_var == FDH._TESTTYPE_LP_:
94106
95 - winner_dpi, percent_win_dpi, conf_dpi, winner_api, percent_win_api, conf_api = br.auto_gen(test_name=test_name_var, start_time_var, end_time_var, utm_campaign_var, label_dict, 2, test_interval)
 107+ winner_dpv, percent_win_dpv, conf_dpv, winner_apv, percent_win_apv, conf_apv = auto_gen(test_name_var, start_time_var, end_time_var, utm_campaign_var, label_dict, 2, test_interval, test_type_var, metric_types)
96108
97 - html = render_to_response('tests/results.html', {'winner' : winner_dpi, 'percent_win_dpi' : '%.2f' % percent_win_dpi, 'percent_win_api' : '%.2f' % percent_win_api, 'conf_dpi' : conf_dpi, 'conf_api' : conf_api, 'utm_campaign' : utm_campaign_var, \
98 - 'metric_names' : metric_names})
99 -
100 - """ Write to test table !! MODIFY -- handle updates !! """
 109+ html = render_to_response('tests/results_' + FDH._TESTTYPE_LP_ + '.html', {'winner' : winner_dpv, 'percent_win_dpv' : '%.2f' % percent_win_dpv, 'percent_win_apv' : '%.2f' % percent_win_apv, 'conf_dpv' : conf_dpv, 'conf_apv' : conf_apv, 'utm_campaign' : utm_campaign_var, \
 110+ 'metric_names' : metric_types}, context_instance=RequestContext(request))
 111+
 112+ """ Write to test table """
101113
102114 ttl = DL.TestTableLoader()
103115
@@ -104,17 +116,168 @@
105117 html_string = html.__str__()
106118 html_string = html_string.replace('"', '\\"')
107119 html_string = Hlp.stringify(html_string)
 120+
 121+# Strips out whitespace
 122+# html_string_parts = html_string.split()
 123+# html_string = ''
 124+# for i in html_string_parts:
 125+# html_string = html_string + i
108126
109 - html_string_parts = html_string.split()
110 - html_string = ''
111 - for i in html_string_parts:
112 - html_string = html_string + i
113 -
114127 if ttl.record_exists(utm_campaign=utm_campaign_var):
115 - ttl.update_test_row(test_name=test_name_var,utm_campaign=utm_campaign_var,start_time=start_time_var,end_time=end_time_var,html_report=html_string)
 128+ ttl.update_test_row(test_name=test_name_var,test_type=test_type_var,utm_campaign=utm_campaign_var,start_time=start_time_var,end_time=end_time_var,html_report=html_string)
116129 else:
117 - ttl.insert_row(test_name=test_name_var,utm_campaign=utm_campaign_var,start_time=start_time_var,end_time=end_time_var,html_report=html_string)
 130+ ttl.insert_row(test_name=test_name_var,test_type=test_type_var,utm_campaign=utm_campaign_var,start_time=start_time_var,end_time=end_time_var,html_report=html_string)
118131
119132 return html
120133
121 -
\ No newline at end of file
 134+
 135+"""
 136+
 137+ Helper method for 'test' view which generates a report
 138+
 139+ INPUT:
 140+ RETURN:
 141+
 142+"""
 143+def auto_gen(test_name, start_time, end_time, campaign, labels, sample_interval, test_interval, test_type, metric_types):
 144+
 145+ # e.g. labels = {'Static banner':'20101227_JA061_US','Fading banner':'20101228_JAFader_US'}
 146+
 147+ os.chdir('/home/rfaulkner/trunk/projects/Fundraiser_Tools/classes')
 148+
 149+ use_labels_var = True
 150+ if len(labels) == 0:
 151+ use_labels_var = False
 152+
 153+ """ Build reporting objects """
 154+ ir = DR.IntervalReporting(use_labels=use_labels_var,font_size=20,plot_type='step',file_path=projSet.__web_home__ + 'tests/static/images/')
 155+ ir_cmpgn = DR.IntervalReporting(use_labels=False,font_size=20,plot_type='line',data_loader='campaign',file_path=projSet.__web_home__ + 'tests/static/images/')
 156+ cr = DR.ConfidenceReporting(use_labels=use_labels_var,font_size=20,plot_type='line',hyp_test='t_test',file_path=projSet.__web_home__ + 'tests/static/images/')
 157+
 158+ """ generate interval reporting plots """
 159+
 160+
 161+ # print 'Generating interval plots ...\n'
 162+ for metric in metric_types:
 163+ if test_type == FDH._TESTTYPE_BANNER_:
 164+ ir.run(start_time, end_time, sample_interval, 'banner', metric, campaign, labels.keys())
 165+ if test_type == FDH._TESTTYPE_LP_:
 166+ ir.run(start_time, end_time, sample_interval, 'LP', metric, campaign, labels.keys())
 167+
 168+ # print 'Generating campaign plots...\n'
 169+ ir_cmpgn.run(start_time, end_time, sample_interval, 'campaign', 'views', campaign, [])
 170+ ir_cmpgn.run(start_time, end_time, sample_interval, 'campaign', 'donations', campaign, [])
 171+
 172+ """ generate confidence reporting plots """
 173+ # print 'Executing hypothesis testing ...\n'
 174+ # cr.run('Fader VS Static','report_banner_confidence','don_per_imp','20101228JA075',{'Static banner':'20101227_JA061_US','Fading banner':'20101228_JAFader_US'},'20101229141000','20101229155000',2,10)
 175+ if test_type == FDH._TESTTYPE_BANNER_:
 176+ winner_dpi, percent_increase_dpi, confidence_dpi = cr.run(test_name,'report_banner_confidence','don_per_imp',campaign, labels, start_time, end_time, sample_interval,test_interval)
 177+ winner_api, percent_increase_api, confidence_api = cr.run(test_name,'report_banner_confidence','amt50_per_imp',campaign, labels, start_time, end_time, sample_interval,test_interval)
 178+ elif test_type == FDH._TESTTYPE_LP_:
 179+ winner_dpi, percent_increase_dpi, confidence_dpi = cr.run(test_name,'report_LP_confidence','don_per_view',campaign, labels, start_time, end_time, sample_interval,test_interval)
 180+ winner_api, percent_increase_api, confidence_api = cr.run(test_name,'report_LP_confidence','amt50_per_view',campaign, labels, start_time, end_time, sample_interval,test_interval)
 181+
 182+ """ compose HTML """
 183+
 184+ os.chdir('/home/rfaulkner/trunk/projects/Fundraiser_Tools/classes/tests/')
 185+
 186+
 187+ f = open('auto_report.html', 'w')
 188+
 189+ html_script = ''
 190+
 191+ html_script = html_script + '\n<html>\n<head>\n<title>Big Ass Reportin\'</title>'
 192+
 193+ html_script = html_script + '</head>\n<body>\n<h1>Test Report</h1>\n<br>\n'
 194+
 195+ html_script = html_script + '<h3><u>Interval Reporting</u></h3>\n'
 196+
 197+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_banner_' + metric_types[0] + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 198+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_banner_' + metric_types[1] + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 199+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_banner_' + metric_types[2] + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 200+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_banner_' + metric_types[3] + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 201+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_campaign_views' + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 202+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_campaign_donations' + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 203+
 204+ html_script = html_script + '<h3><u>Confidence Reporting</u></h3>\n'
 205+
 206+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_conf_don_per_imp' + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 207+ html_script = html_script + '<OBJECT WIDTH="1000" HEIGHT="600" data="' + campaign + '_conf_amt50_per_imp' + '.png" type="image/png">\n<p>.</p>\n</OBJECT><br>\n'
 208+
 209+ """ !! MODIFY -- THIS currently doesn't look great !!
 210+
 211+ f_test_results_1 = open(campaign + '_conf_don_per_imp' + '.txt', 'r')
 212+ f_test_results_2 = open(campaign + '_conf_amt50_per_imp' + '.txt', 'r')
 213+
 214+ data_results_1 = ''
 215+ line = f_test_results_1.readline()
 216+ while (line):
 217+ data_results_1 = data_results_1 + line + '<br>'
 218+ line = f_test_results_1.readline()
 219+
 220+ data_results_2 = ''
 221+ line = f_test_results_2.readline()
 222+ while (line):
 223+ data_results_2 = data_results_2 + line + '<br>'
 224+ line = f_test_results_2.readline()
 225+
 226+ html_script = html_script + data_results_1 + '<br><br>'
 227+ html_script = html_script + data_results_2
 228+
 229+ """
 230+
 231+ html_script = html_script + '</body></html>\n'
 232+
 233+ # print html_script
 234+
 235+ f.write(html_script)
 236+
 237+ f.close()
 238+
 239+ return [winner_dpi, percent_increase_dpi, confidence_dpi, winner_api, percent_increase_api, confidence_api]
 240+
 241+
 242+"""
 243+ Inserts a comment into an existing report
 244+
 245+"""
 246+def add_comment(request, utm_campaign):
 247+
 248+ try:
 249+ comments = request.POST['comments']
 250+
 251+ except:
 252+ return HttpResponseRedirect(reverse('tests.views.index'))
 253+
 254+ """ Retrieve the report """
 255+ ttl = DL.TestTableLoader()
 256+ row = ttl.get_test_row(utm_campaign)
 257+ html_string = ttl.get_test_field(row, 'html_report')
 258+
 259+ """ Insert comment """
 260+ new_html = ''
 261+ lines = html_string.split('\n')
 262+ now = datetime.datetime.utcnow().__str__()
 263+
 264+ for line in lines:
 265+
 266+ if line == '<!-- Cend -->':
 267+ line = '\n<br>' + comments + '\n<br><br> --' + now + '<br>\n' + '<!-- Cend -->'
 268+
 269+ new_html = new_html + line + '\n'
 270+
 271+ html_string = new_html
 272+ html_string = html_string.replace('"', '\\"')
 273+ html_string = Hlp.stringify(html_string)
 274+
 275+ # parse the html for <!-- Cbegin --> <!-- Cend -->
 276+ # add the comment above this
 277+
 278+ """ Update the report """
 279+ ttl.update_test_row(test_name=ttl.get_test_field(row, 'test_name'), test_type=ttl.get_test_field(row, 'test_type'), utm_campaign=ttl.get_test_field(row, 'utm_campaign'), start_time=ttl.get_test_field(row, 'start_time'), \
 280+ end_time=ttl.get_test_field(row, 'end_time'), winner=ttl.get_test_field(row, 'winner'), is_conclusive=ttl.get_test_field(row, 'is_conclusive'), html_report=html_string)
 281+
 282+
 283+ return HttpResponse(new_html)
 284+
Index: trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/tests/urls.py
@@ -3,5 +3,7 @@
44
55 urlpatterns = patterns('',
66 (r'^$', 'tests.views.index'),
7 - (r'^build_test$', 'tests.views.test')
 7+ (r'^build_test$', 'tests.views.test'),
 8+ (r'^report/(?P<utm_campaign>[a-zA-Z0-9_]+)$', 'campaigns.views.show_report'),
 9+ (r'^report/comment/(?P<utm_campaign>[a-zA-Z0-9_]+)$', 'tests.views.add_comment'),
810 )

Status & tagging log