# HG changeset patch # User siwaa # Date 1689869939 0 # Node ID fb6f7d60508df45d1b90bcf21233d1c4acd2e5b9 # Parent bb1ac57f8545413775ef9287f9cbb4d39994b33f "planemo upload for repository https://forgemia.inra.fr/redelac commit d1c69d78e9ccfe06ceb7609dce59b438cd94d9d8" diff -r bb1ac57f8545 -r fb6f7d60508d redelacSticsInputGenerator.R --- a/redelacSticsInputGenerator.R Fri Jul 07 10:19:22 2023 +0000 +++ b/redelacSticsInputGenerator.R Thu Jul 20 16:18:59 2023 +0000 @@ -1,48 +1,164 @@ library(SticsRFiles) library(dplyr) +library(lubridate) + + +startTime <- Sys.time() workspace <- paste0(getwd(), "/WS") javastics_path <- getwd() txt_path <- paste0(getwd(), "/WS/txt_files") -dir.create(txt_path,recursive = T) +dir.create(txt_path, recursive = T) USMsFile <- "USMs.csv" TecFile <- "Tec.csv" IniFile <- "Ini.csv" StationFile <- "Station.csv" +args = commandArgs(trailingOnly = TRUE) + +genUSMsXmlOneAfterOther <- (args[1] == "usmx_one_after_other") + # USMs file loading + usms_param <- read_params_table(file.path(workspace, USMsFile)) %>% - select(usm_name,datedebut,datefin,finit,nomsol,fstation,fclim1,fclim2,culturean,nbplantes,codesimul,fplt_1,ftec_1,flai_1,fplt_2,ftec_2,flai_2) + select( + usm_name, + datedebut, + datefin, + finit, + nomsol, + fstation, + fclim1, + fclim2, + culturean, + nbplantes, + codesimul, + fplt_1, + ftec_1, + flai_1, + fplt_2, + ftec_2, + flai_2 + ) # Tec files loading and generating xml + tec_param <- read_params_table(file.path(workspace, TecFile)) -columnToRemove <- names(tec_param[grep("juleclair|nbinfloecl", names(tec_param))]) -columnToKeep <- names(tec_param)[names(tec_param) %in% columnToRemove == FALSE] -tec_param <- subset(tec_param, select=columnToKeep) +columnToRemove <- + names(tec_param[grep("juleclair|nbinfloecl", names(tec_param))]) +columnToKeep <- + names(tec_param)[names(tec_param) %in% columnToRemove == FALSE] + +tec_param <- subset(tec_param, select = columnToKeep) + gen_tec_xml(param_df = tec_param, out_dir = workspace) # Ini files loading and generating xml + ini_param <- read_params_table(file.path(workspace, IniFile)) + gen_ini_xml(param_df = ini_param, out_dir = workspace) # Station files loading and generating xml + sta_param <- read_params_table(file.path(workspace, StationFile)) + gen_sta_xml(param_df = sta_param, out_dir = workspace) - -# looping on USMs -for(i in 1:nrow(usms_param)) { - row <- usms_param[i,] - - # generating xml - gen_usms_xml(file = file.path(workspace, "usms.xml"), param_df = row) +if (genUSMsXmlOneAfterOther) { + durGenX <- lubridate::as.duration(0) + durGenT <- lubridate::as.duration(0) + + # looping on USMs + for (i in 1:nrow(usms_param)) { + row <- usms_param[i, ] + + beforeGenXmlTimeI <- Sys.time() + + gen_usms_xml(file = file.path(workspace, "usms.xml"), + param_df = row) + + afterGenXmlTimeI <- Sys.time() + durGenXI <- + lubridate::as.duration(lubridate::interval(beforeGenXmlTimeI, + afterGenXmlTimeI)) + + # one after the other generating txt folder + + beforeGenTxtTimeI <- Sys.time() + + gen_usms_xml2txt( + javastics = javastics_path, + workspace = workspace, + out_dir = txt_path, + verbose = TRUE + ) + + afterGenTxtTimeI <- Sys.time() + durGenTI <- + lubridate::as.duration(lubridate::interval(beforeGenTxtTimeI, + afterGenTxtTimeI)) + + durGenX <- durGenX + durGenXI + durGenT <- durGenT + durGenTI + } +} else { + beforeGenXmlTime <- Sys.time() + + gen_usms_xml(file = file.path(workspace, "usms.xml"), + param_df = usms_param) + + afterGenXmlTime <- Sys.time() + durGenX <- + lubridate::as.duration(lubridate::interval(beforeGenXmlTime, + afterGenXmlTime)) + + beforeGenTxtTime <- Sys.time() + + gen_usms_xml2txt( + javastics = javastics_path, + workspace = workspace, + out_dir = txt_path, + verbose = TRUE + ) + + afterGenTxtTime <- Sys.time() + durGenT <- + lubridate::as.duration(lubridate::interval(beforeGenTxtTime, + afterGenTxtTime)) + +} - # generating txt folder - gen_usms_xml2txt(javastics = javastics_path, - workspace = workspace, - out_dir = txt_path, - verbose = TRUE) -} - +endTime <- Sys.time() +dur <- + lubridate::as.period(lubridate::as.duration(lubridate::interval(startTime, endTime))) +durGenXP <- lubridate::as.period(durGenX) +durGenTP <- lubridate::as.period(durGenT) + +print("REDELAC Report") +print("==============") +print(paste0("number of usms: ", nrow(usms_param))) +print(paste("usms.xml one after the other:", genUSMsXmlOneAfterOther)) +sprintf( + 'overall duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', + lubridate::day(dur), + lubridate::hour(dur), + lubridate::minute(dur), + lubridate::second(dur) +) +sprintf( + 'inside gen_usms_xml duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', + lubridate::day(durGenXP), + lubridate::hour(durGenXP), + lubridate::minute(durGenXP), + lubridate::second(durGenXP) +) +sprintf( + 'inside gen_usms_xml2txt duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', + lubridate::day(durGenTP), + lubridate::hour(durGenTP), + lubridate::minute(durGenTP), + lubridate::second(durGenTP) +) diff -r bb1ac57f8545 -r fb6f7d60508d redelacSticsInputGenerator.bash --- a/redelacSticsInputGenerator.bash Fri Jul 07 10:19:22 2023 +0000 +++ b/redelacSticsInputGenerator.bash Thu Jul 20 16:18:59 2023 +0000 @@ -1,20 +1,20 @@ cp -r /home/rstudio/JavaSTICS-1.5.1-STICS-10.0.0/JavaSTICS-1.5.1-STICS-10.0.0 . && rm -rf JavaSTICS-1.5.1-STICS-10.0.0/config && -cp -r $1/config JavaSTICS-1.5.1-STICS-10.0.0 && -unzip $2 -d TMP && +cp -r $2/config JavaSTICS-1.5.1-STICS-10.0.0 && +unzip -q $3 -d TMP && export WSname=$(ls TMP) && mv TMP/* JavaSTICS-1.5.1-STICS-10.0.0/WS && cp JavaSTICS-1.5.1-STICS-10.0.0/config/param_gen.xml JavaSTICS-1.5.1-STICS-10.0.0/WS && cp JavaSTICS-1.5.1-STICS-10.0.0/config/param_newform.xml JavaSTICS-1.5.1-STICS-10.0.0/WS && -unzip $3 -d TMPbis && +unzip -q $4 -d TMPbis && mv TMPbis/*/* JavaSTICS-1.5.1-STICS-10.0.0/WS && -cp $4 JavaSTICS-1.5.1-STICS-10.0.0/WS/USMs.csv && -cp $5 JavaSTICS-1.5.1-STICS-10.0.0/WS/Tec.csv && -cp $6 JavaSTICS-1.5.1-STICS-10.0.0/WS/Ini.csv && -cp $7 JavaSTICS-1.5.1-STICS-10.0.0/WS/Station.csv && +cp $5 JavaSTICS-1.5.1-STICS-10.0.0/WS/USMs.csv && +cp $6 JavaSTICS-1.5.1-STICS-10.0.0/WS/Tec.csv && +cp $7 JavaSTICS-1.5.1-STICS-10.0.0/WS/Ini.csv && +cp $8 JavaSTICS-1.5.1-STICS-10.0.0/WS/Station.csv && cd JavaSTICS-1.5.1-STICS-10.0.0 && -Rscript --verbose $1/redelacSticsInputGenerator.R && +Rscript --verbose $2/redelacSticsInputGenerator.R $1 && rm WS/1* && mv WS $WSname && -zip -r $WSname $WSname && +zip -q -r $WSname $WSname && cp $WSname.zip $8 diff -r bb1ac57f8545 -r fb6f7d60508d redelacSticsInputGenerator.xml --- a/redelacSticsInputGenerator.xml Fri Jul 07 10:19:22 2023 +0000 +++ b/redelacSticsInputGenerator.xml Thu Jul 20 16:18:59 2023 +0000 @@ -5,8 +5,8 @@ + bash $__tool_directory__/redelacSticsInputGenerator.bash ${IterUsmX} $__tool_directory__ ${Workspace} ${Climat} ${USMs} ${Tec} ${Ini} ${Station} ${GeneratedWorkspace} + ]]>{ @@ -16,6 +16,7 @@ +