Search in sources :

Example 1 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class RecordDaoTest method createRecord.

private CollectRecord createRecord(CollectSurvey survey, int sequenceNumber) {
    int skippedCount = new Double(Math.ceil((double) (Math.random() * 40))).intValue();
    int missingCount = new Double(Math.ceil((double) (Math.random() * 50))).intValue();
    int errorsCount = new Double(Math.ceil((double) (Math.random() * 10))).intValue();
    int warningsCount = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
    int numberOfPlots = new Double(Math.ceil((double) (Math.random() * 20))).intValue();
    int numberOfTrees = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
    ;
    CollectRecord record = new CollectRecord(recordManager, survey, "2.0");
    record.setCreationDate(new GregorianCalendar(2011, 0, sequenceNumber, 8, 30).getTime());
    // record.setCreatedBy("ModelDaoIntegrationTest");
    record.setStep(Step.ENTRY);
    record.setModifiedDate(new GregorianCalendar(2011, 1, sequenceNumber, 8, 30).getTime());
    record.setSkipped(skippedCount);
    record.setMissing(missingCount);
    record.setErrors(errorsCount);
    record.setWarnings(warningsCount);
    Entity cluster = record.createRootEntity("cluster");
    String keyId = Integer.toString(sequenceNumber);
    EntityBuilder.addValue(cluster, "id", new Code(keyId));
    EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
    EntityBuilder.addValue(cluster, "region", new Code("001"));
    EntityBuilder.addValue(cluster, "district", new Code("002"));
    EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(432423423l, 4324324l, "srs"));
    EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
    {
        Entity ts = EntityBuilder.addEntity(cluster, "time_study");
        ts.addValue("date", new Date(2011, 2, 14));
        ts.addValue("start_time", new Time(8, 15));
        ts.addValue("end_time", new Time(15, 29));
    }
    {
        Entity ts = EntityBuilder.addEntity(cluster, "time_study");
        ts.addValue("date", new Date(2011, 2, 15));
        ts.addValue("start_time", new Time(8, 32));
        ts.addValue("end_time", new Time(11, 20));
    }
    for (int i = 0; i < numberOfPlots; i++) {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code(Integer.toString(i + 1)));
        for (int j = 0; j < numberOfTrees; j++) {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            tree.addValue("dbh", 54.2);
            tree.addValue("total_height", 2.0);
            RealAttribute boleHeight = tree.addValue("bole_height", (Double) null);
            boleHeight.getField().setSymbol('*');
            boleHeight.getField().setRemarks("No value specified");
        // .setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
        }
    }
    // set counts
    record.getEntityCounts().add(numberOfPlots);
    // set keys
    record.getRootEntityKeys().add(keyId);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RealAttribute(org.openforis.idm.model.RealAttribute) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Example 2 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class ModelPathExpressionTest method testAttributeParent.

@Test
public void testAttributeParent() throws InvalidExpressionException {
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    RealAttribute canopyCover = EntityBuilder.addValue(plot, "canopy_cover", 12.56);
    List<Node<?>> plots = iterateExpression("parent()", canopyCover);
    Assert.assertEquals(1, plots.size());
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 3 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class RelevanceExpressionTest method testRelevanceOnNegativeNodeExpression.

@Test
public void testRelevanceOnNegativeNodeExpression() throws InvalidExpressionException {
    EntityBuilder.addValue(cluster, "plot_direction", 345.45);
    RealAttribute plotDistance = EntityBuilder.addValue(cluster, "plot_distance", 12.2);
    String expr = "not(parent()/plot_direction)";
    assertFalse(evaluateExpression(expr, plotDistance));
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 4 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class PathTest method testSingleAttributeWithIndex.

@Test
public void testSingleAttributeWithIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree1 = EntityBuilder.addEntity(plot, "tree");
    EntityBuilder.addValue(tree1, "dbh", 12.2);
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh[1]");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals(dbh2, res.get(0));
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh2.getDefinition(), def);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 5 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class PathTest method testMultipleFieldPathWithIndex.

@Test
public void testMultipleFieldPathWithIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    EntityBuilder.addEntity(plot, "tree");
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    EntityBuilder.addValue(tree2, "dbh", 12.2);
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh[2]/value");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals(15.7, ((Field<?>) res.get(0)).getValue());
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh2.getDefinition().getFieldDefinition("value"), def);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Aggregations

RealAttribute (org.openforis.idm.model.RealAttribute)39 Test (org.junit.Test)33 Entity (org.openforis.idm.model.Entity)25 AbstractTest (org.openforis.idm.AbstractTest)14 CollectRecord (org.openforis.collect.model.CollectRecord)9 Code (org.openforis.idm.model.Code)9 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 Node (org.openforis.idm.model.Node)6 RealValue (org.openforis.idm.model.RealValue)6 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Coordinate (org.openforis.idm.model.Coordinate)4 Date (org.openforis.idm.model.Date)4 Time (org.openforis.idm.model.Time)4 Unit (org.openforis.idm.metamodel.Unit)2 IntegerAttribute (org.openforis.idm.model.IntegerAttribute)2 TextAttribute (org.openforis.idm.model.TextAttribute)2 GregorianCalendar (java.util.GregorianCalendar)1 Ignore (org.junit.Ignore)1