r80243 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80242‎ | r80243 | r80244 >
Date:09:54, 14 January 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
added confidence analysis for landing pages. fixed exception handling for ip localization in miner help
Modified paths:
  • /trunk/fundraiser-statistics/fundraiser-scripts/miner_help.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/query_store.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/sql/report_LP_confidence.sql (added) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/sql/report_LP_confidence.sql
@@ -0,0 +1,44 @@
 2+
 3+
 4+
 5+select
 6+
 7+lp.utm_source,
 8+views as views,
 9+total_clicks as clicks,
 10+donations as donations,
 11+amount as amount,
 12+donations / total_clicks as completion_rate,
 13+donations / views as don_per_view,
 14+amount / views as amt_per_view,
 15+amount / donations as amt_per_donation
 16+
 17+from
 18+
 19+select
 20+landing_page,
 21+count(*) as views
 22+from landing_page
 23+where request_time >= '%s' and request_time < '%s'
 24+and utm_campaign REGEXP '%s'
 25+and landing_page REGEXP '%s'
 26+group by 1) as lp
 27+
 28+join
 29+
 30+(select
 31+SUBSTRING_index(substring_index(utm_source, '.', 2),'.',-1) as landing_page,
 32+count(*) as total_clicks,
 33+sum(not isnull(contribution_tracking.contribution_id)) as donations,
 34+sum(converted_amount) AS amount
 35+from
 36+drupal.contribution_tracking LEFT JOIN civicrm.public_reporting
 37+ON (contribution_tracking.contribution_id = civicrm.public_reporting.contribution_id)
 38+where ts >= '%s' and ts < '%s'
 39+and utm_campaign REGEXP '%s'
 40+and SUBSTRING_index(substring_index(utm_source, '.', 2),'.',-1) REGEXP '%s'
 41+group by 1) as ecomm
 42+
 43+on ecomm.landing_page = lp.landing_page and ecomm.utm_campaign = lp.utm_campaign
 44+
 45+group by 1;
Index: trunk/fundraiser-statistics/fundraiser-scripts/query_store.py
@@ -103,7 +103,14 @@
104104 banner = args[2]
105105 campaign = args[3]
106106 sql_stmnt = sql_stmnt % (start, end, banner, start, end, campaign, start, end, campaign, banner)
107 -
 107+
 108+ elif query_name == 'report_LP_confidence':
 109+ start = args[0]
 110+ end = args[1]
 111+ lp = args[2]
 112+ campaign = args[3]
 113+ sql_stmnt = sql_stmnt % (start, end, campaign, lp, start, end, campaign, lp)
 114+
108115 else:
109116 return 'no such table\n'
110117
@@ -251,6 +258,17 @@
252259 return 10
253260 else:
254261 return -1
 262+ elif query_name == 'report_LP_confidence':
 263+ if metric_name == 'completion_rate':
 264+ return 5
 265+ elif metric_name == 'don_per_view':
 266+ return 6
 267+ elif metric_name == 'amt_per_view':
 268+ return 7
 269+ elif metric_name == 'amt_per_donation':
 270+ return 8
 271+ else:
 272+ return -1
255273 else:
256274 return 'no such table'
257275
Index: trunk/fundraiser-statistics/fundraiser-scripts/miner_help.py
@@ -187,14 +187,8 @@
188188 return new_collection
189189
190190 """ Given an IP localizes the country """
191 -def localize_IP(ip_string):
 191+def localize_IP(cur, ip_string):
192192
193 - """ Get db object / Create cursor """
194 - # db = MySQLdb.connect(host='127.0.0.1', user='rfaulk', db='faulkner', port=3307)
195 - db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner')
196 - cur = db.cursor()
197 -
198 -
199193 # compute ip number
200194 ip_fields = ip_string.split('.')
201195 w = int(ip_fields[0])
@@ -211,17 +205,13 @@
212206 row = cur.fetchone()
213207 except:
214208 db.rollback()
215 - sys.exit("Could execute: " + sql_stmnt)
 209+ sys.exit("Could not execute: " + sql_stmnt)
216210
217 - country = row[0]
 211+ try:
 212+ country = row[0]
 213+ except:
 214+ country = ''
218215
219 - # Commit to the db
220 - db.commit()
221 -
222 - # Close connection
223 - cur.close()
224 - db.close()
225 -
226216 return country
227217
228218 """ Load data into the IP localization table to associate IPs with countries """

Status & tagging log