Skip to content

Commit

Permalink
Raw Data can be accessed now too, replacing print with cat
Browse files Browse the repository at this point in the history
  • Loading branch information
SeBassTian23 committed Apr 27, 2017
1 parent 7af540e commit e9d3397
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 45 deletions.
6 changes: 3 additions & 3 deletions R/createDataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ createDataframe <- function(project_info="", project_data =""){
if(!is.null(project_info) && !is.null(project_data)){

# Print Project data receival information
print("Project data received, generating data frame.")
cat("Project data received, generating data frame.\n")

# Exclusion list
ToExclude <- c("protocol_number","protocol_id","id","protocol_name","baseline_values","chlorophyll_spad_calibration","averages","data_raw","baseline_sample","HTML","Macro","GraphType","time","time_offset","get_ir_baseline","get_blank_cal","get_userdef0","get_userdef1","get_userdef2","get_userdef3","get_userdef4","get_userdef5","get_userdef6","get_userdef7","get_userdef8","get_userdef9","get_userdef10","get_userdef11","get_userdef12","get_userdef13","get_userdef14","get_userdef15","get_userdef16","get_userdef17","get_userdef18","get_userdef19","get_userdef20","r","g","b","recall","messages","order")
ToExclude <- c("protocol_number","protocol_id","id","protocol_name","baseline_values","chlorophyll_spad_calibration","averages","baseline_sample","HTML","Macro","GraphType","time","time_offset","get_ir_baseline","get_blank_cal","get_userdef0","get_userdef1","get_userdef2","get_userdef3","get_userdef4","get_userdef5","get_userdef6","get_userdef7","get_userdef8","get_userdef9","get_userdef10","get_userdef11","get_userdef12","get_userdef13","get_userdef14","get_userdef15","get_userdef16","get_userdef17","get_userdef18","get_userdef19","get_userdef20","r","g","b","recall","messages","order")

# Since we have all the information ready
# now it is time to preprocess the data
Expand Down Expand Up @@ -267,7 +267,7 @@ createDataframe <- function(project_info="", project_data =""){
return(dfs)
}
else{
print("Warning: Missing objects")
cat("Warning: Missing objects\n")
return(NULL)
}
}
34 changes: 10 additions & 24 deletions R/getProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,36 @@
#' This function allows you to receive data from PhotosynQ and convert it into a data frame.
#' @param email Your email address you use to login
#' @param projectID The ID of your Project (Just copy the Project ID from the project page or your user page)
#' @param rawTraces Include the raw traces for each measurement (increases data size significantly!)
#' @param processedData Receive the processed data when set to TRUE, receive raw Data when set to FALSE. (raw data will increases data size significantly!)
#' @param rawTraces Adds raw traces to processed data. It is ignored when processedData is set to TRUE. (increases data size significantly!)
#' @keywords Project Data
#' @export
#' @examples
#' getProject("john.doe@domain.com",1566,FALSE)

getProject <- function(email="", projectID="", rawTraces = FALSE){
getProject <- function(email="", projectID="", processedData = TRUE, rawTraces = FALSE){
if(email !="" && projectID != ""){
login <- PhotosynQ::login(email)

# Print a welcome statement
print(paste("Successfully signed in as:", login$name, sep=" "))


if(!is.null(login)){
project_info <- PhotosynQ::getProjectInfo(login$email, login$token, projectID)

# Print Project name
print(paste("Project:", project_info$name, sep=" "))

if(!is.null(project_info)){
project_data <- PhotosynQ::getProjectData(login$email, login$token, projectID, rawTraces)
# Print Project name
cat(paste("Project:", project_info$name, "\n", sep=" "))

project_data <- PhotosynQ::getProjectData(login$email, login$token, projectID, processedData, TRUE)
if(!is.null(project_data)){

dl <- createDataframe(project_info,project_data)
cat("Done\n")
return(dl)

}
else {
print("Warning: Project Data download failed.")
return(NULL)
}
}
else {
print("Warning: Project does not exist.")
return(NULL)
}
}
else {
print("Warning: Login failed.")
return(NULL)
}
}
else {
print("You have to supply email, password and project ID")
cat("You have to supply email, password and project ID\n")
return(NULL)
}
}
15 changes: 8 additions & 7 deletions R/getProjectData.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,41 @@
#' @param email Your email address you use to login
#' @param token Your login token from the login function
#' @param projectID The ID of your Project (Just copy the Project ID from the project page or your user page)
#' @param rawTraces Include the raw traces for each measurement (increases data size significantly!)
#' @param processedData Receive the processed data when set to TRUE, receive raw Data when set to FALSE. (raw data will increases data size significantly!)
#' @param rawTraces Adds raw traces to processed data. It is ignored when processedData is set to TRUE. (increases data size significantly!)
#' @keywords Project Data
#' @export
#' @examples
#' getProjectData("john.doe@domain.com","A67DHsajjshda78",1566, FALSE)

getProjectData <- function(email="", token="", projectID="", rawTraces = FALSE){
getProjectData <- function(email="", token="", projectID="", processedData = TRUE, rawTraces = FALSE){
if(email !="" && token != "" && projectID != ""){
httrFound <- require("httr",quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE)
if(!httrFound){
install.packages("httr")
library("httr",quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE)
}
url <- paste("https://photosynq.org/api/v3/projects/",toString(projectID),"/data.json?user_email=",email,"&user_token=",token,"&upd=true&include_raw_data=",rawTraces, sep="")
url <- paste("https://photosynq.org/api/v3/projects/",toString(projectID),"/data.json?user_email=",email,"&user_token=",token,"&upd=",processedData,"&include_raw_data=",rawTraces, sep="")
request <- httr::GET(url)
if(status_code(request) == 500){
print("Warning: Failed collect project data.")
cat("Warning: Failed collect project data.\n")
return(NULL)
}
content <- content(request)
if(content$status == "success"){
return(content$data)
}
else if(content$status == "failed"){
print(content$notice)
cat(paste(content$notice,"\n", sep=""))
return(NULL)
}
else{
print("Warning: There was an error receiving the project data")
cat("Warning: There was an error receiving the project data.\n")
return(NULL)
}
}
else {
print("Warning: Project does not exist or is not available.")
cat("Warning: Project does not exist or is not available.\n")
return(NULL)
}
}
8 changes: 4 additions & 4 deletions R/getProjectInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ getProjectInfo <- function(email="", token="", projectID=""){
url <- paste("https://photosynq.org/api/v3/projects/",toString(projectID),".json?user_email=",email,"&user_token=",token, sep="")
request <- httr::GET(url)
if(status_code(request) == 500){
print("Warning: Failed to get project info.")
cat("Warning: Failed to receive the project information.\n")
return(NULL)
}
content <- content(request)
if(content$status == "success"){
return(content$project)
}
else if(content$status == "failed"){
print(content$notice)
cat(paste(content$notice,"\n", sep=""))
return(NULL)
}
else{
print("Warning: There was an error receiving the project data")
cat("Warning: There was an error receiving the project data\n")
return(NULL)
}
}
else {
print("Warning: Project does not exist or is not available.")
cat("Warning: Project does not exist or is not available.\n")
return(NULL)
}
}
10 changes: 5 additions & 5 deletions R/login.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ login <- function(email=""){
}
pwd <- getPass(msg = "Your PhotosynQ Password: ", forcemask = FALSE)
if(is.null(pwd)){
print("Info: Login canceled.")
cat("Info: Login canceled.\n")
return(NULL)
}
url <- "https://photosynq.org/api/v3/sign_in.json"
request <- httr::POST(url, body= list("user[email]" = email,"user[password]" = pwd))
if(status_code(request) == 500){
print("Warning: Failed to login.")
cat("Warning: Failed to login.\n")
return(NULL)
}
content <- content(request)
if(content$status == "success"){
paste("Hello", content$user$name, sep=" ")
cat("Successfully signed in as: ", content$user$name,"\n", sep=" ")
result <- list(email=content$user$email,token=content$user$auth_token,name=content$user$name)
return(result)
}
else if(content$status == "failed"){
print(content$notice)
cat(paste(content$notice,"\n", sep=""))
return(NULL)
}
}
else {
print("Warning: Please provide your email to login.")
cat("Warning: Please provide your email to login.\n")
return(NULL)
}
}
4 changes: 2 additions & 2 deletions R/logout.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ logout <- function(token=""){
}
url <- "https://photosynq.org/api/v3/sign_out.json"
request <- httr::DELETE(url, body= list("auth_token" = token))
print("Goodbye!")
cat("Goodbye!\n")
}
else {
print("Warning: You have to provide your login token.")
cat("Warning: You have to provide your login token.\n")
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ project_info <- PhotosynQ::getProjectInfo(login$email, login$token, ID)
```R
ID <- 1556
project_data <- PhotosynQ::getProjectData(login$email, login$token, ID)

# Use raw data
processed_data <- FALSE
project_data <- PhotosynQ::getProjectData(login$email, login$token, ID, processed_data)
```

#### Create a Data frame
Expand Down

0 comments on commit e9d3397

Please sign in to comment.