Skip to content

Instantly share code, notes, and snippets.

@atopal
atopal / CTR-en-US.sql
Created September 21, 2012 10:31
en-US CTR
SELECT table_numerator.ds AS DS, table_numerator.numerator AS clicks, table_denominator.denominator AS searches, round((table_numerator.numerator/ table_denominator.denominator), 2) AS CTR
FROM
(
select ds, count(*) AS numerator
FROM research_logs
WHERE
ds = '${hiveconf:check_date}'
AND `domain`='support.mozilla.com'
AND ip_address != 'NULL' AND http_version = 200 AND request_type = 'GET'
AND parse_url(empty_string_1,'PATH') RLIKE '\\/en-US\/search\$'
@atopal
atopal / gist:3776307
Created September 24, 2012 14:46
Number of Searches en-US
select count(*) as denominator
FROM research_logs
WHERE
ds = '${hiveconf:check_date}'
AND `domain`='support.mozilla.com'
AND ip_address != 'NULL' AND http_version = 200 AND request_type = 'GET'
AND parse_url(concat('http://a.com',request_url),'PATH') RLIKE '\\/en-US\/search\$'
AND parse_url(concat('http://a.com',request_url),'QUERY','a') IS NULL
AND parse_url(concat('http://a.com',request_url),'QUERY','page') IS NULL
AND parse_url(concat('http://a.com',request_url),'QUERY','format') IS NULL
@atopal
atopal / gist:3776311
Created September 24, 2012 14:46
Number of clickthroughs en-US
select ds, count(*) AS clickhtroughs
FROM research_logs
WHERE
ds = '${hiveconf:check_date}'
AND `domain`='support.mozilla.com'
AND ip_address != 'NULL' AND http_version = 200 AND request_type = 'GET'
AND parse_url(empty_string_1,'PATH') RLIKE '\\/en-US\/search\$'
AND parse_url(empty_string_1,'HOST') = 'support.mozilla.org'
AND
( parse_url(concat('http://a.com',request_url),'PATH') RLIKE '\\/kb\\/'
@atopal
atopal / gist:3804542
Created September 29, 2012 16:36
Helpful votes from internal search
SELECT positive_search_votes.date_created as created_date, positive_search_votes.votes, all_search_votes.votes, (positive_search_votes.votes/all_search_votes.votes*100) as helpful_votes
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvote`.`id`=`wiki_helpfulvotemetadata`.`vote_id`
WHERE `wiki_helpfulvote`.`created` BETWEEN '2012-09-22 0' AND '2012-09-23 0'
AND `wiki_document`.`locale` LIKE 'en-US'
@atopal
atopal / gist:3804550
Created September 29, 2012 16:38
Helpful votes from google
SELECT positive_search_votes.date_created as created_date, positive_search_votes.votes, all_search_votes.votes, (positive_search_votes.votes/all_search_votes.votes*100) as helpful_votes
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvote`.`id`=`wiki_helpfulvotemetadata`.`vote_id`
WHERE `wiki_helpfulvote`.`created` BETWEEN '2012-09-22 0:0:0' AND '2012-09-23 23:59:59'
AND `wiki_document`.`locale` LIKE 'en-US'
@atopal
atopal / gist:3806515
Created September 30, 2012 11:30
All helpful votes for en-US articles
SELECT positive_search_votes.date_created as created_date, positive_search_votes.votes, all_search_votes.votes, (positive_search_votes.votes/all_search_votes.votes*100) as helpful_votes
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
WHERE `wiki_helpfulvote`.`created` BETWEEN '2012-09-22 0:0:0' AND '2012-09-23 23:59:59'
AND `wiki_document`.`locale` LIKE 'en-US'
AND `wiki_helpfulvote`.`user_agent` NOT LIKE '%bot%'
@atopal
atopal / gist:3806570
Created September 30, 2012 11:54
Helpful votes for en-US how-to articles
SELECT positive_search_votes.date_created as created_date, positive_search_votes.votes, all_search_votes.votes, (positive_search_votes.votes/all_search_votes.votes*100) as helpful_votes
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvote`.`id`=`wiki_helpfulvotemetadata`.`vote_id`
WHERE `wiki_helpfulvote`.`created` >= '2012-01-01'
AND `wiki_document`.`locale` LIKE 'en-US'
@atopal
atopal / gist:3817837
Created October 2, 2012 09:36
conversion rate for registration in AAQ
SELECT active_users.user_date as user_date, active_users.active_users, all_users.all_users, (active_users.active_users/all_users.all_users)*100 as conversion_rate
FROM
(
SELECT DATE(`questions_question`.`created`) as user_date, count(*) as active_users
FROM `auth_user`
JOIN `questions_question` ON `questions_question`.`creator_id`=`auth_user`.`id`
Where `auth_user`.`is_active`='1'
AND DATE(`questions_question`.`created`) LIKE '2012-07-01'
AND DATE(`auth_user`.`date_joined`) LIKE '2012-07-01'
group by DATE(`questions_question`.`created`)
@atopal
atopal / gist:3832348
Created October 4, 2012 09:00
helpful votes from browsing for Spanish
SELECT positive_search_votes.date_created as created_date, positive_search_votes.votes, all_search_votes.votes, (positive_search_votes.votes/all_search_votes.votes*100) as helpful_votes
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvote`.`id`=`wiki_helpfulvotemetadata`.`vote_id`
WHERE `wiki_helpfulvote`.`created` BETWEEN '2012-01-01 0:0:0' AND '2012-09-30 23:59:59'
AND `wiki_document`.`locale` LIKE 'es'
@atopal
atopal / gist:3906711
Created October 17, 2012 16:57
a/b testing of new forum excerpts
SELECT table_numerator.ds, table_numerator.numerator AS clicks, table_denominator.denominator AS searches, round((table_numerator.numerator/ table_denominator.denominator), 2) AS CTR
FROM
(
select ds, count(*) AS numerator
FROM research_logs
WHERE
ds > '2012-10-09'
AND `domain`='support.mozilla.com'
AND ip_address != 'NULL' AND http_version = 200 AND request_type = 'GET'
AND parse_url(empty_string_1,'PATH') RLIKE '\\/en-US\/search\$'