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);
}
}
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());
}
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()));
}
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)));
}
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));
}
Aggregations