Creation file for DIVA from DataBase

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/SeaDataNetConnector@119275 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Gianpaolo Coro 2015-09-30 15:54:13 +00:00
parent b48f405c99
commit 401e9db924
2 changed files with 29 additions and 7 deletions

View File

@ -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<String, String> statResultMap = new LinkedHashMap<String, String>();
@ -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<Object> 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

View File

@ -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");