Skip to content

Commit

Permalink
Update database
Browse files Browse the repository at this point in the history
This version will process raw data and add it to the database.
  • Loading branch information
johnsonra committed Dec 4, 2023
1 parent 0d5dcaa commit 5d4ffd6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ChemotaxisDashboard
Title: Chemotaxis dashboard
Version: 0.1
Version: 0.1.1
Authors@R: c(person('Randy', 'Johnson', email = '[email protected]',
role = c('cre','aut')))
Description: Dashboard for exploring chemotaxis data.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(qc_cardsUI)
export(qc_server)
export(qc_sidebarUI)
import(rlang)
importFrom(DBI,dbAppendTable)
importFrom(DBI,dbConnect)
importFrom(DBI,dbDisconnect)
importFrom(DBI,dbGetQuery)
Expand Down
36 changes: 34 additions & 2 deletions R/initialize.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# initialize.R

#' dbinit
#' Set up database and infrastructure needed to run the Chemotaxis-Dashboard
#' Set up database and infrastructure needed to run the Chemotaxis-Dashboard. If the database already exists and data is not empty, this will append the information in data to the database.
#'
#' @param db_path Character value specifying the path to the file where the database should be initialized.
#' @param data List of data.frames to initialize or add to the database. Internal test data will be used if `data` is NULL.
Expand Down Expand Up @@ -36,35 +36,67 @@ dbinit <- function(db_path, data = NULL)
# add data.frames
if(!'users' %in% tabs &
!is.null(data$users))
{
dbWriteTable(con, "users", data$users)
}else if(!is.null(data$users)){
dbAppendTable(con, "users", data$users)
}

if(!'access' %in% tabs &
!is.null(data$access))
{
dbWriteTable(con, "access", data$access)
}else if(!is.null(data$access)){
dbAppendTable(con, "access", data$access)
}

if(!'expSummary' %in% tabs &
!is.null(data$expSummary))
{
dbWriteTable(con, "expSummary", data$expSummary)
}else if(!is.null(data$expSummary)){
dbAppendTable(con, "expSummary", data$expSummary)
}

if(!'expStats' %in% tabs &
!is.null(data$expStats))
{
dbWriteTable(con, "expStats", data$expStats)
}else if(!is.null(data$expStats)){
dbAppendTable(con, "expStats", data$expStats)
}

if(!'chanSummary' %in% tabs &
!is.null(data$chanSummary))
{
dbWriteTable(con, "chanSummary", data$chanSummary)

}else if(!is.null(data$chanSummary)){
dbAppendTable(con, "chanSummary", data$chanSummary)
}

if(!'chanRaw' %in% tabs &
!is.null(data$chanRaw))
{
dbWriteTable(con, "chanRaw", data$chanRaw)
}else if(!is.null(data$chanRaw)){
dbAppendTable(con, "chanRaw", data$chanRaw)
}

if(!'trackSummary' %in% tabs &
!is.null(data$trackSummary))
{
dbWriteTable(con, "trackSummary", data$trackSummary)
}else if(!is.null(data$trackSummary)){
dbAppendTable(con, "trackSummary", data$trackSummary)
}

if(!'trackRaw' %in% tabs &
!is.null(data$trackRaw))
{
dbWriteTable(con, "trackRaw", data$trackRaw)
}else{
dbAppendTable(con, "trackRaw", data$trackRaw)
}

dbDisconnect(con)
}
Expand Down
13 changes: 9 additions & 4 deletions data-raw/process_raw_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ all_experiments <- all_experiments[!all_experiments %in% done]


# process experiments that haven't been processed yet
processed_data <- process_experiments(all_experiments,
source_dir = file.path(root, 'data-raw', 'results_csv'),
results_dir = file.path(root, '.data'),
seed = 923847)
if(length(all_experiments) > 0)
{
processed_data <- process_experiments(all_experiments,
source_dir = file.path(root, 'data-raw', 'results_csv'),
results_dir = file.path(root, '.data'),
seed = 923847)

dbinit(db_path, processed_data)
}

parallel::stopCluster(parallel::getDefaultCluster())
4 changes: 2 additions & 2 deletions man/dbinit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d4ffd6

Please sign in to comment.