Skip to content

Instantly share code, notes, and snippets.

@lumiqai
Last active July 28, 2016 12:22
Show Gist options
  • Select an option

  • Save lumiqai/f72ba07b33e6eac4dc293acf756b499d to your computer and use it in GitHub Desktop.

Select an option

Save lumiqai/f72ba07b33e6eac4dc293acf756b499d to your computer and use it in GitHub Desktop.
suppressPackageStartupMessages(library(RJSONIO))
#We will load all the R files starting from the base directory
base_folder <- getwd()
#The lib folder contains the R program that handles all the communication with Storm.
lib_folder <- paste(base_folder, "/lib", sep="")
#The files in the baseload folder contain all the code related to calculation of baseload, baseload duration etc.
baseload_folder <- paste(base_folder, "/baseload_code", sep="")
#Get the full paths of all the R files inside the specified directories
file.sources = list.files(c(lib_folder, baseload_folder),
pattern="*.R$", full.names=TRUE,
ignore.case=TRUE)
# #We suppress the output of sapply so that it doesn't interfere with working of R Bolt
invisible(sapply(file.sources,source,.GlobalEnv))
#Bolt.process is like the execute function in Java bolt, it is run every time data is received from the preceding bolt.
#It is called from the R script inside the lib folder
Bolt.process <- function(tuple){
#1 because indexes in R start from 1
json <- as.character(tuple$values[1])
#Convert JSON to R list
data <- fromJSON(json)
siteId <- data$siteid
meterId <- data$meterid
acquisitionDate <- data$localdate
rstorm.log(paste("Siteid is: ",siteId))
rstorm.log(paste("localdate is: ",acquisitionDate))
data1 <- fromJSON(json, simplifyWithNames = FALSE)
week_data <- data1$week_data
entryexit.data <- toJSON(entryexits)
rstorm.emit(json.data)
}
Bolt.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment