diff --git a/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java b/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java index db7cf88..5606838 100644 --- a/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java +++ b/src/org/gcube/dataanalysis/seadatanet/SeaDataNetConnector.java @@ -19,9 +19,12 @@ import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType; import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes; import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.TableTemplates; import org.gcube.dataanalysis.ecoengine.interfaces.StandardLocalExternalAlgorithm; +import org.gcube.dataanalysis.ecoengine.utils.DatabaseFactory; import org.gcube.dataanalysis.ecoengine.utils.DatabaseUtils; import org.hibernate.SessionFactory; +import weka.classifiers.trees.m5.Impurity; + public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { LinkedHashMap statResultMap = new LinkedHashMap(); @@ -41,6 +44,7 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { File outputfile; @Override + protected void process() throws Exception { String outpath = config.getPersistencePath(); File neofile = new File(outpath,"seadn_diva_"+UUID.randomUUID()+".nc"); @@ -80,7 +84,23 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { } dbconnection = DatabaseUtils.initDBSession(config); + + String query = "select "+config.getParam("Longitude")+","+ + config.getParam("Latitude")+","+config.getParam("Quantity") + + " From " + getInputParameter("InputTable")+" ORDER BY RANDOM() limit 1000"; + AnalysisLogger.getLogger().debug("Query: "+query); + List dataList = DatabaseFactory.executeSQLQuery(query , dbconnection); + + + File fileForDiva= new File(outpath,"file_for_diva_"+UUID.randomUUID()+".txt"); + BufferedWriter fileWriterDiva = new BufferedWriter(new FileWriter(fileForDiva)); + AnalysisLogger.getLogger().debug("writing input file in: "+fileForDiva.getAbsolutePath() ); + for(Object o : dataList){ + Object[] oarray = (Object[]) o; + fileWriterDiva.write(" "+oarray[0]+" "+oarray[1]+" "+oarray[2]+"\n"); + } + fileWriterDiva.close(); } @@ -116,11 +136,11 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { PrimitiveType p7 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, "LatitudeMinValue", - "Minimum value of Latitude Range","-90"); + "Minimum value of Latitude Range","-85"); PrimitiveType p8 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, "LatitudeMaxValue", - "Maximum value of Latitude Range","90"); + "Maximum value of Latitude Range","85"); PrimitiveType p9 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, "LatitudeResolution", @@ -172,11 +192,13 @@ public class SeaDataNetConnector extends StandardLocalExternalAlgorithm { "Output file in NetCDF format"); - PrimitiveType p = new PrimitiveType(HashMap.class.getName(), - PrimitiveType.stringMap2StatisticalMap(statResultMap), PrimitiveTypes.MAP, - "Statistical results","Statistical results from DIVA fit"); + for (String key:statResultMap.keySet()){ + String value = statResultMap.get(key); + PrimitiveType val = new PrimitiveType(String.class.getName(),value, + PrimitiveTypes.STRING, key, key); + outputDivaMap.put(key, val); + } - outputDivaMap.put("Statistical fit parameters", p); outputDivaMap.put("Netcdf output file", file); PrimitiveType hashma = new PrimitiveType(HashMap.class.getName(), outputDivaMap diff --git a/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java b/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java index 20829ad..6c33a28 100644 --- a/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java +++ b/src/org/gcube/dataanalysis/seadatanet/test/TestSeaDataNetConnector.java @@ -48,7 +48,7 @@ public class TestSeaDataNetConnector { config.setParam("Latitude", "centerlat"); config.setParam("Quantity", "landdist"); - config.setParam("LongitudeMinValue", "pippo"); + config.setParam("LongitudeMinValue", "76"); config.setParam("LongitudeMaxValue", "78"); config.setParam("LongitudeResolution", "1");