Skip to content

Instantly share code, notes, and snippets.

@Ironholds
Created October 11, 2013 22:57
Show Gist options
  • Select an option

  • Save Ironholds/6943291 to your computer and use it in GitHub Desktop.

Select an option

Save Ironholds/6943291 to your computer and use it in GitHub Desktop.
Thanks users on Wikipedia.
#Read in config variables and associated packages.
source("config.r")
#Construct query function
sql.fun <- function(query_statement){
#Open a connection
con <- dbConnect(drv = "MySQL",
username = analytics_user,
password = analytics_pass,
host = analytics_server,
dbname = analytics_database)
#Send the query
QuerySend <- dbSendQuery(con, statement = query_statement)
#Retrieve output of query
output <- fetch(QuerySend, n = -1)
#Kill connection
dbDisconnect(con)
#Return output
return(output)
}
#Retrieve thanks data
thanks_data <- sql.fun("SELECT log_user AS user, log_timestamp AS timestamp FROM logging WHERE log_type = 'thanks';")
#Retrieve preference data, factoring in when thanks was first used/enabled
user_preference <- sql.fun(paste("
SELECT up_user
FROM user_properties WHERE up_user IN
(SELECT DISTINCT(rev_user)
FROM revision
WHERE rev_timestamp >= '",min(thanks_data$timestamp),"'
GROUP BY rev_user)
AND up_property = 'vector-noexperiments';",sep = ""))
#And so the result of "the number of users who have even edited since thanks became active, compared to the number who used the system" iiis..
((nrow(user_preference))/(length(unique(thanks_data$user))+nrow(user_preference))*100)
#7.120085
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment