Skip to content
Snippets Groups Projects
Commit 3439326a authored by mpotterf's avatar mpotterf
Browse files

no need to run for loop, run onced in Main.r

parent 0fcc18f2
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ create_table_max_v <- 'CREATE TABLE max_v AS SELECT comp_unit.id AS id,
MAX(comp_unit.V) AS max_v FROM comp_unit GROUP BY comp_unit.id'
create_table_UNIT <- 'Create Table UNIT AS SELECT u.*,(select max(stratum.H_dom) From stratum where stratum.data_id = u.data_id) as H_dom,
(select max(stratum.D_gm) From stratum where stratum.data_id = u.data_id) as D_gm,
(select sum(stratum.N) From stratum where stratum.data_id = u.data_id and D_gm >40) as N_where_D_gt_40,
......@@ -52,54 +53,68 @@ create_table_UNIT <- 'Create Table UNIT AS SELECT u.*,(select max(stratum.H_d
##### For each "db_names", defined in main.R ...
# sim_variant <- "without_SA"
# db_names <- c("MV_Hartola",
# "MV_Kitee",
# "MV_Korsnas",
# "MV_Parikkala",
# "MV_Pori",
# "MV_Pyhtaa",
# "MV_Raasepori",
# "MV_Simo",
# "MV_Vaala",
# "MV_Voyri")
for (name in db_names){
# name = "MV_Hartola"
# Connect to the database
#con <- dbConnect(dbDriver("SQLite"), dbname = paste0(path,"input_data/simulated_", sim_variant,"_" ,name , "_rsu.db"))
# db <- dbConnect(dbDriver("SQLite"),
# dbname = paste(inputFolder, paste0(name, ".db"), sep = "/"))
db <- dbConnect(dbDriver("SQLite"),
# for (name in db_names){
# print(name)
# #name = "simulated_without_MV_Korsnas_Wind_1_SA"
# # Connect to database
# db <- dbConnect(dbDriver("SQLite"),
# dbname = paste(inputFolder,
# paste0(name, ".db"), sep = "/"))
#
#
# # If the following tables already exist, for which the query is defined, remove them
# tab_to_delete <- c("OPERS2", "OPERS3", "max_v", "UNIT")
#
# for(i in tab_to_delete){
# if(dbExistsTable(db, i)) {dbRemoveTable(db, i)}
# }
#
# # Run the Queries and create the final table "UNIT",
# # which contains the development of all stands and indicators under the simulated management regimes
# query_to_run <- c(create_table_max_v, create_table_UNIT)
#
# for(i in query_to_run){
# dbExecute(db, i)
# }
#
# dbDisconnect(db)
#
# #!!! REMOVE This, not sure of needed???
# #rm(query_to_run, tab_to_delete, db)
# }
#rm(create_table_max_v, create_table_UNIT)
print("I am in SA")
#name = "simulated_without_MV_Korsnas_Wind_1_SA"
# Connect to database
db <- dbConnect(dbDriver("SQLite"),
dbname = paste(inputFolder,
paste0(name, ".db"), sep = "/"))
# If the following tables already exist, for which the query is defined, remove them
tab_to_delete <- c("OPERS2", "OPERS3", "max_v", "UNIT")
# If the following tables already exist, for which the query is defined, remove them
tab_to_delete <- c("OPERS2", "OPERS3", "max_v", "UNIT")
for(i in tab_to_delete){
if(dbExistsTable(con, i)) {dbRemoveTable(con, i)}
}
for(i in tab_to_delete){
if(dbExistsTable(db, i)) {dbRemoveTable(db, i)}
}
# Run the Queries and create the final table "UNIT",
# which contains the development of all stands and indicators under the simulated management regimes
query_to_run <- c(create_table_max_v, create_table_UNIT)
query_to_run <- c(create_table_max_v, create_table_UNIT)
for(i in query_to_run){
dbExecute(con, i)
}
for(i in query_to_run){
dbExecute(db, i)
}
dbDisconnect(con)
dbDisconnect(db)
rm(query_to_run, tab_to_delete, con)
}
#!!! REMOVE This, not sure of needed???
#rm(query_to_run, tab_to_delete, db)
rm(create_table_max_v, create_table_UNIT)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment