From fea7e653f46f55599d77e6d1ff20c939a749569f Mon Sep 17 00:00:00 2001 From: francesco amato Date: Fri, 6 Dec 2019 14:54:03 +0100 Subject: [PATCH] s --- RScripts/selemix/IS2_selemix.R | 2 +- .../app/service/AdministrationService.java | 45 ++++++++++++++ .../it/istat/is2/workflow/engine/EngineR.java | 36 +++++++++++- src/main/resources/templates/admin/home.html | 58 +++++++++++++++++++ 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 src/main/java/it/istat/is2/app/service/AdministrationService.java create mode 100644 src/main/resources/templates/admin/home.html diff --git a/RScripts/selemix/IS2_selemix.R b/RScripts/selemix/IS2_selemix.R index 49502b29..c1f99b8c 100644 --- a/RScripts/selemix/IS2_selemix.R +++ b/RScripts/selemix/IS2_selemix.R @@ -93,7 +93,7 @@ library("SeleMix") #stima completa is2_mlest <- function(workset,params, s=S,x=X,y=Y,z=Z, ...) { #environment check - print(class(params)) + print(params) print("----") print(x) print("----") diff --git a/src/main/java/it/istat/is2/app/service/AdministrationService.java b/src/main/java/it/istat/is2/app/service/AdministrationService.java new file mode 100644 index 00000000..8a227034 --- /dev/null +++ b/src/main/java/it/istat/is2/app/service/AdministrationService.java @@ -0,0 +1,45 @@ +/** + * Copyright 2019 ISTAT + * + * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. You may + * obtain a copy of the Licence at: + * + * http://ec.europa.eu/idabc/eupl5 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * Licence for the specific language governing permissions and limitations under + * the Licence. + * + * @author Francesco Amato + * @author Mauro Bruno + * @author Paolo Francescangeli + * @author Renzo Iannacone + * @author Stefano Macone + * @version 1.0 + */ +package it.istat.is2.app.service; + +import java.io.File; +import java.io.IOException; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class AdministrationService { + + @Value("${path.script.R}") + private String pathR; + + @Value("${RServe.file.start}") + private String startRServe; + + public void startR() throws IOException { + Process process = Runtime.getRuntime().exec("cmd /c "+startRServe, null, new File(pathR)); + + } +} diff --git a/src/main/java/it/istat/is2/workflow/engine/EngineR.java b/src/main/java/it/istat/is2/workflow/engine/EngineR.java index cf603c1f..e9495dca 100644 --- a/src/main/java/it/istat/is2/workflow/engine/EngineR.java +++ b/src/main/java/it/istat/is2/workflow/engine/EngineR.java @@ -141,7 +141,7 @@ public void init(DataProcessing dataProcessing, StepInstance stepInstance) throw prepareEnv(); createConnection(serverRHost, serverRPort); bindInputColumns(worksetVariabili, EngineR.IS2_WORKSET); - bindInputColumns(parametriMap, EngineR.IS2_PARAMETRI); + bindInputColumnsParams(parametriMap, EngineR.IS2_PARAMETRI); bindInputColumns(ruleset, EngineR.IS2_RULESET); setRuoli(ruoliVariabileNome); @@ -218,6 +218,40 @@ public void bindInputColumns(LinkedHashMap> workset, S } } + + public void bindInputColumnsParams(LinkedHashMap> workset, String varR) + throws REngineException { + + if (!workset.isEmpty()) { + List keys = new ArrayList(workset.keySet()); + String listaCampi = ""; + String listaCampiLabel = ""; + int size = keys.size(); + String key = ""; + + for (int i = 0; i < size; i++) { + key = keys.get(i); + + String[] arrX = workset.get(key).toArray(new String[workset.get(key).size()]); + listaCampi += key + ","; + listaCampiLabel += "'" + key + "',"; + connection.assign(key, arrX); + } + listaCampi = listaCampi.substring(0, listaCampi.length() - 1); + listaCampiLabel = listaCampiLabel.substring(0, listaCampiLabel.length() - 1); + connection.eval(varR + " <- c(" + listaCampi + ")"); + + // assegnazione nome dei campi alle colonne + + String namecols = ((size > 1) ? "col" : "") + "names(" + varR + ") = c(" + listaCampiLabel + ")"; + // String exec = "colnames(" + varR + ") = c(" + listaCampi + ")"; + Logger.getRootLogger().debug("Bind input columns names " + namecols); + connection.eval(namecols); + + } + } + + private boolean isNumeric(String[] arrX) { // TODO Auto-generated method stub diff --git a/src/main/resources/templates/admin/home.html b/src/main/resources/templates/admin/home.html new file mode 100644 index 00000000..77b9101e --- /dev/null +++ b/src/main/resources/templates/admin/home.html @@ -0,0 +1,58 @@ + + + + + + + + + +
+ +
+ + + +
+ + +
+
+ Start R +
+
+
+
+ +