Search in sources :

Example 1 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class RunnableCheck method run.

/**
 * Runs the {@link Check} over {@link AtlasObject}s, posting resulting {@link CheckFlag}s to
 * {@link RunnableCheckBase#eventService} and {@link MapRouletteClient}
 */
@Override
public void run() {
    try {
        final Time timer = Time.now();
        this.getObjects().forEach(object -> {
            final Optional<CheckFlag> flag = this.getCheck().check(object);
            if (flag.isPresent()) {
                this.addTask(flag.get());
                this.getEventService().post(new CheckFlagEvent(this.getName(), flag.get()));
            }
        });
        this.getCheck().clear();
        final Duration checkRunTime = timer.elapsedSince();
        logger.info("{} completed in {}.", this.getName(), checkRunTime);
        this.getEventService().post(new MetricEvent(this.getName(), checkRunTime));
        this.uploadTasks();
    } catch (final Exception e) {
        logger.error(String.format("%s failed to complete.", this.getName()), e);
    }
}
Also used : MetricEvent(org.openstreetmap.atlas.checks.event.MetricEvent) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Time(org.openstreetmap.atlas.utilities.time.Time) Duration(org.openstreetmap.atlas.utilities.scalars.Duration) CheckFlagEvent(org.openstreetmap.atlas.checks.event.CheckFlagEvent)

Example 2 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class PierTest method testPierOverrideSkip.

/**
 * Test the pier override value that will allow piers to be processed.
 */
@Test
public void testPierOverrideSkip() {
    final String configSource = "{\"PierTestCheck.accept.piers\": true}";
    final PierTestCheck check = new PierTestCheck(ConfigurationResolver.inlineConfiguration(configSource));
    final Set<CheckFlag> flags = Iterables.stream(check.flags(setup.getAtlas())).collectToSet();
    Assert.assertEquals(3, flags.size());
}
Also used : PierTestCheck(org.openstreetmap.atlas.checks.base.checks.PierTestCheck) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Test(org.junit.Test)

Example 3 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class PierTest method testPierSkip.

/**
 * Test default behavior to make sure the pier override value when explicitly set to false
 * maintains the behavior of not allowing piers to be processed
 */
@Test
public void testPierSkip() {
    final String configSource = "{\"PierTestCheck.accept.piers\": false}";
    final PierTestCheck check = new PierTestCheck(ConfigurationResolver.inlineConfiguration(configSource));
    final Set<CheckFlag> flags = Iterables.stream(check.flags(setup.getAtlas())).collectToSet();
    Assert.assertEquals(2, flags.size());
    flags.forEach(flag -> Assert.assertNotEquals(100, flag.getIdentifier()));
}
Also used : PierTestCheck(org.openstreetmap.atlas.checks.base.checks.PierTestCheck) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Test(org.junit.Test)

Example 4 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class SinkIslandCheck method flag.

