use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class AnalysisViewModelTest method dumpQuery.
private void dumpQuery(ResourceId formId, String... columns) {
if (DUMP_RAW_DATA) {
try {
File tempFile = File.createTempFile("query", ".csv");
try (PrintWriter writer = new PrintWriter(tempFile)) {
QueryModel model = new QueryModel(formId);
for (int i = 0; i < columns.length; i++) {
model.selectExpr(columns[i]).as("c" + i);
}
ColumnSet columnSet = assertLoads(formStore.query(model));
for (int i = 0; i < columns.length; i++) {
if (i > 0) {
writer.print(",");
}
writer.print(columns[i]);
}
writer.println();
for (int i = 0; i < columnSet.getNumRows(); i++) {
for (int j = 0; j < columns.length; j++) {
if (j > 0) {
writer.print(",");
}
ColumnView columnView = columnSet.getColumnView("c" + j);
Object cell = columnView.get(i);
String cells = "";
if (cell != null) {
cells = cell.toString();
}
writer.print(cells);
}
writer.println();
}
}
System.out.println("Dumped data to " + tempFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class OfflineStoreGwtTest method verifyWeCanQueryRecords.
private Promise<Void> verifyWeCanQueryRecords(Void input) {
QueryModel queryModel = new QueryModel(survey.getFormId());
queryModel.selectResourceId().as("id");
queryModel.selectField(survey.getNameFieldId()).as("name");
queryModel.selectField(survey.getAgeFieldId()).as("age");
return formStore.query(queryModel).once().then(columnSet -> {
assertEquals(survey.getRowCount(), columnSet.getNumRows());
ColumnView name = columnSet.getColumnView("name");
ColumnView age = columnSet.getColumnView("age");
assertEquals(survey.getRowCount(), columnSet.getNumRows());
assertEquals("Melanie", name.get(0));
assertEquals("Joe", name.get(1));
assertEquals("Matilda", name.get(2));
return null;
});
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class Presenter method choices.
private Supplier<Promise<List<Choice>>> choices(final Level level) {
final QueryModel queryModel = new QueryModel(level.getFormId());
queryModel.selectResourceId().as("id");
queryModel.selectExpr("label").as("label");
if (!level.isRoot()) {
Choice selectedParent = getSelection(level.getParent());
queryModel.selectExpr("parent").as("parent");
queryModel.setFilter(Formulas.equals(new SymbolNode("parent"), Formulas.idConstant(selectedParent.getRef().getRecordId())));
}
return new Supplier<Promise<List<Choice>>>() {
@Override
public Promise<List<Choice>> get() {
return locator.queryTable(queryModel).then(new Function<ColumnSet, List<Choice>>() {
@Nullable
@Override
public List<Choice> apply(ColumnSet input) {
ColumnView id = input.getColumnView("id");
ColumnView label = input.getColumnView("label");
ColumnView parent = input.getColumnView("parent");
List<Choice> choices = new ArrayList<>();
for (int i = 0; i < input.getNumRows(); i++) {
if (parent == null) {
choices.add(new Choice(level.getFormId(), ResourceId.valueOf(id.getString(i)), label.getString(i)));
} else {
choices.add(new Choice(level.getFormId(), ResourceId.valueOf(id.getString(i)), label.getString(i), new RecordRef(level.getParent().getFormId(), ResourceId.valueOf(parent.getString(i)))));
}
}
return choices;
}
});
}
};
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class FieldScoreMatrix method scoreTextColumnMatch.
private double scoreTextColumnMatch(FieldProfile sourceProfile, FieldProfile targetProfile) {
ColumnView source = sourceProfile.getView();
ColumnView target = targetProfile.getView();
if (source.numRows() <= target.numRows()) {
return scoreTextColumnMatch(source, target);
} else {
return scoreTextColumnMatch(target, source);
}
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class BinaryBooleanOperator method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
checkArity(arguments, 2);
ColumnView a = arguments.get(0);
ColumnView b = arguments.get(1);
if (a.numRows() != b.numRows()) {
throw new FormulaSyntaxException("Arguments must have the same number of rows");
}
int[] result = new int[a.numRows()];
for (int i = 0; i < result.length; i++) {
int ai = a.getBoolean(i);
int bi = b.getBoolean(i);
result[i] = apply(ai, bi);
}
return new BooleanColumnView(result);
}
Aggregations