enhancement of the comparison query

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@76683 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Gianpaolo Coro 2013-06-03 11:11:28 +00:00
parent 2fcab8df54
commit d928073a6c
1 changed files with 18 additions and 5 deletions

View File

@ -22,11 +22,11 @@ public class DiscrepancyAnalysis extends DataAnalysis {
// static String discrepancyQuery = "select distinct a.%1$s as csquareone,b.%2$s as csquaretwo,a.%3$s as firstprob,b.%4$s as secondprob from %5$s as a inner join %6$s as b on a.%1$s=b.%2$s and (a.%3$s<>b.%4$s)";
// static String discrepancyQuery = "select distinct a.%1$s as csquareone,b.%2$s as csquaretwo,a.%3$s as firstprob,b.%4$s as secondprob from (select * from %5$s order by %1$s limit %7$s) as a inner join (select * from %6$s order by %2$s limit %7$s) as b on a.%1$s=b.%2$s and (a.%3$s<>b.%4$s)";
static String discrepancyQuery = "select distinct a.%1$s as csquareone,b.%2$s as csquaretwo,a.%3$s as firstprob,b.%4$s as secondprob from " +
"(select csquarecode,sum(%3$s) as %3$s from (select distinct * from %5$s order by %1$s limit %7$s) as aa group by %1$s) as a " +
static String discrepancyQuery = "select * from (select distinct a.%1$s as csquareone,b.%2$s as csquaretwo,a.%3$s as firstprob,b.%4$s as secondprob from " +
"(select %1$s , sum(%3$s) as %3$s from (select distinct * from %5$s order by %1$s limit %7$s) as aa group by %1$s) as a " +
"left join " +
"(select csquarecode,sum(%4$s) as %4$s from (select distinct * from %6$s order by %2$s limit %7$s) as aa group by %2$s) as b " +
"on a.%1$s=b.%2$s and (a.%3$s<>b.%4$s)";
"(select %2$s , sum(%4$s) as %4$s from (select distinct * from %6$s order by %2$s limit %7$s) as aa group by %2$s) as b " +
"on a.%1$s=b.%2$s) as sel where firstprob<>secondprob";
static String getNumberOfElementsQuery = "select count(*) from %1$s";
private static int minElements = 100;
@ -119,7 +119,7 @@ public class DiscrepancyAnalysis extends DataAnalysis {
AnalysisLogger.getLogger().trace("Number Of Elements to take: "+nelements);
String query = String.format(discrepancyQuery, FirstTableCsquareColumn, SecondTableCsquareColumn, FirstTableProbabilityColumn, SecondTableProbabilityColumn, FirstTable, SecondTable,""+nelements);
AnalysisLogger.getLogger().trace("Discrepancy Calculation - Query to perform :" + query);
AnalysisLogger.getLogger().debug("Discrepancy Calculation - Query to perform :" + query);
List<Object> takePoints = DatabaseFactory.executeSQLQuery(query, connection);
super.processedRecords = 0;
@ -144,6 +144,12 @@ public class DiscrepancyAnalysis extends DataAnalysis {
output.put("ACCURACY", "" + MathFunctions.roundDecimal(accuracy,2));
output.put("MAXIMUM_ERROR", "" + MathFunctions.roundDecimal(maxerror,2));
output.put("MAXIMUM_ERROR_POINT", "" + maxdiscrepancyPoint);
if (numLower>numHigher)
output.put("TREND", "CONTRACTION");
if (numLower<numHigher)
output.put("TREND", "EXPANSION");
else
output.put("TREND", "STATIONARY");
return output;
}
@ -166,6 +172,9 @@ public class DiscrepancyAnalysis extends DataAnalysis {
}
}
long numHigher = 0;
long numLower = 0;
public void analyzeCompareList(List<Object> points) {
errors = new ArrayList<Float>();
@ -189,6 +198,10 @@ public class DiscrepancyAnalysis extends DataAnalysis {
maxerror = discrepancy;
maxdiscrepancyPoint = csquare;
}
if (probabilityPoint2>probabilityPoint1)
numHigher++;
if (probabilityPoint2<probabilityPoint1)
numLower++;
}
}
}