Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significantly improve performance for StreetAddressTest #47

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
call-workflow:
strategy:
matrix:
josm-revision: ["", "r18877"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2
josm-revision: ["", "r19067"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v3
with:
java-version: 17
josm-revision: ${{ matrix.josm-revision }}
plugin-jar-name: 'mapwithai'
perform-revision-tagging: ${{ matrix.josm-revision == 'r18877' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
perform-revision-tagging: ${{ matrix.josm-revision == 'r19067' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
secrets: inherit

2 changes: 1 addition & 1 deletion .github/workflows/reports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ permissions:

jobs:
call-workflow:
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v2
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v3
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# The minimum JOSM version this plugin is compatible with (can be any numeric version
plugin.main.version = 18877
plugin.main.version = 19067
# The JOSM version this plugin is currently compiled against
# Please make sure this version is available at https://josm.openstreetmap.de/download
# The special values "latest" and "tested" are also possible here, but not recommended.
plugin.compile.version = 18877
plugin.compile.version = 19067
plugin.canloadatruntime = true
plugin.author = Taylor Smock
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin
Expand Down
193 changes: 193 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openstreetmap.josm.plugins</groupId>
<artifactId>MapWithAI</artifactId>
<version>SNAPSHOT</version>
<properties>
<jmockit.version>1.49.a</jmockit.version>
<pmd.version>7.5.0</pmd.version>
<jacoco.version>0.8.12</jacoco.version>
<checkstyle.version>10.18.1</checkstyle.version>
<spotbugs.version>4.8.6</spotbugs.version>
</properties>
<repositories>
<repository>
<id>JOSM-releases</id>
<url>https://josm.openstreetmap.de/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>JOSM-snapshots</id>
<url>https://josm.openstreetmap.de/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.openstreetmap.josm</groupId>
<artifactId>josm</artifactId>
<version>SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openstreetmap.josm.plugins</groupId>
<artifactId>pmtiles</artifactId>
<version>SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openstreetmap.josm.plugins</groupId>
<artifactId>utilsplugin2</artifactId>
<version>SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openstreetmap.josm</groupId>
<artifactId>josm-unittest</artifactId>
<version>SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency> <!-- needed until JOSM core removes Junit4 support -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.49.a</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/unit</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<java>
<eclipse>
<version>4.21</version>
<file>${project.basedir}/../00_core_tools/eclipse/formatter.xml</file>
</eclipse>
<removeUnusedImports/>
<licenseHeader>
<content>// License: GPL. For details, see LICENSE file.</content>
</licenseHeader>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/unit/**/*.java</include>
<include>src/test/integration/**/*.java</include>
</includes>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.3</version>
</requireMavenVersion>
</rules>
</configuration>
</plugin>
<!-- Configure the test plugin, specifically enable autodetection of global extensions -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
<argLine>-javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
<properties>
<configurationParameters>
file.encoding = UTF-8
java.locale.providers = SPI,CLDR
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.execution.parallel.enabled = true
</configurationParameters>
</properties>
<systemPropertyVariables>
<josm.home>src/test/build/config/josm.home</josm.home>
<josm.test.data>src/test/resources</josm.test.data>
<java.awt.headless>true</java.awt.headless>
<glass.platform>Monocle</glass.platform>
<monocle.platform>Headless</monocle.platform>
<prism.order>sw</prism.order>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
Logging.error(e);
}
}
} else {
esriInfo.add(layer);
}
}
layers.addAll(esriInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class StreetAddressTest extends Test {
public static final double BBOX_EXPANSION = 0.002;
private static final String ADDR_STREET = "addr:street";
private final Set<OsmPrimitive> namePrimitiveMap = new HashSet<>();
private final Map<Point2D, Set<String>> nameMap = new HashMap<>();
private final Map<Point2D, List<OsmPrimitive>> primitiveCellMap = new HashMap<>();
private final Map<Point, Set<String>> nameMap = new HashMap<>();
private final Map<Point, List<OsmPrimitive>> primitiveCellMap = new HashMap<>();
/**
* Classified highways. This uses a {@link Set} instead of a {@link List} since
* the MapWithAI code doesn't care about order.
Expand Down Expand Up @@ -146,7 +146,8 @@ private void realVisit(OsmPrimitive primitive) {
final var n1 = nodes.get(i);
final var n2 = nodes.get(i + 1);
for (Point2D cell : ValUtil.getSegmentCells(n1, n2, gridDetail)) {
this.nameMap.computeIfAbsent(cell, k -> new HashSet<>()).addAll(names);
this.nameMap.computeIfAbsent(new Point(cell.getX(), cell.getY()), k -> new HashSet<>())
.addAll(names);
}
}
} else if (hasStreetAddressTags(primitive) && !primitive.isOutsideDownloadArea()) {
Expand All @@ -159,7 +160,7 @@ private void realVisit(OsmPrimitive primitive) {
if (en != null) {
long x = (long) Math.floor(en.getX() * gridDetail);
long y = (long) Math.floor(en.getY() * gridDetail);
final var point = new Point2D.Double(x, y);
final var point = new Point(x, y);
primitiveCellMap.computeIfAbsent(point, p -> new ArrayList<>()).add(primitive);
}
}
Expand All @@ -174,7 +175,7 @@ private static Collection<String> getWayNames(IPrimitive way) {
.filter(s -> !s.isEmpty()).collect(Collectors.toSet());
}

private Collection<String> getSurroundingHighwayNames(Point2D point2D) {
private Collection<String> getSurroundingHighwayNames(Point point2D) {
if (this.nameMap.isEmpty()) {
return Collections.emptySet();
}
Expand All @@ -183,8 +184,9 @@ private Collection<String> getSurroundingHighwayNames(Point2D point2D) {
while (surroundingWays.isEmpty()) {
for (int x = -surrounding; x <= surrounding; x++) {
for (int y = -surrounding; y <= surrounding; y++) {
final var key = new Point2D.Double((long) Math.floor(point2D.getX() + x),
(long) Math.floor(point2D.getY() + y));
final var xPoint = (long) Math.floor(point2D.x() + x);
final var yPoint = (long) Math.floor(point2D.y() + y);
final var key = new Point(xPoint, yPoint);
if (this.nameMap.containsKey(key)) {
surroundingWays.addAll(this.nameMap.get(key));
}
Expand Down Expand Up @@ -303,4 +305,20 @@ public static BBox expandBBox(BBox bbox, double degree) {
bbox.add(bbox.getTopLeftLon() - degree, bbox.getTopLeftLat() + degree);
return bbox;
}
}

private record Point(double x, double y) implements Comparable<Point> {

@Override
public int compareTo(Point other) {
if (other.x == this.x && other.y == this.y) {
return 0;
}
if (other.x < this.x) {
return -1;
}
if (other.x > this.x) {
return 1;
}
return Double.compare(other.y, this.y);
}
}}
1 change: 1 addition & 0 deletions src/test/data
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
},
"response" : {
"status" : 200,
"body" : "{\n \"Taylor's Address Conflation Server\" : {\n \"categories\" : [\n \"addresses\"\n ],\n \"description\" : \"Originally developed for use with local datasets, it now accepts external datasets for conflation purposes. In the event of a failure, the plugin will use the original dataset.\",\n \"license\" : \"AGPL\",\n \"source\" : \"https://gitlab.com/smocktaylor/serve_osm_files/\",\n \"url\" : \"https://importdata.riverviewtechnologies.com/conflate\"\n }\n}\n",
"jsonBody": {
"Taylor's Address Conflation Server": {
"categories": [
"addresses"
],
"description": "Originally developed for use with local datasets, it now accepts external datasets for conflation purposes. In the event of a failure, the plugin will use the original dataset.",
"license": "AGPL",
"source": "{{ request.baseUrl }}/smocktaylor/serve_osm_files/",
"url": "{{ request.baseUrl }}/conflate"
}
},
"transformers": [
"response-template"
],
"headers" : {
"Accept-Ranges" : "bytes",
"Cache-Control" : "max-age=600",
Expand Down
Loading