@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
    // Flag to keep track of whether we found an issue or not
    boolean emptyFlag = false;
    // The current edge to be explored
    Edge candidate = (Edge) object;
    // A set of all edges that we have already explored
    final Set<AtlasObject> explored = new HashSet<>(this.storeSize, LOAD_FACTOR);
    // A set of all edges that we explore that have no outgoing edges
    final Set<AtlasObject> terminal = new HashSet<>();
    // Current queue of candidates that we can draw from
    final Queue<Edge> candidates = new ArrayDeque<>(this.storeSize);
    // Start edge always explored
    explored.add(candidate);
    // Keep looping while we still have a valid candidate to explore
    while (candidate != null) {
        // process
        if (this.isFlagged(candidate.getIdentifier())) {
            emptyFlag = true;
            break;
        }
        // Retrieve all the valid outgoing edges to explore
        final Set<Edge> outEdges = candidate.outEdges().stream().filter(this::validEdge).collect(Collectors.toSet());
        if (outEdges.isEmpty()) {
            // Sink edge. Don't mark the edge explored until we know how big the tree is
            terminal.add(candidate);
        } else {
            // Add the current candidate to the set of already explored edges
            explored.add(candidate);
            // From the list of outgoing edges from the current candidate filter out any edges
            // that have already been explored and add all the rest to the queue of possible
            // candidates
            outEdges.stream().filter(outEdge -> !explored.contains(outEdge)).forEach(candidates::add);
            // loop and assume that this is not a SinkIsland
            if (candidates.size() + explored.size() > this.treeSize) {
                emptyFlag = true;
                break;
            }
        }
        // Get the next candidate
        candidate = candidates.poll();
    }
    // flag.
    if (!emptyFlag) {
        // Include all touched edges
        explored.addAll(terminal);
    }
    // Set every explored edge as flagged for any other processes to know that we have already
    // process all those edges
    explored.forEach(marked -> this.markAsFlagged(marked.getIdentifier()));
    // Create the flag if and only if the empty flag value is not set to false
    return emptyFlag ? Optional.empty() : Optional.of(createFlag(explored, this.getLocalizedInstruction(0)));
}
Also used : Arrays(java.util.Arrays) Set(java.util.Set) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) RouteTag(org.openstreetmap.atlas.tags.RouteTag) Collectors(java.util.stream.Collectors) Validators(org.openstreetmap.atlas.tags.annotations.validation.Validators) HashSet(java.util.HashSet) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) List(java.util.List) BaseCheck(org.openstreetmap.atlas.checks.base.BaseCheck) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) TagPredicates(org.openstreetmap.atlas.checks.atlas.predicates.TagPredicates) SyntheticBoundaryNodeTag(org.openstreetmap.atlas.tags.SyntheticBoundaryNodeTag) Optional(java.util.Optional) AerowayTag(org.openstreetmap.atlas.tags.AerowayTag) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 5 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class DuplicateNodeCheckTest method testCheck.

@Test
public void testCheck() {
    final Rectangle bounds = Rectangle.TEST_RECTANGLE;
    final Set<Location> nodes = new HashSet<>();
    while (nodes.size() < 10) {
        nodes.add(Location.random(bounds));
    }
    final PackedAtlasBuilder builder = new PackedAtlasBuilder();
    int identifier = 0;
    for (final Location node : nodes) {
        // for first node make it a duplicate
        if (identifier == 0) {
            builder.addNode(identifier++, node, RandomTagsSupplier.randomTags(5));
        }
        builder.addNode(identifier++, node, RandomTagsSupplier.randomTags(5));
    }
    final Iterator<Location> locationIterator = nodes.iterator();
    final Location start = locationIterator.next();
    identifier = 0;
    while (locationIterator.hasNext()) {
        if (identifier == 0) {
            builder.addEdge(identifier++, new Segment(start, locationIterator.next()), RandomTagsSupplier.randomTags(5));
        }
        builder.addEdge(identifier++, new Segment(start, locationIterator.next()), RandomTagsSupplier.randomTags(5));
    }
    final Atlas atlas = builder.get();
    final Iterable<CheckFlag> flags = new DuplicateNodeCheck(ConfigurationResolver.emptyConfiguration()).flags(atlas);
    Assert.assertEquals(1, Iterables.size(flags));
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) PackedAtlasBuilder(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder) Rectangle(org.openstreetmap.atlas.geography.Rectangle) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Segment(org.openstreetmap.atlas.geography.Segment) Location(org.openstreetmap.atlas.geography.Location) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)17 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)6 HashSet (java.util.HashSet)4 List (java.util.List)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Test (org.junit.Test)4 AtlasObject (org.openstreetmap.atlas.geography.atlas.items.AtlasObject)4 HighwayTag (org.openstreetmap.atlas.tags.HighwayTag)4 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)4 Arrays (java.util.Arrays)3 BaseCheck (org.openstreetmap.atlas.checks.base.BaseCheck)3 Location (org.openstreetmap.atlas.geography.Location)3 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)3 Area (org.openstreetmap.atlas.geography.atlas.items.Area)3 Queue (java.util.Queue)2 Collectors (java.util.stream.Collectors)2 PierTestCheck (org.openstreetmap.atlas.checks.base.checks.PierTestCheck)2 PolyLine (org.openstreetmap.atlas.geography.PolyLine)2 Polygon (org.openstreetmap.atlas.geography.Polygon)2