Skip to content

Commit

Permalink
update r request files
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Apr 28, 2023
1 parent 29a6067 commit cfb346c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
Empty file added R-Code-Samples/.Rhistory
Empty file.
19 changes: 9 additions & 10 deletions R-Code-Samples/DataEnginePrimaryFunctions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -104,7 +103,7 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
# if line is heartbeat then acknowledge and continue
if (grepl("<<<heartbeat>>>", temp, fixed=TRUE))
{
print(paste("Heartbeat read for", protocol, sep=" "))
print(paste0("Heartbeat read for ", protocol))
next
}
Expand All @@ -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)
})
Expand Down
19 changes: 9 additions & 10 deletions R-Code-Samples/ExampleUserClusteringStarter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -122,7 +121,7 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
# if line is heartbeat then acknowledge and continue
if (grepl("<<<heartbeat>>>", temp, fixed=TRUE))
{
print(paste("Heartbeat read for", protocol, sep=" "))
print(paste0("Heartbeat read for ", protocol))
next
}
Expand All @@ -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)
})
Expand Down
21 changes: 10 additions & 11 deletions R-Code-Samples/GetTransactions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -106,7 +105,7 @@ request <- function(protocol, properties = "", headers = "", startdate = "", end
# if line is heartbeat then acknowledge and continue
if (grepl("<<<heartbeat>>>", temp, fixed=TRUE))
{
print(paste("Heartbeat read for", protocol, sep=" "))
print(paste0("Heartbeat read for ", protocol))
next
}
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
```

Expand Down

0 comments on commit cfb346c

Please sign in to comment.