r78638 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78637‎ | r78638 | r78639 >
Date:21:52, 20 December 2010
Author:rfaulk
Status:deferred
Tags:
Comment:
Enabled reporting for the latest running tests based on utm campaign.
Modified paths:
  • /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/sql/report_LP_metrics.sql (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/sql/report_latest_campaign.sql (added) (history)
  • /trunk/fundraiser-statistics/reporting/landing_page_test.sql (modified) (history)
  • /trunk/fundraiser-statistics/reporting/landing_page_test_by_hour.sql (modified) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/query_store.py
@@ -64,7 +64,12 @@
6565 elif query_name == 'report_bannerLP_metrics':
6666 start_time = args[0]
6767 end_time = args[1]
68 - sql_stmnt = sql_stmnt % ('%', '%', '%', '%', start_time, end_time, '%', '%', '%', '%', start_time, end_time, '%', '%', '%', '%', start_time, end_time, '%', '%', '%', '%', start_time, end_time)
 68+ campaign = args[2]
 69+ sql_stmnt = sql_stmnt % ('%', '%', '%', '%', start_time, end_time, '%', '%', '%', '%', start_time, end_time, '%', '%', '%', '%', start_time, end_time, campaign, '%', '%', '%', '%', start_time, end_time, campaign)
 70+
 71+ elif query_name == 'report_latest_campaign':
 72+ start_time = args[0]
 73+ sql_stmnt = sql_stmnt % (start_time)
6974
7075 else:
7176 print 'no such table\n'
@@ -98,6 +103,8 @@
99104 return 0
100105 elif query_name == 'report_bannerLP_metrics':
101106 return 0
 107+ elif query_name == 'report_latest_campaign':
 108+ return 1
102109 else:
103110 'no such table'
104111
@@ -110,6 +117,8 @@
111118 return 3
112119 elif query_name == 'report_bannerLP_metrics':
113120 return 1
 121+ elif query_name == 'report_latest_campaign':
 122+ return 0
114123 else:
115124 'no such table'
116125
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()
@@ -373,7 +373,7 @@
374374
375375 class BannerLPReporting(FundraiserReporting):
376376
377 - def run_query(self,start_time, end_time, query_name, metric_name):
 377+ def run_query(self,start_time, end_time, campaign, query_name, metric_name):
378378
379379 self.init_db()
380380
@@ -387,12 +387,12 @@
388388 sql_stmnt = mh.read_sql(filename)
389389
390390 query_name = 'report_bannerLP_metrics' # rename query to work with query store
391 - sql_stmnt = query_obj.format_query(query_name, sql_stmnt, [start_time, end_time])
 391+ sql_stmnt = query_obj.format_query(query_name, sql_stmnt, [start_time, end_time, campaign])
392392
393393 key_index = query_obj.get_banner_index(query_name)
394394 time_index = query_obj.get_time_index(query_name)
395395 metric_index = query_obj.get_metric_index(query_name, metric_name)
396 -
 396+
397397 # Composes the data for each banner
398398 try:
399399 err_msg = sql_stmnt
@@ -418,7 +418,6 @@
419419 self.db.rollback()
420420 sys.exit("Database Interface Exception:\n" + err_msg)
421421
422 -
423422 """ Convert Times to Integers """
424423 # Find the earliest date
425424 max_i = 0
@@ -483,16 +482,16 @@
484483
485484 """
486485
487 - type = 'LP' || 'BAN'
 486+ type = 'LP' || 'BAN' || 'BAN-TEST' || 'LP-TEST'
488487
489488 """
490489 def run(self, type, metric_name):
491490
492491 # Current date & time
493492 now = datetime.datetime.now()
494 - #UTC = 8
495 - #delta = datetime.timedelta(hours=UTC)
496 - #now = now + delta
 493+ UTC = 8
 494+ delta = datetime.timedelta(hours=UTC)
 495+ now = now + delta
497496
498497 # ESTABLISH THE START TIME TO PULL ANALYTICS
499498 hours_back = 24
@@ -500,52 +499,89 @@
501500
502501 start_time = times[0]
503502 end_time = times[1]
504 -
 503+
505504 print '\nGenerating ' + type +' for ' + str(hours_back) + ' hours back. The start and end times are: ' + start_time + ' - ' + end_time +' ... \n'
506505
507506 if type == 'LP':
508 - query_name = 'report_LP_metrics'
 507+ query_name = 'report_LP_metrics'
 508+ campaign = '[0-9](JA|SA|EA)[0-9]'
 509+ title = query_name + '_' + metric_name
 510+ fname = title + '.png'
509511 elif type == 'BAN':
510512 query_name = 'report_banner_metrics'
 513+ campaign = '[0-9](JA|SA|EA)[0-9]'
 514+ title = query_name + '_' + metric_name
 515+ fname = title + '.png'
511516 elif type == 'BAN-TEST':
512 - '[0-9](JA|SA|EA)[0-9]'
 517+ r = self.get_latest_campaign()
 518+ query_name = 'report_banner_metrics'
 519+ campaign = r[0]
 520+ start_time = r[1]
 521+ title = query_name + '_' + metric_name + '_' + campaign
 522+ fname = title + '.png'
513523 elif type == 'LP-TEST':
514 - '[0-9](JA|SA|EA)[0-9]'
 524+ r = self.get_latest_campaign()
 525+ query_name = 'report_LP_metrics'
 526+ campaign = r[0]
 527+ start_time = r[1]
 528+ title = query_name + '_' + metric_name + '_' + campaign
 529+ fname = title + '.png'
515530 else:
516531 sys.exit("Invalid type name - must be 'LP' or 'BAN'.")
517532
518 - return_val = self.run_query(start_time, end_time, query_name, metric_name)
 533+
 534+ return_val = self.run_query(start_time, end_time, campaign, query_name, metric_name)
519535 metrics = return_val[0]
520536 times = return_val[1]
521537
522 - title = metric_name + ': ' + start_time + ' -- ' + end_time
 538+ # title = metric_name + ': ' + start_time + ' -- ' + end_time
523539 xlabel = 'Time - Hours'
524540 ylabel = metric_name
525541 subplot_index = 111
526542
527 - ranges = [-hours_back, -1]
 543+ min_time = 99
 544+ for key in times.keys():
 545+ min_elem = min(times[key])
 546+ if min_elem < min_time:
 547+ min_time = min_elem
528548
529 - self.gen_plot(metrics, times, title, xlabel, ylabel, ranges, subplot_index, query_name + '_' + metric_name + '.png')
 549+ ranges = [min_time, -1]
530550
 551+ self.gen_plot(metrics, times, title, xlabel, ylabel, ranges, subplot_index, fname)
 552+
531553 return [metrics, times]
532554
533555
534 -"""
535 -
536 -CLASS :: ^TestReporting^
537 -
538 -This subclass handles reporting on specific tests as defined by a utm campaign.
539 -
540 -"""
541 -
542 -class TestReporting(FundraiserReporting):
543 -
544 - def run_query(self,start_time, end_time, query_name, metric_name):
545 - 'report_latest_campaign'
546 - # select the first row
 556+ def get_latest_campaign(self):
547557
 558+ query_name = 'report_latest_campaign'
 559+ self.init_db()
548560
549 - def gen_plot(self,counts, times, title, xlabel, ylabel, ranges, subplot_index, fname):
 561+ # Look at campaigns over the past 24 hours
 562+ now = datetime.datetime.now()
 563+ hours_back = 24
 564+ times = self.gen_date_strings_hr(now, hours_back)
550565
551 - def run(self, type, metric_name):
552 -
\ No newline at end of file
 566+ query_obj = qs.query_store()
 567+ sql_stmnt = mh.read_sql('./sql/report_latest_campaign.sql')
 568+ sql_stmnt = query_obj.format_query(query_name, sql_stmnt, [times[0]])
 569+
 570+ campaign_index = query_obj.get_campaign_index(query_name)
 571+ time_index = query_obj.get_time_index(query_name)
 572+
 573+ try:
 574+ err_msg = sql_stmnt
 575+ self.cur.execute(sql_stmnt)
 576+
 577+ row = self.cur.fetchone()
 578+ except:
 579+ self.db.rollback()
 580+ sys.exit("Database Interface Exception:\n" + err_msg)
 581+
 582+ campaign = row[campaign_index]
 583+ timestamp = row[time_index]
 584+
 585+ self.close_db()
 586+
 587+ return [campaign, timestamp]
 588+
\ No newline at end of file
Index: trunk/fundraiser-statistics/fundraiser-scripts/sql/report_latest_campaign.sql
@@ -0,0 +1,14 @@
 2+
 3+-- sorts utm_campaigns by most recently added
 4+
 5+select utm_campaign, min(ts) as min_ts, count(*) as hits
 6+
 7+from
 8+drupal.contribution_tracking LEFT JOIN civicrm.public_reporting
 9+ON (contribution_tracking.contribution_id = civicrm.public_reporting.contribution_id)
 10+
 11+where ts > '%s' and utm_campaign REGEXP '[0-9](JA|SA|EA)[0-9]'
 12+group by 1
 13+having hits > 100
 14+order by 2 desc
 15+;
\ No newline at end of file
Index: trunk/fundraiser-statistics/fundraiser-scripts/sql/report_LP_metrics.sql
@@ -53,7 +53,7 @@
5454 drupal.contribution_tracking LEFT JOIN civicrm.public_reporting
5555 ON (contribution_tracking.contribution_id = civicrm.public_reporting.contribution_id)
5656 where ts >= '%s' and ts < '%s'
57 -and utm_campaign REGEXP '[0-9](JA|SA|EA)[0-9]'
 57+and utm_campaign REGEXP '%s'
5858 group by 1,2) as ecomm
5959
6060 on ecomm.landing_page = lp.landing_page and ecomm.hr = lp.hr
Index: trunk/fundraiser-statistics/reporting/landing_page_test.sql
@@ -8,7 +8,7 @@
99 total_clicks as clicks,
1010 donations as donations,
1111 amount as amount,
12 -donations / total_clicks as conversion_rate,
 12+donations / total_clicks as completion_rate,
1313 donations / views as don_per_view,
1414 amount / views as amt_per_view,
1515 modified_amount / views as amt_per_view_reduced,
Index: trunk/fundraiser-statistics/reporting/landing_page_test_by_hour.sql
@@ -8,7 +8,7 @@
99 total_clicks as clicks,
1010 donations as donations,
1111 amount as amount,
12 -donations / total_clicks as conversion_rate,
 12+donations / total_clicks as completion_rate,
1313 donations / views as don_per_view,
1414 amount / views as amt_per_view,
1515 modified_amount / views as amt_per_view_reduced,

Status & tagging log