r91007 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91006‎ | r91007 | r91008 >
Date:21:22, 28 June 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
Added donations and timestamp filter form to index view
Modified paths:
  • /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
@@ -18,6 +18,8 @@
1919 __revision__ = "$Rev$"
2020 __date__ = "June 20th, 2011"
2121
 22+
 23+""" Import django modules """
2224 from django.shortcuts import render_to_response
2325 from django.http import Http404
2426 from django.shortcuts import render_to_response, get_object_or_404
@@ -25,19 +27,19 @@
2628 from django.http import HttpResponseRedirect, HttpResponse
2729 from django.core.urlresolvers import reverse
2830
29 -import sys
30 -import os
31 -import datetime
 31+""" Import python base modules """
 32+import sys, os, datetime, operator
3233
 34+""" Import Analytics modules """
3335 import Fundraiser_Tools.classes.Helper as Hlp
3436 import Fundraiser_Tools.classes.DataReporting as DR
3537 import Fundraiser_Tools.classes.DataLoader as DL
3638 import Fundraiser_Tools.classes.FundraiserDataHandler as FDH
3739 import Fundraiser_Tools.classes.TimestampProcessor as TP
3840 import Fundraiser_Tools.settings as projSet
39 -import operator
4041
4142
 43+
4244 """
4345 Index page for finding the latest camapigns. Displays a list of recent campaigns with more than k donations over the last n hours.
4446 Also if a report exists a link is provided.
@@ -45,6 +47,18 @@
4648 """
4749 def index(request):
4850
 51+ err_msg = ''
 52+
 53+ """ Parse the filter fields """
 54+ filter_data = True
 55+ try:
 56+ min_donations_var = request.POST['min_donations']
 57+ earliest_utc_ts_var = request.POST['utc_ts']
 58+
 59+ except KeyError as e:
 60+ filter_data = False
 61+
 62+
4963 """ Interface with the DataLoader """
5064
5165 os.chdir(projSet.__project_home__ + 'classes')
@@ -58,10 +72,27 @@
5973 end_time = TP.timestamp_from_obj(datetime.datetime.now() + datetime.timedelta(hours=8),1,3)
6074
6175 campaigns, all_data = crl.run_query({'metric_name':'earliest_timestamp','start_time':start_time,'end_time':end_time})
62 -
 76+
6377 sorted_campaigns = sorted(campaigns.iteritems(), key=operator.itemgetter(1))
6478 sorted_campaigns.reverse()
6579
 80+ if filter_data:
 81+ try:
 82+ if min_donations_var == '':
 83+ min_donations = 0
 84+ else:
 85+ min_donations = int(min_donations_var)
 86+
 87+ earliest_utc_ts = int(earliest_utc_ts_var)
 88+ except:
 89+ err_msg = 'Filter fields are incorrect.'
 90+
 91+ filter_data = False
 92+ else:
 93+ min_donations_var = ''
 94+ earliest_utc_ts_var = ''
 95+
 96+
6697 new_sorted_campaigns = list()
6798 for campaign in sorted_campaigns:
6899 key = campaign[0]
@@ -72,13 +103,18 @@
73104 name = 'none'
74105 # timestamp = TP.timestamp_from_obj(all_data[key][3], 2, 2)
75106 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]])
 107+
 108+ if filter_data:
 109+ if all_data[key][2] > min_donations and int(all_data[key][3]) > earliest_utc_ts:
 110+ new_sorted_campaigns.append([campaign[0], campaign[1], name, timestamp, all_data[key][2], all_data[key][4]])
 111+ else:
 112+ new_sorted_campaigns.append([campaign[0], campaign[1], name, timestamp, all_data[key][2], all_data[key][4]])
77113
78114 sorted_campaigns = new_sorted_campaigns
79115
80116 os.chdir(projSet.__project_home__ + 'web_reporting')
81117
82 - return render_to_response('campaigns/index.html', {'campaigns' : sorted_campaigns})
 118+ return render_to_response('campaigns/index.html', {'campaigns' : sorted_campaigns, 'err_msg' : err_msg, 'min_donations' : min_donations_var, 'earliest_utc' : earliest_utc_ts_var}, context_instance=RequestContext(request))
83119
84120
85121
@@ -106,7 +142,7 @@
107143
108144 """ Estimate start/end time of campaign """
109145 """ This generates an image for campaign views """
110 - ir = DR.IntervalReporting(use_labels=False, font_size=20, plot_type='line', query_type='campaign', file_path=projSet.__web_home__ + 'campaigns/static/images/')
 146+ ir = DR.IntervalReporting(was_run=False, use_labels=False, font_size=20, plot_type='line', query_type='campaign', file_path=projSet.__web_home__ + 'campaigns/static/images/')
111147
112148 """
113149 Try to produce analysis on the campaign view data
@@ -116,16 +152,14 @@
117153 ir.run(start_time, end_time, interval, 'views', utm_campaign, [])
118154
119155 except Exception as inst:
120 -
121156 print >> sys.stderr, type(inst) # the exception instance
122157 print >> sys.stderr, inst.args # arguments stored in .args
123158 print >> sys.stderr, inst # __str__ allows args to printed directly
124159
125160 err_msg = 'There is insufficient data to analyze this campaign %s.' % utm_campaign
126161 return HttpResponseRedirect(reverse('campaigns.views.index'))
127 -
 162+
128163 """ search for start_time and end_time """
129 -
130164 top_view_interval = max(ir._counts_[utm_campaign])
131165
132166 start_count = 0
@@ -145,6 +179,7 @@
146180 break
147181
148182 count = count + 1
 183+
149184
150185 count = 0
151186 ir._counts_[utm_campaign].reverse()
@@ -170,9 +205,11 @@
171206 row = ttl.get_test_row(utm_campaign)
172207 test_name = ttl.get_test_field(row ,'test_name')
173208
174 - """ Regenerate the data using the estimated start and end times """
 209+ """ Regenerate the data using the estimated start and end times !! FIXME / MODIFY -- this is cumbersome .. should just generate the plot !! """
 210+ ir = DR.IntervalReporting(was_run=False, use_labels=False, font_size=20, plot_type='line', query_type='campaign', file_path=projSet.__web_home__ + 'campaigns/static/images/')
175211 ir.run(start_time_est, end_time_est, interval, 'views', utm_campaign, [])
176 -
 212+
 213+
177214 """ determine the type of test """
178215 """ Get the banners """
179216 test_type, artifact_name_list = FDH.get_test_type(utm_campaign, start_time, end_time, DL.CampaignReportingLoader(''))

Status & tagging log