r78655 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78654‎ | r78655 | r78656 >
Date:00:35, 21 December 2010
Author:rfaulk
Status:deferred
Tags:
Comment:
Added credit card paypal amounts and completion rates to reporting.
Modified paths:
  • /trunk/fundraiser-statistics/bash/plot_build_hr.sh (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/fundraiser_reporting.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/query_store.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/run_plots.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/sql/report_total_amounts.sql (modified) (history)
  • /trunk/fundraiser-statistics/reporting/fundraiser_analytics.html (modified) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/fundraiser_reporting.py
@@ -48,8 +48,8 @@
4949 def init_db(self):
5050 """ Establish connection """
5151 #db = MySQLdb.connect(host='db10.pmtpa.wmnet', user='rfaulk', db='faulkner')
52 - self.db = MySQLdb.connect(host='127.0.0.1', user='rfaulk', db='faulkner', port=3307)
53 - #self.db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner')
 52+ #self.db = MySQLdb.connect(host='127.0.0.1', user='rfaulk', db='faulkner', port=3307)
 53+ self.db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner')
5454
5555 """ Create cursor """
5656 self.cur = self.db.cursor()
@@ -213,7 +213,7 @@
214214 sql_stmnt = mh.read_sql(filename)
215215 sql_stmnt = query_obj.format_query(query_name + descriptor, sql_stmnt, [start_time, end_time])
216216
217 - labels = [None] * 9
 217+ labels = [None] * 20
218218 labels[0] = 'clicks'
219219 labels[1] = 'donations'
220220 labels[2] = 'total amount'
@@ -223,6 +223,18 @@
224224 labels[6] = 'Other Amount'
225225 labels[7] = 'Email Amount'
226226 labels[8] = 'Recurring Guess'
 227+ labels[9] = 'completion_rate'
 228+ labels[10] = 'pp_clicks'
 229+ labels[11] = 'pp_donations'
 230+ labels[12] = 'pp_completion'
 231+ labels[13] = 'pp_amount'
 232+ labels[14] = 'pp_max_amount'
 233+ labels[15] = 'cc_clicks'
 234+ labels[16] = 'cc_donations'
 235+ labels[17] = 'cc_completion'
 236+ labels[18] = 'cc_amount'
 237+ labels[19] = 'cc_max_amount'
 238+
227239
228240 num_keys = len(labels)
229241
@@ -248,7 +260,7 @@
249261 self.close_db()
250262
251263 # Only interested in amounts
252 - return [labels[2:9], lists[2:9]]
 264+ return [labels, lists]
253265
254266
255267
@@ -274,7 +286,7 @@
275287
276288
277289
278 - def run_hr(self):
 290+ def run_hr(self, type):
279291
280292
281293 # Current date & time
@@ -300,12 +312,38 @@
301313 # RUN BY HOUR
302314 descriptor = '_by_hr'
303315 return_val = self.run_query(start_time, end_time, query_name, descriptor)
 316+
304317 labels = return_val[0] # curve labels
305318 counts = return_val[1] # curve data - lists
306 -
307 - title = 'Total Amounts: ' + start_time + ' -- ' + end_time
 319+
 320+ if type == 'BAN_EM':
 321+ indices = range(2,9)
 322+ title = 'Total Amounts: ' + start_time + ' -- ' + end_time
 323+ ylabel = 'Amount'
 324+ elif type == 'CC_PP_completion':
 325+ indices = [12,17]
 326+ title = 'Credit Card & Paypal Completion Rates: ' + start_time + ' -- ' + end_time
 327+ ylabel = 'Rate'
 328+ elif type == 'CC_PP_amount':
 329+ indices = [13,18]
 330+ title = 'Credit Card & Paypal Total Amounts: ' + start_time + ' -- ' + end_time
 331+ ylabel = 'Amount'
 332+ else:
 333+ sys.exit("Total Amounts: You must enter a valid report type.\n" )
 334+
 335+ # Exract relevant labels and values
 336+ labels_temp = list()
 337+ counts_temp = list()
 338+
 339+ for i in range(len(labels)):
 340+ if i in indices:
 341+ labels_temp.append(labels[i])
 342+ counts_temp.append(counts[i])
 343+
 344+ labels = labels_temp
 345+ counts = counts_temp
 346+
308347 xlabel = 'Time - Hours'
309 - ylabel = 'Amount'
310348 subplot_index = 111
311349
312350 # plot the curves
@@ -315,7 +353,8 @@
316354
317355 ranges = [min(time_range), max(time_range)]
318356
319 - self.gen_plot(time_range, counts, labels, title, xlabel, ylabel, ranges, subplot_index, query_name+descriptor)
 357+ fname = query_name + descriptor + '_' + type
 358+ self.gen_plot(time_range, counts, labels, title, xlabel, ylabel, ranges, subplot_index, fname)
320359
321360
322361
@@ -489,9 +528,9 @@
490529
491530 # Current date & time
492531 now = datetime.datetime.now()
493 - UTC = 8
494 - delta = datetime.timedelta(hours=UTC)
495 - now = now + delta
 532+ #UTC = 8
 533+ #delta = datetime.timedelta(hours=UTC)
 534+ #now = now + delta
496535
497536 # ESTABLISH THE START TIME TO PULL ANALYTICS
498537 hours_back = 24
Index: trunk/fundraiser-statistics/fundraiser-scripts/sql/report_total_amounts.sql
@@ -13,18 +13,17 @@
1414 sum(if(utm_source REGEXP '.rpp' ,1 ,0))*0.5*8*10 as recurring_guess,
1515
1616 sum(not isnull(contribution_tracking.contribution_id)) /count(*) as completion_rate,
17 -sum(converted_amount) AS amount,
18 -sum(if(right(utm_source,2)='pp' and contribution_tracking.contribution_id,1,0))/sum(if(right(utm_source,2)='cc' and contribution_tracking.contribution_id,1,0)) as pp_over_cc_dons,
 17+-- sum(if(right(utm_source,2)='pp' and contribution_tracking.contribution_id,1,0))/sum(if(right(utm_source,2)='cc' and contribution_tracking.contribution_id,1,0)) as pp_over_cc_dons,
1918 sum(if(right(utm_source,2)='pp',1,0)) as pp_clicks,
2019 sum(if(right(utm_source,2)='pp' and contribution_tracking.contribution_id,1,0)) as pp_donations,
2120 sum(if(right(utm_source,2)='pp' and contribution_tracking.contribution_id,1,0))/sum(if(right(utm_source,2)='pp',1,0)) as pp_completion,
 21+sum(if(right(utm_source,2)='pp',converted_amount,0)) as pp_amt,
 22+max(if(right(utm_source,2)='pp',converted_amount,0)) as max_pp_amt,
2223 sum(if(right(utm_source,2)='cc',1,0)) as cc_clicks,
2324 sum(if(right(utm_source,2)='cc' and contribution_tracking.contribution_id,1,0)) as cc_donations,
2425 sum(if(right(utm_source,2)='cc' and contribution_tracking.contribution_id,1,0))/sum(if(right(utm_source,2)='cc',1,0)) as cc_completion,
2526 sum(if(right(utm_source,2)='cc',converted_amount,0)) as cc_amt,
26 -sum(if(right(utm_source,2)='pp',converted_amount,0)) as pp_amt,
2727 max(if(right(utm_source,2)='cc',converted_amount,0)) as max_cc_amt,
28 -max(if(right(utm_source,2)='pp',converted_amount,0)) as max_pp_amt,
2928 avg(converted_amount) as average,
3029 max(converted_amount) as max_amount
3130
Index: trunk/fundraiser-statistics/fundraiser-scripts/query_store.py
@@ -173,7 +173,7 @@
174174 return 7
175175 elif metric_name == 'click_rate':
176176 return 8
177 - elif metric_name == 'conversion_rate':
 177+ elif metric_name == 'completion_rate':
178178 return 9
179179 elif metric_name == 'don_per_imp':
180180 return 10
Index: trunk/fundraiser-statistics/fundraiser-scripts/run_plots.py
@@ -20,14 +20,16 @@
2121
2222
2323 # Run the total amount plots
24 -tar.run_hr()
 24+tar.run_hr('BAN_EM')
 25+tar.run_hr('CC_PP_completion')
 26+tar.run_hr('CC_PP_amount')
2527 tar.run_day()
2628
2729 # Run the banner/lp plots
2830 blpr.run('LP', 'don_per_view')
2931 blpr.run('BAN', 'don_per_imp')
3032 blpr.run('BAN', 'click_rate')
31 -blpr.run('LP', 'conversion_rate')
 33+blpr.run('LP', 'completion_rate')
3234
3335 # Run the banner/lp plots
3436 blpr.run('LP-TEST', 'don_per_view')
Index: trunk/fundraiser-statistics/reporting/fundraiser_analytics.html
@@ -29,8 +29,9 @@
3030 <h1><u>Wikimedia Fundraiser Analystics</u></h1>
3131 <br>
3232
33 -<h3><a href="http://fundraising.wikimedia.org/stats/reporting.html">Reporting</a></h3>
 33+<h3><a href="http://fundraising.wikimedia.org/stats/reporting_totals.html">Reporting - Totals</a></h3>
3434 <h3><a href="http://fundraising.wikimedia.org/stats/reporting_latest.html">Reporting - Latest Test</a></h3>
 35+<h3><a href="http://fundraising.wikimedia.org/stats/reporting_all.html">Reporting - All Banners / LPs</a></h3>
3536
3637 <br>
3738
Index: trunk/fundraiser-statistics/bash/plot_build_hr.sh
@@ -7,7 +7,9 @@
88 cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_LP_metrics_don_per_view.png /srv/org.wikimedia.fundraising/stats/
99 cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_total_amounts_by_day.png /srv/org.wikimedia.fundraising/stats/
1010 cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_banner_metrics_don_per_imp.png /srv/org.wikimedia.fundraising/stats/
11 -cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_total_amounts_by_hr.png /srv/org.wikimedia.fundraising/stats/
 11+cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_total_amounts_by_hr_BAN_EM.png /srv/org.wikimedia.fundraising/stats/
 12+cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_total_amounts_by_hr_CC_PP_amount.png /srv/org.wikimedia.fundraising/stats/
 13+cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_total_amounts_by_hr_CC_PP_completion.png /srv/org.wikimedia.fundraising/stats/
1214 cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_banner_metrics_click_rate.png /srv/org.wikimedia.fundraising/stats/
1315 cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_LP_metrics_conversion_rate.png /srv/org.wikimedia.fundraising/stats/
1416

Status & tagging log