package org.gcube.dataanalysis.seadatanet.test;

import java.util.LinkedHashMap;
import java.util.List;

import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent;
import org.gcube.dataanalysis.ecoengine.processing.factories.TransducerersFactory;
import org.gcube.dataanalysis.ecoengine.test.regression.Regressor;
import org.gcube.dataanalysis.seadatanet.SeaDataNetConnector_AutoCorrelation;

public class TestSeaDataNetConnectorAutoCorr {


	 
	public static void main(String[] args) throws Exception {
		//SeaDataNetConnector_AutoCorrelation auto = new SeaDataNetConnector_AutoCorrelation();
//		new SeaDataNetConnector_AutoCorrelation().parseExtension("POLYGON((-206.71875 133.59375,-206.71875 -147.65625,212.34375 -147.65625,212.34375 133.59375,-206.71875 133.59375))");
		System.out.println("TEST 1");
		List<ComputationalAgent> trans = null;
		
		trans = TransducerersFactory.getTransducerers(testConfigLocal());
		ComputationalAgent prova = trans.get(0);
		prova.init();
		prova.compute();
		StatisticalType output = prova.getOutput();
		System.out.println(output.getDescription());
		System.out.println(output.getClass());
		if (output instanceof PrimitiveType){
			PrimitiveType ptype = (PrimitiveType) output;
			LinkedHashMap<String, StatisticalType> map = (LinkedHashMap<String, StatisticalType>)ptype.getContent();
			
			System.out.println(map);
			//System.out.println(FileTools.loadString(file.getAbsolutePath(), "UTF-8"));
		}
		trans = null;
		
		
	}
	
	public static void main1(String[] args) throws Exception {
	System.out.println("TEST 1");
	List<ComputationalAgent> trans = null;
	
	trans = TransducerersFactory.getTransducerers(testConfigLocal());
	ComputationalAgent prova = trans.get(0);
	prova.init();
	prova.compute();
	StatisticalType output = prova.getOutput();
	System.out.println(output.getDescription());
	System.out.println(output.getClass());
	if (output instanceof PrimitiveType){
		PrimitiveType ptype = (PrimitiveType) output;
		LinkedHashMap<String, StatisticalType> map = (LinkedHashMap<String, StatisticalType>)ptype.getContent();
		
		System.out.println(map);
		//System.out.println(FileTools.loadString(file.getAbsolutePath(), "UTF-8"));
	}
	trans = null;
	}
	 
	private static AlgorithmConfiguration testConfigLocal() {
	 
	 AlgorithmConfiguration config = Regressor.getConfig();
	 
	 config.setAgent("GEO_INTERPOLATION");
	 
	 config.setParam("InputTable", "hcaf_d");
	 config.setParam("Longitude", "centerlong");
	 config.setParam("Latitude", "centerlat");
	 config.setParam("Quantity", "landdist");
	 		 
//	 config.setParam("InputTable", "generic_id0c032cb2_01e1_4570_9b84_56979bc046ab");
//	 config.setParam("Longitude", "x");
//	 config.setParam("Latitude", "y");
//	 config.setParam("Quantity", "fvalue");
	 
	 config.setParam("ProjectionExtension", "POLYGON((-206.71875 133.59375,-206.71875 -147.65625,212.34375 -147.65625,212.34375 133.59375,-206.71875 133.59375))");
	 config.setParam("ProjectionResolution", "1");

	 config.setParam("DepthOrHeightLevel", "0");
	 
	 config.setParam("UseCurrentsInformation", "true");
	 
	 
	 config.setParam("DatabaseUserName","dmalgorithms_u");
	 config.setParam("DatabasePassword","cdec755ed6633ba");
	 config.setParam("DatabaseURL","jdbc:postgresql://postgresql-srv-dev.d4science.org/dmalgorithms");
	 config.setParam("DatabaseDriver","org.postgresql.Driver");
		
	return config;
	}
	
	
	private static AlgorithmConfiguration testConfigLocalGeneral() {
		 
		 AlgorithmConfiguration config = Regressor.getConfig();
		 config.setAgent("SEADATANET_CONNECTOR");
		 
		 config.setParam("InputTable", "hcaf_d");
		 config.setParam("Longitude", "centerlong");
		 config.setParam("Latitude", "centerlat");
		 config.setParam("Quantity", "landdist");
		 
		 config.setParam("LongitudeMinValue", "-180");
		 config.setParam("LongitudeMaxValue", "180");
		 config.setParam("LongitudeResolution", "3");
		 
		 config.setParam("LatitudeMinValue", "-80");
		 config.setParam("LatitudeMaxValue", "80");
		 config.setParam("LatitudeResolution", "3");
		 
		 config.setParam("CorrelationLength", "10");
		 config.setParam("SignalNoise", "0.8");
		 config.setParam("DepthLevel", "1");
		 
		 config.setParam("DatabaseUserName","dmalgorithms_u");
		 config.setParam("DatabasePassword","cdec755ed6633ba");
		 config.setParam("DatabaseURL","jdbc:postgresql://postgresql-srv-dev.d4science.org/dmalgorithms");
		 config.setParam("DatabaseDriver","org.postgresql.Driver");
			
		return config;
		}
}
