git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineExternalAlgorithms@99164 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3515f40d6e
commit
6b3939fcb1
|
@ -0,0 +1,222 @@
|
|||
package org.gcube.dataanalysis.geothermal;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.contentmanagement.graphtools.data.conversions.ImageTools;
|
||||
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
|
||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
|
||||
import org.gcube.dataanalysis.ecoengine.configuration.INFRASTRUCTURE;
|
||||
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
|
||||
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
|
||||
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
|
||||
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;
|
||||
import org.gcube.dataanalysis.ecoengine.interfaces.Transducerer;
|
||||
import org.gcube.dataanalysis.ecoengine.utils.DatabaseFactory;
|
||||
import org.gcube.dataanalysis.ecoengine.utils.DatabaseUtils;
|
||||
import org.gcube.dataanalysis.ecoengine.utils.IOHelper;
|
||||
import org.gcube.dataanalysis.ecoengine.utils.ResourceFactory;
|
||||
import org.gcube.dataanalysis.geo.algorithms.XYExtraction;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
|
||||
public abstract class AbstractProcess implements Transducerer {
|
||||
|
||||
static String geothermalData = "GeothermalManagementArea_ERANET";
|
||||
String featuresTable = "gth"+UUID.randomUUID().toString().replace("_", "").replace("-","");
|
||||
|
||||
// String getTable = "select distinct f_name, f_area, f_f1990_mwe, f_f1995_mwt, f_f1995_h_tjy, f_f1995_mwe, f_f2000_mwt, f_f2000_h_tjy, f_f2000_mwe, f_f2005_mwt, f_f2005_h_tjy, f_f2005_mwe, f_f2010_mwt, f_f2010_h_tjy, f_f2010_mwe, f_f2013_mwe from "+featuresTable;
|
||||
|
||||
String getTable = "select distinct f_NAME,f_AREA,f_MWe_1990,f_MWth_1995,f_H_TJy_1995,f_MWe_1995,f_MWth_2000,f_H_TJy_2000,f_MWe_2000,f_MWth_2005,f_H_TJy_2005,f_MWe_2005,f_MWth_2010,f_H_TJy_2010,f_MWe_2010,f_MWe_2013 from "+featuresTable;
|
||||
|
||||
AlgorithmConfiguration config;
|
||||
float status;
|
||||
public static boolean display = false;
|
||||
static String MWE = "MegaWatt Electrical";
|
||||
static String MWT = "MegaWatt Thermal";
|
||||
static String TJY = "Heat TeraJoule per Year";
|
||||
protected static String countryParam = "CountryName";
|
||||
protected static String yearStartParam = "StartYear";
|
||||
protected static String yearEndParam = "EndYear";
|
||||
|
||||
public List<StatisticalType> inputs = new ArrayList<StatisticalType>();
|
||||
public HashMap<String, Image> producedImages = new HashMap<String, Image>();
|
||||
|
||||
protected void extractElements() throws Exception{
|
||||
AnalysisLogger.getLogger().debug("General Processing: Extracting features ");
|
||||
|
||||
config.setParam("Layer",geothermalData);
|
||||
config.setParam("Z","0");
|
||||
config.setParam("TimeIndex","0");
|
||||
config.setParam("BBox_LowerLeftLat","-90");
|
||||
config.setParam("BBox_LowerLeftLong","-180");
|
||||
config.setParam("BBox_UpperRightLat","90");
|
||||
config.setParam("BBox_UpperRightLong","180");
|
||||
config.setParam("XResolution","1");
|
||||
config.setParam("YResolution","1");
|
||||
config.setParam("OutputTableName",featuresTable);
|
||||
config.setParam("OutputTableLabel",featuresTable);
|
||||
|
||||
XYExtraction extractor = new XYExtraction();
|
||||
extractor.setConfiguration(config);
|
||||
extractor.init();
|
||||
extractor.compute();
|
||||
AnalysisLogger.getLogger().debug("General Processing: All features extracted in the table: "+featuresTable);
|
||||
}
|
||||
|
||||
abstract void initDatasets();
|
||||
abstract void fulfillDataset(String f_name, String f_area, double f_f1990_mwe, double f_f1995_mwt, double f_f1995_h_tjy, double f_f1995_mwe, double f_f2000_mwt, double f_f2000_h_tjy,
|
||||
double f_f2000_mwe, double f_f2005_mwt, double f_f2005_h_tjy, double f_f2005_mwe, double f_f2010_mwt, double f_f2010_h_tjy, double f_f2010_mwe, double f_f2013_mwe, int startYear, int endYear);
|
||||
abstract JFreeChart createChartForMWE();
|
||||
abstract JFreeChart createChartForMWT();
|
||||
abstract JFreeChart createChartForTJY();
|
||||
|
||||
abstract void renderChartForMWE();
|
||||
abstract void renderChartForMWT();
|
||||
abstract void renderChartForTJY();
|
||||
|
||||
@Override
|
||||
public void compute() throws Exception {
|
||||
SessionFactory session = null;
|
||||
try {
|
||||
extractElements();
|
||||
status = 30;
|
||||
session = DatabaseUtils.initDBSession(config);
|
||||
List<Object> rows = DatabaseFactory.executeSQLQuery(getTable, session);
|
||||
|
||||
initDatasets();
|
||||
String countryFilter = config.getParam(countryParam);
|
||||
int startYearFilter = 0;
|
||||
int endYearFilter = 3000;
|
||||
try{startYearFilter = Integer.parseInt(config.getParam(yearStartParam));}catch(Exception e1){}
|
||||
|
||||
try{endYearFilter = Integer.parseInt(config.getParam(yearEndParam));}catch(Exception e1){}
|
||||
|
||||
if (endYearFilter<startYearFilter)
|
||||
throw new Exception("Invalid Years Range");
|
||||
|
||||
int nrows = rows.size();
|
||||
|
||||
float step = (float)MathFunctions.roundDecimal((90d-status)/(double)nrows,2);
|
||||
|
||||
for (Object row : rows) {
|
||||
Object[] rowA = (Object[]) row;
|
||||
String country = ""+rowA[0];
|
||||
|
||||
if (countryFilter==null || countryFilter.length()==0 || countryFilter.equalsIgnoreCase("ALL") || countryFilter.equalsIgnoreCase(country)){
|
||||
|
||||
// f_name, f_area, f_f1990_mwe, f_f1995_mwt, f_f1995_h_tjy, f_f1995_mwe, f_f2000_mwt, f_f2000_h_tjy, f_f2000_mwe, f_f2005_mwt, f_f2005_h_tjy, f_f2005_mwe, f_f2010_mwt, f_f2010_h_tjy, f_f2010_mwe, f_f2013_mwe
|
||||
fulfillDataset(""+rowA[0], ""+rowA[1], Double.parseDouble("" + rowA[2]),Double.parseDouble("" + rowA[3]),Double.parseDouble("" + rowA[4]),Double.parseDouble("" + rowA[5]),
|
||||
Double.parseDouble("" + rowA[6]),Double.parseDouble("" + rowA[7]),Double.parseDouble("" + rowA[8]),Double.parseDouble("" + rowA[9]),Double.parseDouble("" + rowA[10]),
|
||||
Double.parseDouble("" + rowA[11]),Double.parseDouble("" + rowA[12]),Double.parseDouble("" + rowA[13]),Double.parseDouble("" + rowA[14]),Double.parseDouble("" + rowA[15]), startYearFilter, endYearFilter);
|
||||
}
|
||||
|
||||
status=Math.min(status+step,90);
|
||||
}
|
||||
|
||||
try{
|
||||
JFreeChart chartMWE = createChartForMWE();
|
||||
Image imageMWE = ImageTools.toImage(chartMWE.createBufferedImage(680, 420));
|
||||
producedImages.put(MWE, imageMWE);
|
||||
if (display)renderChartForMWE();
|
||||
}catch(Exception e){AnalysisLogger.getLogger().debug("Could not produce chart for MWE");}
|
||||
|
||||
try{
|
||||
JFreeChart chartMWT = createChartForMWT();
|
||||
Image imageMWT = ImageTools.toImage(chartMWT.createBufferedImage(680, 420));
|
||||
producedImages.put(MWT, imageMWT);
|
||||
if (display)renderChartForMWT();
|
||||
}catch(Exception e){AnalysisLogger.getLogger().debug("Could not produce chart for MWT");}
|
||||
try{
|
||||
JFreeChart chartTJY = createChartForTJY();
|
||||
Image imageTJY = ImageTools.toImage(chartTJY.createBufferedImage(680, 420));
|
||||
producedImages.put(TJY, imageTJY);
|
||||
if (display)renderChartForTJY();
|
||||
}catch(Exception e){AnalysisLogger.getLogger().debug("Could not produce chart for TJY");}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
try {
|
||||
AnalysisLogger.getLogger().debug("Dropping table "+featuresTable);
|
||||
DatabaseFactory.executeSQLUpdate(DatabaseUtils.dropTableStatement(featuresTable), session);
|
||||
AnalysisLogger.getLogger().debug("Table "+featuresTable+" dropped");
|
||||
} catch (Exception ee) {
|
||||
AnalysisLogger.getLogger().debug("Could not drop table "+featuresTable+": "+ee.getLocalizedMessage());
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
status = 100;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public INFRASTRUCTURE getInfrastructure() {
|
||||
return INFRASTRUCTURE.LOCAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatisticalType> getInputParameters() {
|
||||
|
||||
IOHelper.addStringInput(inputs, countryParam, "The country on which the analysis will focus (ALL to get statistics about all countries)", "ALL");
|
||||
IOHelper.addIntegerInput(inputs, yearStartParam, "The starting year of the analysis", "1990");
|
||||
IOHelper.addIntegerInput(inputs, yearEndParam, "The final year of the analysis", "2013");
|
||||
|
||||
DatabaseType.addDefaultDBPars(inputs);
|
||||
return inputs;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatisticalType getOutput() {
|
||||
PrimitiveType images = new PrimitiveType(HashMap.class.getName(), producedImages, PrimitiveTypes.IMAGES, "images", "Trends");
|
||||
LinkedHashMap<String, StatisticalType> outputmap = new LinkedHashMap<String, StatisticalType>();
|
||||
outputmap.put("Images", images);
|
||||
|
||||
PrimitiveType output = new PrimitiveType(HashMap.class.getName(), outputmap, PrimitiveTypes.MAP, "ResultsMap", "Results Map");
|
||||
return output;
|
||||
}
|
||||
|
||||
protected ResourceFactory resourceManager;
|
||||
public String getResourceLoad() {
|
||||
if (resourceManager == null)
|
||||
resourceManager = new ResourceFactory();
|
||||
return resourceManager.getResourceLoad(1);
|
||||
}
|
||||
|
||||
public String getResources() {
|
||||
return ResourceFactory.getResources(100f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfiguration(AlgorithmConfiguration arg0) {
|
||||
config = arg0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
AnalysisLogger.getLogger().debug("Shutdown");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.gcube.dataanalysis.geothermal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
|
||||
import org.gcube.dataanalysis.ecoengine.utils.IOHelper;
|
||||
|
||||
public class EnergyHistogramAggregated extends EnergyHistogramPerYear {
|
||||
|
||||
public static enum operators {
|
||||
AVG, SUM
|
||||
};
|
||||
|
||||
static String aggregationParam = "Aggregation";
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "An algorithm reporting the aggregated energy in a time range produced by the countries contributing to EGIP";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatisticalType> getInputParameters() {
|
||||
|
||||
List<StatisticalType> inputs = super.getInputParameters();
|
||||
IOHelper.addEnumerateInput(inputs, operators.values(), aggregationParam, "Aggregation Function", operators.AVG.toString());
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
void fulfillDataset(String f_name, String f_area, double f_f1990_mwe, double f_f1995_mwt, double f_f1995_h_tjy, double f_f1995_mwe, double f_f2000_mwt, double f_f2000_h_tjy, double f_f2000_mwe, double f_f2005_mwt, double f_f2005_h_tjy, double f_f2005_mwe, double f_f2010_mwt, double f_f2010_h_tjy, double f_f2010_mwe, double f_f2013_mwe, int startYear, int endYear) {
|
||||
|
||||
double aggregatedMWE = 0;
|
||||
double counterMWE = 0;
|
||||
double aggregatedMWT = 0;
|
||||
double counterMWT = 0;
|
||||
double aggregatedTJY = 0;
|
||||
double counterTJY = 0;
|
||||
|
||||
if (startYear <= 1990 && endYear >= 1990) {
|
||||
aggregatedMWE += f_f1990_mwe;
|
||||
counterMWE++;
|
||||
}
|
||||
|
||||
if (startYear <= 1995 && endYear >= 1995) {
|
||||
aggregatedMWE += f_f1995_mwe;
|
||||
aggregatedMWT += f_f1995_mwt;
|
||||
aggregatedTJY += f_f1995_h_tjy;
|
||||
counterMWE++;
|
||||
counterMWT++;
|
||||
counterTJY++;
|
||||
}
|
||||
if (startYear <= 2000 && endYear >= 2000) {
|
||||
aggregatedMWE += f_f2000_mwe;
|
||||
aggregatedMWT += f_f2000_mwt;
|
||||
aggregatedTJY += f_f2000_h_tjy;
|
||||
counterMWE++;
|
||||
counterMWT++;
|
||||
counterTJY++;
|
||||
}
|
||||
if (startYear <= 2005 && endYear >= 2005) {
|
||||
aggregatedMWE += f_f2005_mwe;
|
||||
aggregatedMWT += f_f2005_mwt;
|
||||
aggregatedTJY += f_f2005_h_tjy;
|
||||
counterMWE++;
|
||||
counterMWT++;
|
||||
counterTJY++;
|
||||
}
|
||||
if (startYear <= 2010 && endYear >= 2010) {
|
||||
aggregatedMWE += f_f2010_mwe;
|
||||
aggregatedMWT += f_f2010_mwt;
|
||||
aggregatedTJY += f_f2010_h_tjy;
|
||||
counterMWE++;
|
||||
counterMWT++;
|
||||
counterTJY++;
|
||||
}
|
||||
if (startYear <= 2013 && endYear >= 2013)
|
||||
aggregatedMWE += f_f2013_mwe;
|
||||
counterMWE++;
|
||||
|
||||
String aggregation = config.getParam(aggregationParam);
|
||||
operators e = operators.AVG;
|
||||
if (aggregation != null)
|
||||
try {
|
||||
e = operators.valueOf(aggregation);
|
||||
} catch (Exception e1) {
|
||||
}
|
||||
|
||||
switch (e) {
|
||||
case AVG:
|
||||
aggregatedMWE = aggregatedMWE / (double) counterMWE;
|
||||
aggregatedMWT = aggregatedMWT / (double) counterMWT;
|
||||
aggregatedTJY = aggregatedTJY / (double) counterTJY;
|
||||
datasetMWE.addValue(aggregatedMWE,f_name,e.toString()+"_MWe");
|
||||
datasetMWT.addValue(aggregatedMWT, f_name, e.toString()+"_MWt");
|
||||
datasetTJY.addValue(aggregatedTJY, f_name ,e.toString()+"_H_TJy");
|
||||
break;
|
||||
default:
|
||||
aggregatedTJY = aggregatedTJY / (double) counterTJY;
|
||||
datasetMWE = null;
|
||||
datasetMWT = null;
|
||||
datasetTJY.addValue(aggregatedTJY, f_name ,e.toString()+"_H_TJy");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.gcube.dataanalysis.geothermal;
|
||||
|
||||
public class EnergyHistogramPerCountry extends EnergyHistogramPerYear {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "An algorithm reporting the energy produced by the countries contributing to EGIP";
|
||||
}
|
||||
|
||||
@Override
|
||||
void fulfillDataset(String f_name, String f_area, double f_f1990_mwe, double f_f1995_mwt, double f_f1995_h_tjy, double f_f1995_mwe, double f_f2000_mwt, double f_f2000_h_tjy, double f_f2000_mwe, double f_f2005_mwt, double f_f2005_h_tjy, double f_f2005_mwe, double f_f2010_mwt, double f_f2010_h_tjy, double f_f2010_mwe, double f_f2013_mwe, int startYear, int endYear) {
|
||||
|
||||
if (startYear <= 1990 && endYear >= 1990)
|
||||
datasetMWE.addValue(f_f1990_mwe, f_name, "1990");
|
||||
if (startYear <= 1995 && endYear >= 1995) {
|
||||
datasetMWE.addValue(f_f1995_mwe, f_name, "1995");
|
||||
datasetMWT.addValue(f_f1995_mwt, f_name, "1995");
|
||||
datasetTJY.addValue(f_f1995_h_tjy, f_name, "1995");
|
||||
}
|
||||
if (startYear <= 2000 && endYear >= 2000) {
|
||||
datasetMWE.addValue(f_f2000_mwe, f_name, "2000");
|
||||
datasetMWT.addValue(f_f2000_mwt, f_name, "2000");
|
||||
datasetTJY.addValue(f_f2000_h_tjy, f_name, "2000");
|
||||
}
|
||||
if (startYear <= 2005 && endYear >= 2005) {
|
||||
datasetMWE.addValue(f_f2005_mwe, f_name, "2005");
|
||||
datasetMWT.addValue(f_f2005_mwt, f_name, "2005");
|
||||
datasetTJY.addValue(f_f2005_h_tjy, f_name, "2005");
|
||||
}
|
||||
if (startYear <= 2010 && endYear >= 2010) {
|
||||
datasetMWE.addValue(f_f2010_mwe, f_name, "2010");
|
||||
datasetMWT.addValue(f_f2010_mwt, f_name, "2010");
|
||||
datasetTJY.addValue(f_f2010_h_tjy, f_name, "2010");
|
||||
}
|
||||
if (startYear <= 2013 && endYear >= 2013)
|
||||
datasetMWE.addValue(f_f2013_mwe, f_name, "2013");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package org.gcube.dataanalysis.geothermal;
|
||||
|
||||
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.data.category.DefaultCategoryDataset;
|
||||
|
||||
public class EnergyHistogramPerYear extends AbstractProcess {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "An algorithm reporting the energy produced per year by the countries contributing to EGIP";
|
||||
}
|
||||
|
||||
DefaultCategoryDataset datasetMWE = new DefaultCategoryDataset();
|
||||
DefaultCategoryDataset datasetMWT = new DefaultCategoryDataset();
|
||||
DefaultCategoryDataset datasetTJY = new DefaultCategoryDataset();
|
||||
|
||||
|
||||
@Override
|
||||
void initDatasets() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
void fulfillDataset(String f_name, String f_area, double f_f1990_mwe, double f_f1995_mwt, double f_f1995_h_tjy, double f_f1995_mwe, double f_f2000_mwt, double f_f2000_h_tjy, double f_f2000_mwe, double f_f2005_mwt, double f_f2005_h_tjy, double f_f2005_mwe, double f_f2010_mwt, double f_f2010_h_tjy, double f_f2010_mwe, double f_f2013_mwe,int startYear, int endYear) {
|
||||
|
||||
if (startYear <= 1990 && endYear >= 1990)
|
||||
datasetMWE.addValue(f_f1990_mwe, "1990", f_name);
|
||||
if (startYear <= 1995 && endYear >= 1995) {
|
||||
datasetMWE.addValue(f_f1995_mwe, "1995", f_name);
|
||||
datasetMWT.addValue(f_f1995_mwt, "1995",f_name );
|
||||
datasetTJY.addValue(f_f1995_h_tjy, "1995",f_name );
|
||||
}
|
||||
if (startYear <= 2000 && endYear >= 2000) {
|
||||
datasetMWE.addValue(f_f2000_mwe, "2000",f_name);
|
||||
datasetMWT.addValue(f_f2000_mwt, "2000",f_name );
|
||||
datasetTJY.addValue(f_f2000_h_tjy, "2000",f_name );
|
||||
}
|
||||
if (startYear <= 2005 && endYear >= 2005) {
|
||||
datasetMWE.addValue(f_f2005_mwe, "2005",f_name);
|
||||
datasetMWT.addValue(f_f2005_mwt, "2005",f_name );
|
||||
datasetTJY.addValue(f_f2005_h_tjy, "2005",f_name );
|
||||
}
|
||||
if (startYear <= 2010 && endYear >= 2010) {
|
||||
datasetMWE.addValue(f_f2010_mwe,"2010",f_name);
|
||||
datasetMWT.addValue(f_f2010_mwt, "2010",f_name );
|
||||
datasetTJY.addValue(f_f2010_h_tjy, "2010",f_name );
|
||||
}
|
||||
if (startYear <= 2013 && endYear >= 2013)
|
||||
datasetMWE.addValue(f_f2013_mwe,"2013",f_name );
|
||||
}
|
||||
|
||||
@Override
|
||||
JFreeChart createChartForMWE() {
|
||||
if (datasetMWE==null) return null;
|
||||
return HistogramGraph.createStaticChart(datasetMWE);
|
||||
}
|
||||
|
||||
@Override
|
||||
JFreeChart createChartForMWT() {
|
||||
if (datasetMWT==null) return null;
|
||||
return HistogramGraph.createStaticChart(datasetMWT);
|
||||
}
|
||||
|
||||
@Override
|
||||
JFreeChart createChartForTJY() {
|
||||
if (datasetTJY==null) return null;
|
||||
return HistogramGraph.createStaticChart(datasetTJY);
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderChartForMWE() {
|
||||
HistogramGraph tsg = new HistogramGraph("MWE");
|
||||
tsg.render(datasetMWE);
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderChartForMWT() {
|
||||
HistogramGraph tsg2 = new HistogramGraph("MWT");
|
||||
tsg2.render(datasetMWT);
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderChartForTJY() {
|
||||
HistogramGraph tsg3 = new HistogramGraph("TJY");
|
||||
tsg3.render(datasetTJY);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package org.gcube.dataanalysis.geothermal;
|
||||
|
||||
import org.gcube.contentmanagement.graphtools.plotting.graphs.TimeSeriesGraph;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.data.time.TimeSeries;
|
||||
import org.jfree.data.time.TimeSeriesCollection;
|
||||
import org.jfree.data.time.Year;
|
||||
|
||||
public class EnergyTrends extends AbstractProcess {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "An algorithm reporting the energy trends for the countries contributing to EGIP";
|
||||
}
|
||||
|
||||
TimeSeriesCollection datasetMWE = new TimeSeriesCollection();
|
||||
TimeSeriesCollection datasetMWT = new TimeSeriesCollection();
|
||||
TimeSeriesCollection datasetTJY = new TimeSeriesCollection();
|
||||
|
||||
@Override
|
||||
void initDatasets() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
void fulfillDataset(String f_name, String f_area, double f_f1990_mwe, double f_f1995_mwt, double f_f1995_h_tjy, double f_f1995_mwe, double f_f2000_mwt, double f_f2000_h_tjy, double f_f2000_mwe, double f_f2005_mwt, double f_f2005_h_tjy, double f_f2005_mwe, double f_f2010_mwt, double f_f2010_h_tjy, double f_f2010_mwe, double f_f2013_mwe, int startYear, int endYear) {
|
||||
|
||||
final TimeSeries seriesMWE = new TimeSeries(f_name);
|
||||
final TimeSeries seriesMWT = new TimeSeries(f_name);
|
||||
final TimeSeries seriesTJY = new TimeSeries(f_name);
|
||||
|
||||
if (startYear <= 1990 && endYear >= 1990)
|
||||
seriesMWE.add(new Year(1990), f_f1990_mwe);
|
||||
|
||||
if (startYear <= 1995 && endYear >= 1995) {
|
||||
seriesMWE.add(new Year(1995), f_f1995_mwe);
|
||||
seriesMWT.add(new Year(1995), f_f1995_mwt);
|
||||
seriesTJY.add(new Year(1995), f_f2000_h_tjy);
|
||||
}
|
||||
|
||||
if (startYear <= 2000 && endYear >= 2000) {
|
||||
seriesMWE.add(new Year(2000), f_f2000_mwe);
|
||||
seriesMWT.add(new Year(2000), f_f2000_mwt);
|
||||
seriesTJY.add(new Year(2000), f_f2000_h_tjy);
|
||||
}
|
||||
|
||||
if (startYear <= 2005 && endYear >= 2005) {
|
||||
seriesMWE.add(new Year(2005), f_f2005_mwe);
|
||||
seriesMWT.add(new Year(2005), f_f2005_mwt);
|
||||
seriesTJY.add(new Year(2005), f_f2005_h_tjy);
|
||||
}
|
||||
if (startYear <= 2010 && endYear >= 2010) {
|
||||
seriesMWE.add(new Year(2010), f_f2010_mwe);
|
||||
seriesMWT.add(new Year(2010), f_f2010_mwt);
|
||||
seriesTJY.add(new Year(2010), f_f2010_h_tjy);
|
||||
}
|
||||
if (startYear <= 2013 && endYear >= 2013) {
|
||||
seriesMWE.add(new Year(2013), f_f2013_mwe);
|
||||
}
|
||||
|
||||
datasetMWE.addSeries(seriesMWE);
|
||||
datasetMWT.addSeries(seriesMWT);
|
||||
datasetTJY.addSeries(seriesTJY);
|
||||
}
|
||||
|
||||
@Override
|
||||
JFreeChart createChartForMWE() {
|
||||
|
||||
return TimeSeriesGraph.createStaticChart(datasetMWE, "yyyy");
|
||||
}
|
||||
|
||||
@Override
|
||||
JFreeChart createChartForMWT() {
|
||||
return TimeSeriesGraph.createStaticChart(datasetMWT, "yyyy");
|
||||
}
|
||||
|
||||
@Override
|
||||
JFreeChart createChartForTJY() {
|
||||
return TimeSeriesGraph.createStaticChart(datasetTJY, "yyyy");
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderChartForMWE() {
|
||||
TimeSeriesGraph tsg = new TimeSeriesGraph("MWE");
|
||||
tsg.timeseriesformat = "yyyy";
|
||||
tsg.render(datasetMWE);
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderChartForMWT() {
|
||||
TimeSeriesGraph tsg2 = new TimeSeriesGraph("MWT");
|
||||
tsg2.timeseriesformat = "yyyy";
|
||||
tsg2.render(datasetMWT);
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderChartForTJY() {
|
||||
TimeSeriesGraph tsg3 = new TimeSeriesGraph("TJY");
|
||||
tsg3.timeseriesformat = "yyyy";
|
||||
tsg3.render(datasetTJY);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.dataanalysis.test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
|
||||
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.geothermal.AbstractProcess;
|
||||
|
||||
public class TestGeothermalProcessing {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AbstractProcess.display=true;
|
||||
System.out.println("TEST 1");
|
||||
List<ComputationalAgent> trans = null;
|
||||
trans = TransducerersFactory.getTransducerers(testConfig());
|
||||
trans.get(0).init();
|
||||
Regressor.process(trans.get(0));
|
||||
StatisticalType st = trans.get(0).getOutput();
|
||||
trans = null;
|
||||
}
|
||||
|
||||
private static AlgorithmConfiguration testConfig() {
|
||||
|
||||
AlgorithmConfiguration config = Regressor.getConfig();
|
||||
config.setConfigPath("./cfg/");
|
||||
config.setPersistencePath("./");
|
||||
|
||||
config.setAgent("TESTGEO4");
|
||||
config.setGcubeScope("/gcube/devsec/statVRE");
|
||||
|
||||
config.setParam("DatabaseUserName","gcube");
|
||||
config.setParam("DatabasePassword","d4science2");
|
||||
config.setParam("DatabaseURL","jdbc:postgresql://146.48.87.169/testdb");
|
||||
config.setParam("DatabaseDriver","org.postgresql.Driver");
|
||||
config.setParam("CountryName","ALL");
|
||||
config.setParam("StartYear","1000");
|
||||
config.setParam("EndYear","3000");
|
||||
config.setParam("Aggregation","SUM");
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue