Gianpaolo Coro 2015-11-02 10:22:07 +00:00
parent da4b6ad1ec
commit bfd581bd3f
16 changed files with 134 additions and 44 deletions

View File

@ -217,3 +217,4 @@ public class CSquaresCreator extends StandardLocalExternalAlgorithm {
} }
} }

View File

@ -129,3 +129,4 @@ public class RasterDataPublisher extends StandardLocalExternalAlgorithm{
} }
} }

View File

@ -19,12 +19,12 @@ public class TestFAOAreaCodesCreator {
// config.setParam("Longitude_Column", "centerlong"); // config.setParam("Longitude_Column", "centerlong");
// config.setParam("Latitude_Column", "centerlat"); // config.setParam("Latitude_Column", "centerlat");
config.setParam("Longitude_Column", "long"); config.setParam("Longitude_Column", "x_coord");
config.setParam("Latitude_Column", "lat"); config.setParam("Latitude_Column", "y_coord");
// config.setParam("InputTable", "interp_2024_linear_01355325354899"); // config.setParam("InputTable", "interp_2024_linear_01355325354899");
// config.setParam("InputTable", "interp_2036_linear_11384851795640"); // config.setParam("InputTable", "interp_2036_linear_11384851795640");
config.setParam("InputTable", "generic_id6ef3e4fa_6a06_4df1_9445_553f2e918102"); // config.setParam("InputTable", "generic_id6ef3e4fa_6a06_4df1_9445_553f2e918102");
config.setParam("InputTable", "generic_id25433bf4_c58c_4907_ac87_23919a3af0dc");
config.setParam("OutputTableName", "csqout"); config.setParam("OutputTableName", "csqout");
config.setParam("Resolution", "5"); config.setParam("Resolution", "5");

View File

@ -0,0 +1,58 @@
package org.gcube.dataanalysis.geo.test.infra;
import java.util.List;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
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.geo.connectors.table.TableMatrixRepresentation;
public class TestEstimateMonthlyFishingEffort {
static AlgorithmConfiguration[] configs = { testGridConversion()};
public static void main(String[] args) throws Exception {
System.out.println("TEST 1");
for (int i = 0; i < configs.length; i++) {
AnalysisLogger.getLogger().debug("Executing: "+configs[i].getAgent());
List<ComputationalAgent> trans = null;
trans = TransducerersFactory.getTransducerers(configs[i]);
trans.get(0).init();
Regressor.process(trans.get(0));
StatisticalType st = trans.get(0).getOutput();
AnalysisLogger.getLogger().debug("ST:" + st);
trans = null;
}
}
private static AlgorithmConfiguration testGridConversion() {
AlgorithmConfiguration config = new AlgorithmConfiguration();
config.setAgent("ESTIMATE_MONTHLY_FISHING_EFFORT");
config.setConfigPath("./cfg/");
config.setPersistencePath("./");
config.setParam("DatabaseUserName","utente");
config.setParam("DatabasePassword","d4science");
config.setParam("DatabaseURL","jdbc:postgresql://statistical-manager.d.d4science.org/testdb");
config.setParam("DatabaseDriver","org.postgresql.Driver");
config.setGcubeScope("/gcube/devsec/devVRE");
config.setParam("InputTable", "code_0b7c500bfaca49f2a0ab4fd3c1647074");
config.setParam("VesselsIDColumn", "vessel_id");
config.setParam("VesselsTimestampsColumn", "datetime");
config.setParam("VesselsLatitudesColumn", "y");
config.setParam("VesselsLongitudesColumn", "x");
config.setParam("VesselsActivityHoursColumn", "activity_hours");
config.setParam("VesselsActivityClassificationColumn", "activity_class_speed");
return config;
}
}

View File

@ -99,3 +99,4 @@ public class CSquareCodesConverter {
} }

View File

