This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(k < 2){ | |
| drink_to_forget() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT regexp_extract(uri_path, '/((\\d+px-)?[^/]+)$', 1) as uri_file | |
| FROM wmf_raw.webrequest | |
| WHERE year = 2014 AND month = 09 AND day = 23 AND | |
| hour = 07 AND webrequest_source='upload' LIMIT 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //R | |
| min lq mean | |
| 200422 201139.5 202649.46 | |
| 15 18.0 33.01 | |
| median uq max neval | |
| 201427 201824 258190 100 | |
| 37 51 56 100 | |
| //C++ | |
| min lq mean median |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Includes/namespaces | |
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| // Recursive session counting function | |
| // [[Rcpp::export]] | |
| int session_count(NumericVector x, int local_minimum) { | |
| //Create output object | |
| int count; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| intertimes <- function(x, local_minimum){ | |
| return(length(x[x > local_minimum]) + 1) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test Freq | |
| 1 Cable 416932 | |
| 2 Corporate 13848 | |
| 3 Dial-up 77302 | |
| 4 Invalid 17842 | |
| 5 Unknown 71175 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Intertime computation timings, for a test vector of 3.4k elements. | |
| #Original C++ implementation | |
| expr min lq mean median uq max neval | |
| { test <- intertime(test_vec) } 3.982 4.25 7.805621 4.3405 4.564 687.78 1000 | |
| #C++ implementation with RCpp's "diff()" - syntactic sugar around adjacent_difference | |
| expr min lq mean median uq max neval | |
| { test <- intertime2(test_vec) } 4.181 4.354 9.668984 4.437 4.696 823 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > z <- c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE) | |
| > | |
| > rle(z) | |
| Run Length Encoding | |
| lengths: int [1:5] 2 2 1 1 3 | |
| values : logi [1:5] TRUE FALSE TRUE FALSE TRUE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #For our test object, we have x, a data.table | |
| timestamp tz order | |
| 1: 20140907142430 Europe/Warsaw 1 | |
| 2: 20141005162245 Europe/Paris 2 | |
| 3: 20140908142859 Europe/Rome 3 | |
| 4: 20140903093741 Asia/Yerevan 4 | |
| 5: 20140805102142 America/Sao_Paulo 5 | |
| 6: 20140905142222 Europe/Brussels 6 | |
| 7: 20140819225906 Europe/Rome 7 | |
| 8: 20140811190410 Europe/London 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x <- x[, j = { | |
| #Copy object | |
| copy.dt <- copy(.SD) | |
| #Convert timestamps | |
| timestamps <- mw_strptime(copy.dt$timestamp) | |
| #Extract timestamps, convert as appropriate. | |
| copy.dt$original_timestamp <- as.character(timestamps) |