Fix imprecise facet statistics in records mode (#2607)
* Fix bug in choice counts for records mode * Add test for value grouper on records * Refactor and comment code * Count distinct instances of null/blank data * Update test to check for blank data count in records * Remove unnecessary import statement
This commit is contained in:
parent
947356ddad
commit
d57d76f7df
@ -123,15 +123,14 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
hasError = false;
|
||||
hasBlank = false;
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
hasError = false;
|
||||
hasBlank = false;
|
||||
|
||||
Row row = project.rows.get(r);
|
||||
visitRow(project, r, row, bindings, record.recordIndex);
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
errorCount++;
|
||||
@ -139,6 +138,7 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor
|
||||
if (hasBlank) {
|
||||
blankCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ import com.google.refine.model.ModelException;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.model.Row;
|
||||
|
||||
|
||||
public class ExpressionNominalValueGrouperTests extends RefineTest {
|
||||
// dependencies
|
||||
//Variables
|
||||
@ -174,4 +173,35 @@ public class ExpressionNominalValueGrouperTests extends RefineTest {
|
||||
Assert.assertEquals(grouper.choices.get(dateTimeStringValue).decoratedValue.label,dateTimeStringValue);
|
||||
Assert.assertEquals(grouper.choices.get(dateTimeStringValue).decoratedValue.value.toString(),dateTimeStringValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionNominalValueGrouperRecords() throws Exception {
|
||||
String completeProjectJson = "col1,col2,col3\n"
|
||||
+ "record1,1,a\n"
|
||||
+ ",,a\n"
|
||||
+ ",,a\n"
|
||||
+ "record2,,a\n"
|
||||
+ ",1,a\n";
|
||||
|
||||
project = createCSVProject(completeProjectJson);
|
||||
bindings = new Properties();
|
||||
bindings.put("project", project);
|
||||
|
||||
eval = MetaParser.parse("value");
|
||||
grouper = new ExpressionNominalValueGrouper(eval, "col2", 1);
|
||||
try {
|
||||
grouper.start(project);
|
||||
int c = project.recordModel.getRecordCount();
|
||||
for (int r = 0; r < c; r++) {
|
||||
grouper.visit(project, project.recordModel.getRecord(r));
|
||||
}
|
||||
} finally {
|
||||
grouper.end(project);
|
||||
}
|
||||
|
||||
Assert.assertEquals(grouper.blankCount, 3);
|
||||
Assert.assertEquals(grouper.choices.size(), 1);
|
||||
Assert.assertTrue(grouper.choices.containsKey(integerStringValue));
|
||||
Assert.assertEquals(grouper.choices.get(integerStringValue).count, 2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user