@ -87,11 +87,26 @@ public class FAOOceanAreaConverter {
} }
} }
String FaoOceanArea = quadrant+padLatitude(bestlat)+padLongitude(bestlon); String FaoOceanArea = getResolutionChar(resolution)+quadrant+padLatitude(bestlat)+padLongitude(bestlon);
if (FaoOceanArea.length()!=6) if (FaoOceanArea.length()!=7)
return null; return null;
return FaoOceanArea; return FaoOceanArea;
} }
public String getResolutionChar(int resolution){
if (resolution == 1)
return "5";
else if (resolution == 5)
return "6";
else if (resolution == 10)
return "7";
else if (resolution == 20)
return "8";
else if (resolution == 30)
return "9";
else
return "0";
}
} }

View File

@ -11,20 +11,20 @@ public class GridCWPConverter {
public float outlon; public float outlon;
public float outlat; public float outlat;
public int gridresolution; public float gridresolution;
public void gridCodeToPair (String grid){ public void gridCodeToPair (String grid){
char resolution = grid.charAt(0); char resolution = grid.charAt(0);
int quadrant = Integer.parseInt(""+grid.charAt(1)); int quadrant = Integer.parseInt(""+grid.charAt(1));
float lat = Float.parseFloat(grid.substring(2,4)); float lat = Float.parseFloat(grid.substring(2,4));
float lon = Float.parseFloat(grid.substring(4)); float lon = Float.parseFloat(grid.substring(4));
int Xr = getResolutionX(resolution); float Xr = getResolutionX(resolution);
// int Yr = getResolutionY(resolution); // int Yr = getResolutionY(resolution);
gridresolution = Xr; gridresolution = Xr;
float latAdj = adjustLat(lat, quadrant); float latAdj = adjustLat(lat, quadrant);
float lonAdj = adjustLon(lon, quadrant); float lonAdj = adjustLon(lon, quadrant);
int resolutionY = getResolutionY(resolution); float resolutionY = getResolutionY(resolution);
int resolutionX = getResolutionX(resolution); float resolutionX = getResolutionX(resolution);
float centerLat = getCenterLat(latAdj, resolutionY, quadrant); float centerLat = getCenterLat(latAdj, resolutionY, quadrant);
float centerLon = getCenterLon(lonAdj, resolutionX, quadrant); float centerLon = getCenterLon(lonAdj, resolutionX, quadrant);
@ -36,7 +36,7 @@ public class GridCWPConverter {
} }
public float getCenterLat(float lat, int resolutionY, int quadrant){ public float getCenterLat(float lat, float resolutionY, int quadrant){
float halfres = (float) resolutionY/2f; float halfres = (float) resolutionY/2f;
if (quadrant == 1 || quadrant == 4) if (quadrant == 1 || quadrant == 4)
@ -45,7 +45,7 @@ public class GridCWPConverter {
return lat-halfres; return lat-halfres;
} }
public float getCenterLon(float lon, int resolutionX, int quadrant){ public float getCenterLon(float lon, float resolutionX, int quadrant){
float halfres = (float) resolutionX/2f; float halfres = (float) resolutionX/2f;
if (quadrant == 1 || quadrant == 2) if (quadrant == 1 || quadrant == 2)
@ -68,38 +68,55 @@ public class GridCWPConverter {
return -1*lon; return -1*lon;
} }
public int getResolutionY(char token){ public float getResolutionY(char token){
if (token == '5') if (token == '5')
return 1; return 1;
else if (token == '6') else if (token == '6')
return 5; return 5;
else if (token == '1') else if (token == '7')
return 5;
else if (token == '2')
return 10; return 10;
else if (token == '3') else if (token == '8')
return 10;
else if (token == '4')
return 20; return 20;
else if (token == '9')
return 30;
else if (token == '0')
return 0;
else if (token == '4')
return 0.5f;
else if (token == '3')
return 0.5f;
else if (token == '2')
return 0.22f;
else if (token == '1')
return 0.17f;
else else
return -1; return -1;
} }
public int getResolutionX(char token){ public float getResolutionX(char token){
if (token == '5') if (token == '5')
return 1; return 1;
else if (token == '6') else if (token == '6')
return 5; return 5;
else if (token == '1') else if (token == '7')
return 10; return 10;
else if (token == '2') else if (token == '8')
return 20; return 20;
else if (token == '3') else if (token == '9')
return 10; return 30;
else if (token == '0')
return 0;
else if (token == '4') else if (token == '4')
return 20; return 1;
else if (token == '3')
return 0.5f;
else if (token == '2')
return 0.22f;
else if (token == '1')
return 0.17f;
else else
return -1; return -1;
} }
} }

View File

@ -269,3 +269,4 @@ public class VectorOperations {
*/ */
} }
} }

