use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class RealValuedFunction method binaryFunctionColumnCall.
private ColumnView binaryFunctionColumnCall(int numRows, List<ColumnView> arguments) {
ColumnView x = arguments.get(0);
ColumnView y = arguments.get(1);
double[] result = new double[x.numRows()];
for (int i = 0; i < result.length; i++) {
double xd = x.getDouble(i);
double yd = y.getDouble(i);
if (Double.isNaN(xd) && Double.isNaN(yd)) {
result[i] = Double.NaN;
} else {
if (Double.isNaN(xd)) {
xd = 0;
}
if (Double.isNaN(yd)) {
yd = 0;
}
result[i] = apply(xd, yd);
}
}
return new DoubleArrayColumnView(result);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class SearchFunction method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
ColumnView substring = arguments.get(0);
ColumnView string = arguments.get(1);
ColumnView startIndex;
if (arguments.size() == 3) {
startIndex = arguments.get(3);
} else {
startIndex = new ConstantColumnView(numRows, 1d);
}
double[] result = new double[numRows];
for (int i = 0; i < numRows; i++) {
result[i] = apply(substring.getString(i), string.getString(i), startIndex.getDouble(i));
}
return new DoubleArrayColumnView(result);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class ImportWithMultiClassRangeTest method school.
private Set<ResourceId> school(String name) {
// Find id of the school with this name
ResourceId id = null;
ColumnView nameColumn = resultSet.getColumnView("name");
ColumnView idColumn = resultSet.getColumnView("id");
for (int i = 0; i < resultSet.getNumRows(); i++) {
if (name.equals(nameColumn.getString(i))) {
id = ResourceId.valueOf(idColumn.getString(i));
break;
}
}
if (id == null) {
throw new AssertionError("No school named '" + name + "'");
}
Promise<FormInstance> record = locator.getFormInstance(SCHOOL_FORM_CLASS, id);
ReferenceValue value = (ReferenceValue) record.get().get(CuidAdapter.field(SCHOOL_FORM_CLASS, CuidAdapter.ADMIN_FIELD));
Set<ResourceId> recordIds = new HashSet<>();
for (RecordRef recordRef : value.getReferences()) {
recordIds.add(recordRef.getRecordId());
}
return recordIds;
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class ApiTestHarness method createDatabase.
public TestDatabase createDatabase() {
String name = aliasTable.createAlias("db");
ActivityInfoClient client = client();
ResourceId databaseId = client.createDatabase(name);
int id = CuidAdapter.getLegacyIdFromCuid(databaseId);
// Query list of partners
QueryModel queryModel = new QueryModel(CuidAdapter.partnerFormId(id));
queryModel.selectResourceId().as("id");
ColumnSet columnSet = client.queryTable(queryModel);
ColumnView partnerIdView = columnSet.getColumnView("id");
ResourceId firstPartnerId = ResourceId.valueOf(partnerIdView.getString(0));
return new TestDatabase(databaseId, name, firstPartnerId);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class DateFunctionQueryTest method testToday.
@Test
public void testToday() {
TestingStorageProvider catalog = new TestingStorageProvider();
IntakeForm intakeForm = catalog.getIntakeForm();
ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
QueryModel queryModel = new QueryModel(intakeForm.getFormId());
queryModel.selectExpr("TODAY()").as("today");
queryModel.selectExpr("YEARFRAC(TODAY(), DOB)").as("age");
queryModel.selectExpr("DOB").as("dob");
ColumnSet columnSet = builder.build(queryModel);
ColumnView today = columnSet.getColumnView("today");
ColumnView age = columnSet.getColumnView("age");
ColumnView dob = columnSet.getColumnView("dob");
for (int i = 0; i < columnSet.getNumRows(); i++) {
if (dob.getString(i) != null) {
double ageInYears = age.getDouble(i);
System.out.println(dob.get(i) + " " + ageInYears);
if (Double.isNaN(ageInYears)) {
throw new AssertionError();
}
}
}
System.out.println(age);
}
Aggregations