Skip to content

Instantly share code, notes, and snippets.

View randyzwitch's full-sized avatar

Randy Zwitch randyzwitch

View GitHub Profile
@randyzwitch
randyzwitch / rsitecatalyst-search.R
Created February 4, 2014 14:03
Examples of Search functionality for RSiteCatalyst v1.3
#Top 100 Pages where the pagename starts with "Categories"
#Uses searchKW argument
queue_ranked_pages_search <- QueueRanked("production",
"2013-01-01",
"2014-01-28",
c("pageviews", "visits"),
"page",
top = "100",
searchKW = "^Categories"
)
@randyzwitch
randyzwitch / rsitecatalyst-variable-timing.R
Created February 4, 2014 14:23
Example of variable timing on a request call
#Change timing of function call
#Wait 30 seconds between attempts to retrieve the report, try 5 times
queue_overtime_visits_pv_day_social_anomaly2 <- QueueOvertime("production",
"2013-01-01",
"2014-01-28",
c("visits", "pageviews"),
"day",
"Visit_Social",
anomalyDetection = "1",
currentData = "1",
@randyzwitch
randyzwitch / array_custom_types
Last active August 29, 2015 13:57
Example from JMW
#Twitter response comes back as string
#Use JSON.jl to make into a Dict
#Create a custom type from Dict, in this case TWEETS
#Want to define a DataFrame method DataFrame(response::Array{TWEETS,1})
20-element Array{TWEETS,1}:
TWEETS(nothing,nothing,"Thu Mar 06 17:19:12 +0000 2014",nothing,["symbols"=>{},"user_mentions"=>{["screen_name"=>"randyzwitch","id_str"=>"98689850","id"=>98689850,"name"=>"Randy Zwitch","indices"=>{0,12}]},"hashtags"=>{},"urls"=>{}],0,false,nothing,441624046657355777,"441624046657355777","randyzwitch",441623445286436864,"441623445286436864",98689850,"98689850","en",nothing,nothing,nothing,1,true,nothing,"<a href=\"http://janetter.net/\" rel=\"nofollow\">Janetter</a>","@randyzwitch the R gods demand sacrifice!!!!!!!!!!!!!!!",false,["screen_name"=>"Randy_Au","profile_use_background_image"=>true,"id_str"=>"148398537","utc_offset"=>nothing,"listed_count"=>7,"profile_sidebar_border_color"=>"C0DEED","profile_image_url"=>"http://pbs.twimg.com/profile_images/2751420418/7f1ff3346d047d82ca93b9413
@randyzwitch
randyzwitch / composite-df.jl
Created March 7, 2014 15:28
DataFrame method on composite type
function DataFrame(array::Array{TWEETS, 1})
#Empty df as container for results
resultdf = DataFrame()
#Get array of field names as symbols from composite type
cols = names(TWEETS)
#For each field in composite type...
for column in cols
@randyzwitch
randyzwitch / getrealtime.R
Created March 10, 2014 14:38
RSiteCatalyst Realtime reports
#Get Real-Time reports that already set up
realtime_reports <- GetRealTimeConfiguration("<reportsuite>")
@randyzwitch
randyzwitch / saverealtime.R
Created March 10, 2014 14:47
RSiteCatalyst SaveRealTimeConfiguration
SaveRealTimeConfiguration("<report suite>",
metric1 = "instances",
elements1 = c("page", "referringdomain", "sitesection"),
metric2 = "revenue",
elements2 = c("referringdomain", "sitesection")
metric3 = "orders",
elements3 = c("products")
)
@randyzwitch
randyzwitch / realtime-overtime.R
Created March 10, 2014 15:04
RSiteCatalyst GetRealTimeReport - Minimal example
GetRealTimeReport("<report suite>", "instances")
@randyzwitch
randyzwitch / realtime-offset.R
Last active August 29, 2015 13:57
RSiteCatalyst GetRealTimeReport - Offsets
GetRealTimeReport("<report suite>",
"instances",
periodMinutes = "5",
periodCount = "12",
periodOffset = "10")
@randyzwitch
randyzwitch / realtime-element.R
Created March 10, 2014 15:15
RSiteCatalyst GetRealTimeReport - Element
GetRealTimeReport("mlcpwmproduction",
"instances",
"page",
periodMinutes = "9",
periodCount = "3")
@randyzwitch
randyzwitch / r-json-paste.R
Last active August 29, 2015 14:01
JSON in R using paste
#"metrics" would be a user input into a function arguments
metrics <- c("a", "b", "c")
#Loop over the metrics list, appending proper curly braces
metrics_conv <- lapply(metrics, function(x) paste('{"id":', '"', x, '"', '}', sep=""))
#Collapse the list into a proper comma separated string
metrics_final <- paste(metrics_conv, collapse=", ")