View File

@ -13,7 +13,6 @@ import org.gcube.dataanalysis.geo.utils.CSquareCodesConverter;
public class CSquare2Coordinates extends GridCWP2Coordinates{ public class CSquare2Coordinates extends GridCWP2Coordinates{
@Override @Override
protected void setInputParameters() { protected void setInputParameters() {

View File

@ -38,7 +38,7 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{
ColumnType Dimension1 = new ColumnType(inputTableParameter, VesselsIDColumn, "A column containing (anonymised) unique vessels identifiers", "vessel_id", false); ColumnType Dimension1 = new ColumnType(inputTableParameter, VesselsIDColumn, "A column containing (anonymised) unique vessels identifiers", "vessel_id", false);
ColumnType Dimension2 = new ColumnType(inputTableParameter, VesselsSpeedsColumn, "The column containing vessels speeds", "speed", false); ColumnType Dimension2 = new ColumnType(inputTableParameter, VesselsSpeedsColumn, "The column containing vessels speeds", "speed", false);
ColumnType Dimension3 = new ColumnType(inputTableParameter, VesselsTimestampsColumn, "The column containing the time stamp of the vessels transmitted information", "datetime", false); ColumnType Dimension3 = new ColumnType(inputTableParameter, VesselsTimestampsColumn, "The column containing the time stamp of the vessels transmitted information (preferred in the following format: MM/dd/yyyy HH:mm:ss a)", "datetime", false);
ColumnType Dimension4 = new ColumnType(inputTableParameter, VesselsLatitudesColumn, "The column containing vessels latitudes", "y", false); ColumnType Dimension4 = new ColumnType(inputTableParameter, VesselsLatitudesColumn, "The column containing vessels latitudes", "y", false);
ColumnType Dimension5 = new ColumnType(inputTableParameter, VesselsLongitudesColumn, "The column containing vessels longitudes", "x", false); ColumnType Dimension5 = new ColumnType(inputTableParameter, VesselsLongitudesColumn, "The column containing vessels longitudes", "x", false);
@ -70,7 +70,7 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{
long t0 = System.currentTimeMillis(); long t0 = System.currentTimeMillis();
String table = IOHelper.getInputParameter(config, inputTableParameter); String table = IOHelper.getInputParameter(config, inputTableParameter);
outTable = ("code_" + UUID.randomUUID()).replace("-", ""); outTable = ("fish_" + UUID.randomUUID()).replace("-", "");
outTableLabel = IOHelper.getInputParameter(config, outputTableParameter); outTableLabel = IOHelper.getInputParameter(config, outputTableParameter);
AnalysisLogger.getLogger().debug("EstimateFishingActivity: received parameters: " + config.getGeneralProperties()); AnalysisLogger.getLogger().debug("EstimateFishingActivity: received parameters: " + config.getGeneralProperties());
@ -87,14 +87,6 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{
} }
} }
public String selectInformationForTransformation (AlgorithmConfiguration config, String table, int limit, int offset){
String d = IOHelper.getInputParameter(config, CodeColumn);
String select = "select *," + d + " as loforcs01 from " + table + " limit " + limit + " offset " + offset;
return select;
}
public void addInformationColumsToTable(String table) throws Exception{ public void addInformationColumsToTable(String table) throws Exception{
AnalysisLogger.getLogger().debug("EstimateFishingActivity: initializing connection"); AnalysisLogger.getLogger().debug("EstimateFishingActivity: initializing connection");
long t0 = System.currentTimeMillis(); long t0 = System.currentTimeMillis();
@ -240,3 +232,4 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{
} }
} }

View File

@ -230,3 +230,4 @@ public class GridCWP2Coordinates extends StandardLocalExternalAlgorithm{
} }
} }

