Skip to content
Snippets Groups Projects
Commit fe703c66 authored by Ludovic Claude's avatar Ludovic Claude
Browse files

Fix data sampling

parent d4886d81
Branches master
No related tags found
No related merge requests found
...@@ -33,16 +33,29 @@ public class DataUtil { ...@@ -33,16 +33,29 @@ public class DataUtil {
for (String var : vars) { for (String var : vars) {
JsonArray currentVarData = new JsonArray(); JsonArray currentVarData = new JsonArray();
int nbRows = (int) countDatasetRows(); long nbRows = countDatasetRows();
if (nbRows < 1) { return data; }
int nb_samples = Math.min(nbRows, MAX_NB_SAMPLES); if (nbRows >= 1) {
int samplingPercentage = 100 * nb_samples / nbRows;
long nb_samples = Math.min(nbRows, MAX_NB_SAMPLES);
int samplingPercentage = (int) (100 * nb_samples / nbRows);
List<Object> queryResult = jdbcTemplate.queryForList( List<Object> queryResult = jdbcTemplate.queryForList(
"SELECT " + var + " FROM "+featuresMainTable+" " + String.format("SELECT %s FROM %s TABLESAMPLE SYSTEM (%d) REPEATABLE (%d)",
"TABLESAMPLE SYSTEM ("+ samplingPercentage +") REPEATABLE ( "+ TABLESAMPLE_SEED +" )", Object.class); var, featuresMainTable, samplingPercentage, TABLESAMPLE_SEED),
for (Object value : queryResult) Object.class);
{ for (Object value : queryResult) {
if (value == null) {
currentVarData.add((String) null);
} else {
if (value instanceof Double) {
currentVarData.add((Double) value);
} else if (value instanceof Float) {
currentVarData.add((Float) value);
} else if (value instanceof Integer) {
currentVarData.add((Integer) value);
} else if (value instanceof Long) {
currentVarData.add((Long) value);
} else {
String strValue = String.valueOf(value); String strValue = String.valueOf(value);
try { try {
double numValue = Double.parseDouble(strValue); double numValue = Double.parseDouble(strValue);
...@@ -51,8 +64,11 @@ public class DataUtil { ...@@ -51,8 +64,11 @@ public class DataUtil {
currentVarData.add(strValue); currentVarData.add(strValue);
} }
} }
}
}
data.add(var, currentVarData); data.add(var, currentVarData);
} }
}
return data; return data;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment