From cfb346c820dc88555c393ad18352385c576869aa Mon Sep 17 00:00:00 2001 From: Conor Flynn Date: Fri, 28 Apr 2023 00:37:24 -0400 Subject: [PATCH] update r request files --- R-Code-Samples/.Rhistory | 0 R-Code-Samples/DataEnginePrimaryFunctions.Rmd | 19 ++++++++--------- .../ExampleUserClusteringStarter.Rmd | 19 ++++++++--------- R-Code-Samples/GetTransactions.Rmd | 21 +++++++++---------- 4 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 R-Code-Samples/.Rhistory diff --git a/R-Code-Samples/.Rhistory b/R-Code-Samples/.Rhistory new file mode 100644 index 00000000..e69de29b diff --git a/R-Code-Samples/DataEnginePrimaryFunctions.Rmd b/R-Code-Samples/DataEnginePrimaryFunctions.Rmd index 0d375bca..a665a4c0 100644 --- a/R-Code-Samples/DataEnginePrimaryFunctions.Rmd +++ b/R-Code-Samples/DataEnginePrimaryFunctions.Rmd @@ -84,9 +84,8 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end #Write this request back to the socket to tell engine what we want writeLines(request.data, socket) - # define data frame - df = data.frame() - temp.df = data.frame() + # define a list which will store the individual rows + rows = list() #Now the engine will begin feeding us data #We grab the first to initialize the data var and then we continue listening\ @@ -104,7 +103,7 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end # if line is heartbeat then acknowledge and continue if (grepl("<<>>", temp, fixed=TRUE)) { - print(paste("Heartbeat read for", protocol, sep=" ")) + print(paste0("Heartbeat read for ", protocol)) next } @@ -121,20 +120,20 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end # increment processed line counter counter <- counter + 1 - if(counter %% 1000 == 0) - print(paste("Processed", counter, "lines for", protocol)) + if(counter %% 1000 == 0){ + print(paste0("Processed ", counter, " lines for ", protocol)) + } # add data point line to data frame tryCatch(expr={ - temp.df <- as.data.frame(fromJSON(temp)) - df <- rbind.fill(df, temp.df) + rows[[counter]] = data.frame(fromJSON(temp)) }, error=function(e){ - message("Heartbeat execption caught and not parsed.") + message("Heartbeat exception caught and not parsed.") }) } - output <- list("response"=response, "df"=df) + output <- list("response"=response, "df"=do.call(rbind.fill, rows)) close(socket) return(output) }) diff --git a/R-Code-Samples/ExampleUserClusteringStarter.Rmd b/R-Code-Samples/ExampleUserClusteringStarter.Rmd index c571bd10..d6993420 100644 --- a/R-Code-Samples/ExampleUserClusteringStarter.Rmd +++ b/R-Code-Samples/ExampleUserClusteringStarter.Rmd @@ -102,9 +102,8 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end #Write this request back to the socket to tell engine what we want writeLines(request.data, socket) - # define data frame - df = data.frame() - temp.df = data.frame() + # define a list which will store the individual rows + rows = list() #Now the engine will begin feeding us data #We grab the first to initialize the data var and then we continue listening\ @@ -122,7 +121,7 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end # if line is heartbeat then acknowledge and continue if (grepl("<<>>", temp, fixed=TRUE)) { - print(paste("Heartbeat read for", protocol, sep=" ")) + print(paste0("Heartbeat read for ", protocol)) next } @@ -139,20 +138,20 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end # increment processed line counter counter <- counter + 1 - if(counter %% 1000 == 0) - print(paste("Processed", counter, "lines for", protocol)) + if(counter %% 1000 == 0){ + print(paste0("Processed ", counter, " lines for ", protocol)) + } # add data point line to data frame tryCatch(expr={ - temp.df <- as.data.frame(fromJSON(temp)) - df <- rbind.fill(df, temp.df) + rows[[counter]] = data.frame(fromJSON(temp)) }, error=function(e){ - message("Heartbeat execption caught and not parsed.") + message("Heartbeat exception caught and not parsed.") }) } - output <- list("response"=response, "df"=df) + output <- list("response"=response, "df"=do.call(rbind.fill, rows)) close(socket) return(output) }) diff --git a/R-Code-Samples/GetTransactions.Rmd b/R-Code-Samples/GetTransactions.Rmd index 15667edf..8dbb749c 100644 --- a/R-Code-Samples/GetTransactions.Rmd +++ b/R-Code-Samples/GetTransactions.Rmd @@ -86,9 +86,8 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end #Write this request back to the socket to tell engine what we want writeLines(request.data, socket) - # define data frame - df = data.frame() - temp.df = data.frame() + # define a list which will store the individual rows + rows = list() #Now the engine will begin feeding us data #We grab the first to initialize the data var and then we continue listening\ @@ -106,7 +105,7 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end # if line is heartbeat then acknowledge and continue if (grepl("<<>>", temp, fixed=TRUE)) { - print(paste("Heartbeat read for", protocol, sep=" ")) + print(paste0("Heartbeat read for ", protocol)) next } @@ -123,20 +122,20 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end # increment processed line counter counter <- counter + 1 - if(counter %% 1000 == 0) - print(paste("Processed", counter, "lines for", protocol)) + if(counter %% 1000 == 0){ + print(paste0("Processed ", counter, " lines for ", protocol)) + } # add data point line to data frame tryCatch(expr={ - temp.df <- as.data.frame(fromJSON(temp)) - df <- rbind.fill(df, temp.df) + rows[[counter]] = data.frame(fromJSON(temp)) }, error=function(e){ - message("Heartbeat execption caught and not parsed.") + message("Heartbeat exception caught and not parsed.") }) } - output <- list("response"=response, "df"=df) + output <- list("response"=response, "df"=do.call(rbind.fill, rows)) close(socket) return(output) }) @@ -526,7 +525,7 @@ users <- get_users() # Next we write a call to get_data to get all needed data: ```{r} startdate <- "2022-01-01" -enddate <- "2022-02-01" +enddate <- "2022-01-10" data <- get_data(startdate, enddate, users) ```