View File

@ -8,6 +8,7 @@ public class Bathymetry {
public static void init() throws Exception { public static void init() throws Exception {
bathymetryObj.open(); bathymetryObj.open();
} }
public static void close() throws Exception { public static void close() throws Exception {
bathymetryObj.close(); bathymetryObj.close();

View File

@ -7,8 +7,7 @@ import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
public class FishingHoursCalculator { public class FishingHoursCalculator {
public static double[] calculateFishingHours(String [] vesselIDsField,Date[] timeStamps){ public static double[] calculateFishingHours(String [] vesselIDsField,Date[] timeStamps){
int vNumber = vesselIDsField.length; int vNumber = vesselIDsField.length;
double [] hours = new double[vNumber]; double [] hours = new double[vNumber];

View File

@ -22,10 +22,11 @@ public class MonthlyFishingEffortCalculator {
return monthsDiff; return monthsDiff;
} }
// positional Object: x,y,date,hours // positional Object: x,y,date,hours
private double minEffort; private double minEffort;
private double maxEffort; private double maxEffort;
//x,y,date,hours,activity
public Map<String, Double> calculateMonthlyFishingEffort(List<Object> rows, Date minDate, Date maxDate) { public Map<String, Double> calculateMonthlyFishingEffort(List<Object> rows, Date minDate, Date maxDate) {
HashMap<String, Double> csquare2month = new HashMap<String, Double>(); HashMap<String, Double> csquare2month = new HashMap<String, Double>();
@ -36,13 +37,13 @@ public class MonthlyFishingEffortCalculator {
for (int i = 0; i < numOfPoints; i++) { for (int i = 0; i < numOfPoints; i++) {
Object[] singleRow = (Object[]) rows.get(i); Object[] singleRow = (Object[]) rows.get(i);
double x = Float.parseFloat(""+singleRow[0]); double x = (Double) singleRow[0];
double y = Float.parseFloat(""+singleRow[1]); double y = (Double) singleRow[1];
Date d = (Date) singleRow[2]; Date d = (Date) singleRow[2];
double hours = (Float) singleRow[3]; double hours = (Double) singleRow[3];
double speed = Double.parseDouble("" + singleRow[4]); String activity = ((String) singleRow[4]).toLowerCase();
if ((speed >= 2) && (speed <= 6)) { if (activity.equalsIgnoreCase("fishing")) {
String csquare = CSquareCodesConverter.convertHalfDegree(x, y); String csquare = CSquareCodesConverter.convertHalfDegree(x, y);
double[] csquaremontheffort = csquaremonths.get(csquare); double[] csquaremontheffort = csquaremonths.get(csquare);

View File

@ -37,6 +37,7 @@ public class VTIBathymetry {
* If only one pair of coordinates is specified, debug information about the calculation is written. * If only one pair of coordinates is specified, debug information about the calculation is written.
* @param args the command-line arguments * @param args the command-line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
int status = 0; int status = 0;
VTIBathymetry bm = new VTIBathymetry(); VTIBathymetry bm = new VTIBathymetry();

View File

@ -19,6 +19,7 @@ public class VTIClassificator {
return "Unclassified"; return "Unclassified";
} }
public static String bathymetryClassification(int classif){ public static String bathymetryClassification(int classif){
if (classif==1) if (classif==1)