Add number, date and boolean counts to List facet

This commit is contained in:
Owen Stephens 2018-06-28 06:21:27 +01:00
parent 55e3914c8d
commit 2a034b65e9
4 changed files with 70 additions and 7 deletions

View File

@ -74,6 +74,9 @@ public class ListFacet implements Facet {
public boolean omitError;
public List<DecoratedValue> selection = new LinkedList<>();
public boolean selectNumber;
public boolean selectDateTime;
public boolean selectBoolean;
public boolean selectBlank;
public boolean selectError;
@ -94,6 +97,9 @@ public class ListFacet implements Facet {
writer.endObject();
}
writer.endArray();
writer.key("selectNumber"); writer.value(selectNumber);
writer.key("selectDateTime"); writer.value(selectDateTime);
writer.key("selectBoolean"); writer.value(selectBoolean);
writer.key("omitBlank"); writer.value(omitBlank);
writer.key("selectBlank"); writer.value(selectBlank);
writer.key("omitError"); writer.value(omitError);
@ -124,6 +130,9 @@ public class ListFacet implements Facet {
omitBlank = JSONUtilities.getBoolean(o, "omitBlank", false);
omitError = JSONUtilities.getBoolean(o, "omitError", false);
selectNumber = JSONUtilities.getBoolean(o, "selectNumber", false);
selectDateTime = JSONUtilities.getBoolean(o, "selectDateTime", false);
selectBoolean = JSONUtilities.getBoolean(o, "selectBoolean", false);
selectBlank = JSONUtilities.getBoolean(o, "selectBlank", false);
selectError = JSONUtilities.getBoolean(o, "selectError", false);
}
@ -149,6 +158,9 @@ public class ListFacet implements Facet {
* Computed results
*/
protected List<NominalFacetChoice> _choices = new LinkedList<NominalFacetChoice>();
protected int _numberCount;
protected int _datetimeCount;
protected int _booleanCount;
protected int _blankCount;
protected int _errorCount;
@ -176,7 +188,27 @@ public class ListFacet implements Facet {
choice.write(writer, options);
}
writer.endArray();
if (_config.selectNumber || _numberCount > 0) {
writer.key("numberChoice");
writer.object();
writer.key("s"); writer.value(_config.selectNumber);
writer.key("c"); writer.value(_numberCount);
writer.endObject();
}
if (_config.selectDateTime || _datetimeCount > 0) {
writer.key("datetimeChoice");
writer.object();
writer.key("s"); writer.value(_config.selectDateTime);
writer.key("c"); writer.value(_datetimeCount);
writer.endObject();
}
if (_config.selectBoolean || _booleanCount > 0) {
writer.key("booleanChoice");
writer.object();
writer.key("s"); writer.value(_configselectBoolean);
writer.key("c"); writer.value(_booleanCount);
writer.endObject();
}
if (!_config.omitBlank && (_config.selectBlank || _blankCount > 0)) {
writer.key("blankChoice");
writer.object();
@ -245,6 +277,9 @@ public class ListFacet implements Facet {
_config.columnName,
_cellIndex,
createMatches(),
_config.selectNumber,
_config.selectDateTime,
_config.selectBoolean,
_config.selectBlank,
_config.selectError,
_config.invert);
@ -310,6 +345,9 @@ public class ListFacet implements Facet {
}
}
_numberCount = grouper.numberCount;
_datetimeCount = grouper.datetimeCount;
_booleanCount = grouper.booleanCount;
_blankCount = grouper.blankCount;
_errorCount = grouper.errorCount;
}
@ -321,4 +359,4 @@ public class ListFacet implements Facet {
}
return a;
}
}
}

View File

@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.browsing.filters;
import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.Properties;
@ -58,8 +60,10 @@ public class ExpressionEqualRowFilter implements RowFilter {
final protected int _cellIndex; // the expression is based on this column;
// -1 if based on no column in particular,
// for expression such as "row.starred".
final protected Object[] _matches;
final protected boolean _selectNumber;
final protected boolean _selectDateTime;
final protected boolean _selectBoolean;
final protected boolean _selectBlank;
final protected boolean _selectError;
final protected boolean _invert;
@ -69,6 +73,9 @@ public class ExpressionEqualRowFilter implements RowFilter {
String columnName,
int cellIndex,
Object[] matches,
boolean selectNumber,
boolean selectDateTime,
boolean selectBoolean,
boolean selectBlank,
boolean selectError,
boolean invert
@ -77,6 +84,9 @@ public class ExpressionEqualRowFilter implements RowFilter {
_columnName = columnName;
_cellIndex = cellIndex;
_matches = matches;
_selectNumber = selectNumber;
_selectDateTime = selectDateTime;
_selectBoolean = selectBoolean;
_selectBlank = selectBlank;
_selectError = selectError;
_invert = invert;
@ -178,6 +188,12 @@ public class ExpressionEqualRowFilter implements RowFilter {
protected boolean testValue(Object v) {
if (ExpressionUtils.isError(v)) {
return _selectError;
} else if (v instanceof Number) {
return _selectNumber;
} else if (v instanceof OffsetDateTime) {
return _selectDateTime;
} else if (v instanceof Boolean) {
return _selectBoolean;
} else if (ExpressionUtils.isNonBlankData(v)) {
for (Object match : _matches) {
if (testValue(v, match)) {

View File

@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.browsing.util;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

View File

@ -103,11 +103,19 @@ public class ExpressionUtils {
static public boolean isError(Object o) {
return o instanceof EvalError;
}
/*
static public boolean isBlank(Object o) {
return o == null || (o instanceof String && ((String) o).length() == 0);
static public boolean isNumber(Object v) {
return v != null && (v instanceof Number);
}
*/
static public boolean isBoolean(Object v) {
return v != null && v instanceof Boolean;
}
static public boolean isDateTime(Object v) {
return v != null && v instanceof OffsetDateTime;
}
static public boolean isNonBlankData(Object o) {
return
o != null &&