Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SIMO_output
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clblatte
SIMO_output
Commits
3439326a
Commit
3439326a
authored
4 years ago
by
mpotterf
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
structure_SIMO_rslDB_SA.R
+51
-36
51 additions, 36 deletions
structure_SIMO_rslDB_SA.R
with
51 additions
and
36 deletions
structure_SIMO_rslDB_SA.R
+
51
−
36
View file @
3439326a
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment