From 100219e813bf8e95a459f5a0369642818814660b Mon Sep 17 00:00:00 2001 From: Conor Flynn Date: Tue, 18 Apr 2023 23:56:53 -0400 Subject: [PATCH] add edge case support for response and heartbeat interaction --- R-Code-Samples/DataEnginePrimaryFunctions.Rmd | 12 ++++++++++-- R-Code-Samples/ExampleUserClusteringStarter.Rmd | 12 ++++++++++-- R-Code-Samples/GetTransactions.Rmd | 12 ++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/R-Code-Samples/DataEnginePrimaryFunctions.Rmd b/R-Code-Samples/DataEnginePrimaryFunctions.Rmd index 8717c71e..0d375bca 100644 --- a/R-Code-Samples/DataEnginePrimaryFunctions.Rmd +++ b/R-Code-Samples/DataEnginePrimaryFunctions.Rmd @@ -112,6 +112,9 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end else if (grepl("<<>>", temp, fixed=TRUE)) { temp <- readLines(socket, 1) + while(grepl("<<>>", temp, fixed=TRUE)) { + temp <- readLines(socket, 1) + } response <- fromJSON(temp) break } @@ -122,8 +125,13 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end print(paste("Processed", counter, "lines for", protocol)) # add data point line to data frame - temp.df <- as.data.frame(fromJSON(temp)) - df <- rbind.fill(df, temp.df) + tryCatch(expr={ + temp.df <- as.data.frame(fromJSON(temp)) + df <- rbind.fill(df, temp.df) + }, + error=function(e){ + message("Heartbeat execption caught and not parsed.") + }) } output <- list("response"=response, "df"=df) diff --git a/R-Code-Samples/ExampleUserClusteringStarter.Rmd b/R-Code-Samples/ExampleUserClusteringStarter.Rmd index 0b767a6f..c571bd10 100644 --- a/R-Code-Samples/ExampleUserClusteringStarter.Rmd +++ b/R-Code-Samples/ExampleUserClusteringStarter.Rmd @@ -130,6 +130,9 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end else if (grepl("<<>>", temp, fixed=TRUE)) { temp <- readLines(socket, 1) + while(grepl("<<>>", temp, fixed=TRUE)) { + temp <- readLines(socket, 1) + } response <- fromJSON(temp) break } @@ -140,8 +143,13 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end print(paste("Processed", counter, "lines for", protocol)) # add data point line to data frame - temp.df <- as.data.frame(fromJSON(temp)) - df <- rbind.fill(df, temp.df) + tryCatch(expr={ + temp.df <- as.data.frame(fromJSON(temp)) + df <- rbind.fill(df, temp.df) + }, + error=function(e){ + message("Heartbeat execption caught and not parsed.") + }) } output <- list("response"=response, "df"=df) diff --git a/R-Code-Samples/GetTransactions.Rmd b/R-Code-Samples/GetTransactions.Rmd index 83f20a14..15667edf 100644 --- a/R-Code-Samples/GetTransactions.Rmd +++ b/R-Code-Samples/GetTransactions.Rmd @@ -114,6 +114,9 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end else if (grepl("<<>>", temp, fixed=TRUE)) { temp <- readLines(socket, 1) + while(grepl("<<>>", temp, fixed=TRUE)) { + temp <- readLines(socket, 1) + } response <- fromJSON(temp) break } @@ -124,8 +127,13 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end print(paste("Processed", counter, "lines for", protocol)) # add data point line to data frame - temp.df <- as.data.frame(fromJSON(temp)) - df <- rbind.fill(df, temp.df) + tryCatch(expr={ + temp.df <- as.data.frame(fromJSON(temp)) + df <- rbind.fill(df, temp.df) + }, + error=function(e){ + message("Heartbeat execption caught and not parsed.") + }) } output <- list("response"=response, "df"=df)