Something went wrong on our end
check_simulated_db.R 1.41 KiB
#####
#
# Check if all stands have been simulated in the DB
# 2020-08-17
#
#####
# This short script opens the simulated_...db
# It counts if all 650 stands per each stand sequence have been simulated
# If stands are missing it prints the name
### Running on cPouta or WIN local
on_cPouta <- TRUE
### Set the working path to this R-project
path <- paste0(getwd())
if(on_cPouta == TRUE) {
# Multiprocessing version:
library(foreach)
library(doParallel)
numCores <- detectCores()
numCores
inputFolder <- "/media/volume/outp_rcp26"
} else {
# for Windows
inputFolder <- paste(path, "input_data/FIN", sep = "/")
}
## load libraries
library(RSQLite)
## List the names indicated by "simulated_"
db_simulated <- grep(list.files(inputFolder, pattern = ".db$"), pattern="simulated", value=T)
check_function <- function(name){
#name = db_simulated[1]
# Connect to db
db <- dbConnect(dbDriver("SQLite"),
dbname = paste(inputFolder,name, sep = "/"))
# Select column id from table "comp_unit"
rsl <- dbGetQuery( db, paste0("select id from comp_unit"))
# Disconnect database
dbDisconnect(db)
if(length(unique(rsl$id)) != 650) {
print(name)
print(length(unique(rsl$id)))
}
}
if(on_cPouta == TRUE) {
mclapply(db_simulated, check_function, mc.cores = numCores)
} else{
lapply(db_simulated, check_function) # for Windows
}