r90438 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90437‎ | r90438 | r90439 >
Date:08:06, 20 June 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
Modified logic for estimating start and end times for campaigns
Added documentation
Modified paths:
  • /trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/campaigns/urls.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/campaigns/views.py (modified) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/campaigns/views.py
@@ -1,4 +1,23 @@
22
 3+"""
 4+ DJANGO VIEW DEFINITIONS:
 5+ ========================
 6+
 7+ Defines the views for campaigns application. This is meant to serve as a view into currently running campaigns and
 8+ generating tests for them.
 9+
 10+ Views:
 11+
 12+ index -- the index page shows a listing of campaigns and the donations they have received along with a link to a generated report if exists
 13+ show_campaigns -- this view shows the view stats for a campaign and allows the user to execute a test and generate a report
 14+ show_report -- this view simply enables linking to existing reports
 15+
 16+"""
 17+
 18+__author__ = "Ryan Faulkner"
 19+__revision__ = "$Rev$"
 20+__date__ = "June 20th, 2011"
 21+
322 from django.shortcuts import render_to_response
423 from django.http import Http404
524 from django.shortcuts import render_to_response, get_object_or_404
@@ -21,17 +40,25 @@
2241
2342 """
2443 Index page for finding the latest camapigns. Displays a list of recent campaigns with more than k donations over the last n hours.
 44+ Also if a report exists a link is provided.
2545
2646 """
2747 def index(request):
2848
2949 """ Interface with the DataLoader """
3050
31 - os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/classes')
 51+ os.chdir(projSet.__project_home__ + 'classes')
3252
33 - crl = DL.CampaignReportingLoader()
34 - campaigns, all_data = crl.run_query('totals',{'metric_name':'donations','start_time':'20101230130400','end_time':'20101230154400'})
 53+ crl = DL.CampaignReportingLoader('totals')
3554
 55+ #end_time, start_time = TP.timestamps_for_interval(datetime.datetime.now() + datetime.timedelta(hours=8), 1, hours=-24)
 56+ #start_time = '20101230130400'
 57+ #end_time = '20101230154400'
 58+ start_time = '20110531120000'
 59+ end_time = TP.timestamp_from_obj(datetime.datetime.now() + datetime.timedelta(hours=8),1,3)
 60+
 61+ campaigns, all_data = crl.run_query({'metric_name':'earliest_timestamp','start_time':start_time,'end_time':end_time})
 62+
3663 sorted_campaigns = sorted(campaigns.iteritems(), key=operator.itemgetter(1))
3764 sorted_campaigns.reverse()
3865
@@ -39,16 +66,17 @@
4067 for campaign in sorted_campaigns:
4168 key = campaign[0]
4269
43 - if campaign[1] > 50:
 70+ if campaign[1] > 0:
4471 name = all_data[key][0]
4572 if name == None:
4673 name = 'none'
47 - timestamp = TP.timestamp_from_obj(all_data[key][3], 2, 2)
48 - new_sorted_campaigns.append([campaign[0], campaign[1], name, timestamp, all_data[key][4]])
 74+ # timestamp = TP.timestamp_from_obj(all_data[key][3], 2, 2)
 75+ timestamp = TP.timestamp_convert_format(all_data[key][3], 1, 2)
 76+ new_sorted_campaigns.append([campaign[0], campaign[1], name, timestamp, all_data[key][2], all_data[key][4]])
4977
5078 sorted_campaigns = new_sorted_campaigns
5179
52 - os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/web_reporting')
 80+ os.chdir(projSet.__project_home__ + 'web_reporting')
5381
5482 return render_to_response('campaigns/index.html', {'campaigns' : sorted_campaigns})
5583
@@ -57,23 +85,45 @@
5886
5987 """
6088
61 - Use time interval views of the data to display campaign information
 89+ Shows view stats over the time range for which the campaign receives landing page hits. A form is also generated from the associated template
 90+ that allows a test report to be generated.
6291
6392 """
6493 def show_campaigns(request, utm_campaign):
6594
66 - """ Look 5 hrs into the past? """
67 - start_time = '20101230130400'
68 - end_time = '20101230154400'
 95+ """ Look 10 hrs into the past? """
 96+ # end_time, start_time = TP.timestamps_for_interval(datetime.datetime.now() + datetime.timedelta(hours=8), 1, hours=-24)
 97+
 98+ #start_time = '20101230130400'
 99+ #end_time = '20101230154400'
 100+ """ currently the start time is hard coded to the beginning of FR testing """
 101+ start_time = '20110531120000'
 102+ end_time = TP.timestamp_from_obj(datetime.datetime.now() + datetime.timedelta(hours=8),1,3)
 103+
69104 interval = 2
70 -
71 - os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/classes')
72105
 106+ os.chdir(projSet.__project_home__ + 'classes')
 107+
73108 """ Estimate start/end time of campaign """
74109 """ This generates an image for campaign views """
75 - ir = DR.IntervalReporting(use_labels=False, font_size=20, plot_type='line', data_loader='campaign', file_path=projSet.__web_home__ + 'campaigns/static/images/')
76 - ir.run(start_time, end_time, interval, 'campaign', 'views', utm_campaign, [])
 110+ ir = DR.IntervalReporting(use_labels=False, font_size=20, plot_type='line', query_type='campaign', file_path=projSet.__web_home__ + 'campaigns/static/images/')
77111
 112+ """
 113+ Try to produce analysis on the campaign view data
 114+ If unsuccessful reverse to index view and emit error message
 115+ """
 116+ try:
 117+ ir.run(start_time, end_time, interval, 'views', utm_campaign, [])
 118+
 119+ except Exception as inst:
 120+
 121+ print >> sys.stderr, type(inst) # the exception instance
 122+ print >> sys.stderr, inst.args # arguments stored in .args
 123+ print >> sys.stderr, inst # __str__ allows args to printed directly
 124+
 125+ err_msg = 'There is insufficient data to analyze this campaign %s.' % utm_campaign
 126+ return HttpResponseRedirect(reverse('campaigns.views.index'))
 127+
78128 """ search for start_time and end_time """
79129
80130 top_view_interval = max(ir._counts_[utm_campaign])
@@ -83,31 +133,53 @@
84134 begin_count = False
85135 count = 0
86136
87 - """ Define the start time as the first interval at least80% of the maximum view interval
88 - Define the end time as the first interval following the estimated start time and less than 50% of the maximum view interval """
 137+ """
 138+ ESTIMATE THE START AND END TIME OF THE CAMAPIGN
 139+
 140+ Search for the first instance when more than 10 views are observed over a smapling period
 141+ """
89142 for i in ir._counts_[utm_campaign]:
90 - if i > (0.5 * top_view_interval) and not(begin_count):
 143+ # if i > (0.5 * top_view_interval) and not(begin_count):
 144+ if i > 10:
91145 start_count = count
92 - begin_count = True
93 -
94 - if begin_count and i < (0.5 * top_view_interval) and (end_count > count):
95 - end_count = count - 3
96 -
 146+ break
 147+
97148 count = count + 1
98149
 150+ count = 0
 151+ ir._counts_[utm_campaign].reverse()
 152+ for i in ir._counts_[utm_campaign]:
 153+
 154+ if i > 10:
 155+ end_count = count
 156+ break
 157+
 158+ count = count + 1
 159+
 160+ ir._counts_[utm_campaign].reverse()
 161+
 162+ """ Based on where the first and last number of views/interval are observed to be greater that 10, generate the associated timestamps """
 163+ end_count = len(ir._counts_[utm_campaign]) - end_count
99164 start_time_est = TP.timestamp_to_obj(start_time, 1) + datetime.timedelta(minutes=interval * start_count)
100165 end_time_est = TP.timestamp_to_obj(start_time, 1) + datetime.timedelta(minutes=interval * end_count)
101166 start_time_est = TP.timestamp_from_obj(start_time_est, 1, 2)
102167 end_time_est = TP.timestamp_from_obj(end_time_est, 1, 2)
103168
 169+ """ Read the test name """
 170+ ttl = DL.TestTableLoader()
 171+ row = ttl.get_test_row(utm_campaign)
 172+ test_name = ttl.get_test_field(row ,'test_name')
104173
 174+ """ Regenerate the data using the estimated start and end times """
 175+ ir.run(start_time_est, end_time_est, interval, 'views', utm_campaign, [])
 176+
105177 """ determine the type of test """
106178 """ Get the banners """
107 - test_type, artifact_name_list = FDH.get_test_type(utm_campaign, start_time_est, end_time_est)
108 -
109 - os.chdir(projSet.__project_home__ + '/Fundraiser_Tools/web_reporting')
 179+ test_type, artifact_name_list = FDH.get_test_type(utm_campaign, start_time, end_time, DL.CampaignReportingLoader(''))
 180+
 181+ os.chdir(projSet.__project_home__ + 'web_reporting')
110182
111 - return render_to_response('campaigns/show_campaigns.html', {'utm_campaign' : utm_campaign, 'start_time' : start_time_est, 'end_time' : end_time_est, 'artifacts' : artifact_name_list, 'test_type' : test_type}, context_instance=RequestContext(request))
 183+ return render_to_response('campaigns/show_campaigns.html', {'utm_campaign' : utm_campaign, 'test_name' : test_name, 'start_time' : start_time_est, 'end_time' : end_time_est, 'artifacts' : artifact_name_list, 'test_type' : test_type}, context_instance=RequestContext(request))
112184
113185 # return HttpResponseRedirect(reverse('campaigns.views.index'))
114186
Index: trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/campaigns/urls.py
@@ -2,6 +2,7 @@
33
44
55 urlpatterns = patterns('',
 6+ # url(r'^$', 'campaigns.views.index', kwargs={'message':''}),
67 (r'^$', 'campaigns.views.index'),
78 (r'^(?P<utm_campaign>[a-zA-Z0-9_]+)$', 'campaigns.views.show_campaigns'),
89 )

Status & tagging log