From 6799c0a171d4cc5f49799be57e39c1a4c7ecc894 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sat, 18 Aug 2018 10:46:16 +0200 Subject: [PATCH 01/10] Suspect-Manager: new-suspects-filter --- .../java/btools/server/SuspectManager.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 621fe0f..98c155d 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -43,12 +43,14 @@ public class SuspectManager extends Thread public static void process( String url, BufferedWriter bw ) throws IOException { bw.write( "\n" ); + bw.write( "BRouter suspect manager. Help " ); StringTokenizer tk = new StringTokenizer( url, "/" ); tk.nextToken(); tk.nextToken(); long id = 0L; String country = null; + String filter = null; if ( tk.hasMoreTokens() ) { @@ -56,10 +58,16 @@ public class SuspectManager extends Thread if ( new File( "suspects/suspects_" + ctry + ".txt" ).exists() ) { country = ctry; + + if ( tk.hasMoreTokens() ) + { + filter = tk.nextToken(); + } } } if ( country == null ) // generate country list { + bw.write( "\n" ); File[] files = new File( "suspects" ).listFiles(); TreeSet names = new TreeSet(); for ( File f : files ) @@ -73,8 +81,9 @@ public class SuspectManager extends Thread for ( String ctry : names ) { String url2 = "/brouter/suspects/" + ctry; - bw.write( "" + ctry + "
\n" ); + bw.write( "
\n" ); } + bw.write( "
" + ctry + "newall
\n" ); bw.write( "\n" ); bw.flush(); return; @@ -109,7 +118,7 @@ public class SuspectManager extends Thread break; StringTokenizer tk2 = new StringTokenizer( line ); id = Long.parseLong( tk2.nextToken() ); - String countryId = country + "/" + id; + String countryId = country + "/" + filter + "/" + id; if ( new File( "falsepositives/" + id ).exists() ) { @@ -150,7 +159,7 @@ public class SuspectManager extends Thread int wps = NearRecentWps.count( id ); if ( wps < 8 ) { - message = "marking false-positive requires at least 10 recent nearby waypoints from BRouter-Web, found: " + wps; + message = "marking false-positive requires at least 8 recent nearby waypoints from BRouter-Web, found: " + wps; } else { @@ -178,7 +187,7 @@ public class SuspectManager extends Thread } if ( id != 0L ) { - String countryId = country + "/" + id; + String countryId = country + "/" + filter + "/" + id; int ilon = (int) ( id >> 32 ); int ilat = (int) ( id & 0xffffffff ); @@ -217,7 +226,7 @@ public class SuspectManager extends Thread File fixedEntry = new File( "fixedsuspects/" + id ); if ( fixedEntry.exists() ) { - bw.write( "

back to watchlist

\n" ); + bw.write( "

back to watchlist

\n" ); } else { @@ -231,14 +240,14 @@ public class SuspectManager extends Thread { bw.write( "mark as a confirmed issue

\n" ); } - bw.write( "

back to issue list

\n" ); + bw.write( "

back to issue list

\n" ); } } else { File suspects = new File( "suspects/suspects_" + country + ".txt" ); - bw.write( "suspect list for " + country + "\n" ); - bw.write( "
see watchlist\n" ); + bw.write( filter + " suspect list for " + country + "\n" ); + bw.write( "
see watchlist\n" ); bw.write( "
back to country list

\n" ); if ( suspects.exists() ) { @@ -258,9 +267,10 @@ public class SuspectManager extends Thread break; StringTokenizer tk2 = new StringTokenizer( line ); id = Long.parseLong( tk2.nextToken() ); + int prio = Integer.parseInt( tk2.nextToken() ); prio = ( ( prio + 1 ) / 2 ) * 2; // normalize (no link prios) - String countryId = country + "/" + id; + String countryId = country + "/" + filter + "/" + id; String hint = ""; @@ -272,6 +282,10 @@ public class SuspectManager extends Thread { continue; // known fixed } + if ( "new".equals( filter ) && new File( "suspectarchive/" + id ).exists() ) + { + continue; // known fixed + } if ( pass == 1 ) { if ( prio > maxprio ) From 337ee21d1760ad1f6b4b4cc4d1f7973edcf9920e Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sun, 19 Aug 2018 11:33:34 +0200 Subject: [PATCH 02/10] Suspect-Manager: josm+overpass links --- .../java/btools/server/SuspectManager.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 98c155d..e1f3e08 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -5,11 +5,23 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.StringTokenizer; import java.util.TreeSet; public class SuspectManager extends Thread { + private static SimpleDateFormat dfTimestampZ = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ); + + private static String formatZ( Date date ) + { + synchronized( dfTimestampZ ) + { + return dfTimestampZ.format( date ); + } + } + private static String formatAge( File f ) { long age = System.currentTimeMillis() - f.lastModified(); @@ -43,7 +55,7 @@ public class SuspectManager extends Thread public static void process( String url, BufferedWriter bw ) throws IOException { bw.write( "\n" ); - bw.write( "BRouter suspect manager. Help " ); + bw.write( "BRouter suspect manager. Help

\n" ); StringTokenizer tk = new StringTokenizer( url, "/" ); tk.nextToken(); @@ -81,7 +93,7 @@ public class SuspectManager extends Thread for ( String ctry : names ) { String url2 = "/brouter/suspects/" + ctry; - bw.write( "" + ctry + "newall\n" ); + bw.write( "" + ctry + " new  all \n" ); } bw.write( "\n" ); bw.write( "\n" ); @@ -204,7 +216,7 @@ public class SuspectManager extends Thread } String url1 = "http://brouter.de/brouter-web/#zoom=18&lat=" + dlat + "&lon=" + dlon - + "&layer=OpenStreetMap&lonlats=" + dlon + "," + dlat + "&profile=" + profile; + + "&lonlats=" + dlon + "," + dlat + "&profile=" + profile; // String url1 = "http://localhost:8080/brouter-web/#map=18/" + dlat + "/" // + dlon + "/Mapsforge Tile Server&lonlats=" + dlon + "," + dlat; @@ -213,9 +225,13 @@ public class SuspectManager extends Thread double slon = 0.00156; double slat = 0.001; - String url3 = "http://osmose.openstreetmap.fr/de/josm_proxy?load_and_zoom?left=" + ( dlon - slon ) + String url3 = "http://127.0.0.1:8111/load_and_zoom?left=" + ( dlon - slon ) + "&bottom=" + ( dlat - slat ) + "&right=" + ( dlon + slon ) + "&top=" + ( dlat + slat ); + Date weekAgo = new Date( System.currentTimeMillis() - 604800000L ); + String url4 = "https://overpass-turbo.eu/?Q=[date:"" + formatZ( weekAgo ) + "Z"];way[highway]({{bbox}});out meta geom;&C=" + + dlat + ";" + dlon + ";18"; + if ( message != null ) { bw.write( "" + message + "

\n" ); @@ -223,6 +239,8 @@ public class SuspectManager extends Thread bw.write( "Open in BRouter-Web

\n" ); bw.write( "Open in OpenStreetmap

\n" ); bw.write( "Open in JOSM (via remote control)

\n" ); + bw.write( "Open in Overpass / minus one week

\n" ); + bw.write( "
\n" ); File fixedEntry = new File( "fixedsuspects/" + id ); if ( fixedEntry.exists() ) { From 373dc7ce367abf69117014df5d0e5559ee27a6b2 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sat, 25 Aug 2018 21:28:33 +0200 Subject: [PATCH 03/10] Suspect Manager: who-did-it, hide-for --- .../java/btools/server/SuspectManager.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index e1f3e08..4c298e4 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -193,8 +193,16 @@ public class SuspectManager extends Thread } if ( "fixed".equals( command ) ) { - new File( "fixedsuspects/" + id ).createNewFile(); + File fixedMarker = new File( "fixedsuspects/" + id ); + fixedMarker.createNewFile(); id = 0L; + + if ( tk.hasMoreTokens() ) + { + String param = tk.nextToken(); + int hideDays = Integer.parseInt( param ); + fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L ); + } } } if ( id != 0L ) @@ -232,6 +240,8 @@ public class SuspectManager extends Thread String url4 = "https://overpass-turbo.eu/?Q=[date:"" + formatZ( weekAgo ) + "Z"];way[highway]({{bbox}});out meta geom;&C=" + dlat + ";" + dlon + ";18"; + String url5 = "https://simon04.dev.openstreetmap.org/whodidit/?zoom=13&lat=" + dlat + "&lon=" + dlon + "&layers=BTT"; + if ( message != null ) { bw.write( "" + message + "

\n" ); @@ -240,6 +250,7 @@ public class SuspectManager extends Thread bw.write( "Open in OpenStreetmap

\n" ); bw.write( "Open in JOSM (via remote control)

\n" ); bw.write( "Open in Overpass / minus one week

\n" ); + bw.write( "Open in Who-Did-It / last week

\n" ); bw.write( "
\n" ); File fixedEntry = new File( "fixedsuspects/" + id ); if ( fixedEntry.exists() ) @@ -252,7 +263,14 @@ public class SuspectManager extends Thread File confirmedEntry = new File( "confirmednegatives/" + id ); if ( confirmedEntry.exists() ) { - bw.write( "mark as fixed

\n" ); + String prefix = "mark as fixed

\n" ); + bw.write( "hide for " ); + bw.write( prefix2 + "/7\">1 week" ); + bw.write( prefix2 + "/30\">1 month" ); + bw.write( prefix2 + "/91\">3 months" ); + bw.write( prefix2 + "/182\">6 months

\n" ); } else { From 2a8ceff2d9b565109d845bf0b062a6040f7b63d8 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sat, 1 Sep 2018 12:15:37 +0200 Subject: [PATCH 04/10] changed fixedsuspect expiry --- .../java/btools/server/SuspectManager.java | 207 +++++++++--------- 1 file changed, 109 insertions(+), 98 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 4c298e4..10ba3c3 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -101,6 +101,15 @@ public class SuspectManager extends Thread return; } + File suspectFile = new File( "suspects/suspects_" + country + ".txt" ); + if ( suspectFile.exists() ) + { + bw.write( "suspect file for country '" + country + "' not found\n" ); + bw.write( "\n" ); + bw.flush(); + return; + } + boolean showWatchList = false; if ( tk.hasMoreTokens() ) { @@ -117,46 +126,41 @@ public class SuspectManager extends Thread if ( showWatchList ) { - File suspects = new File( "suspects/suspects_" + country + ".txt" ); bw.write( "watchlist for " + country + "\n" ); bw.write( "
back to country list

\n" ); - if ( suspects.exists() ) + BufferedReader r = new BufferedReader( new FileReader( suspectFile ) ); + for ( ;; ) { - BufferedReader r = new BufferedReader( new FileReader( suspects ) ); - for ( ;; ) - { - String line = r.readLine(); - if ( line == null ) - break; - StringTokenizer tk2 = new StringTokenizer( line ); - id = Long.parseLong( tk2.nextToken() ); - String countryId = country + "/" + filter + "/" + id; + String line = r.readLine(); + if ( line == null ) + break; + StringTokenizer tk2 = new StringTokenizer( line ); + id = Long.parseLong( tk2.nextToken() ); + String countryId = country + "/" + filter + "/" + id; - if ( new File( "falsepositives/" + id ).exists() ) - { - continue; // known false positive - } - File fixedEntry = new File( "fixedsuspects/" + id ); - File confirmedEntry = new File( "confirmednegatives/" + id ); - if ( !( fixedEntry.exists() && confirmedEntry.exists() ) ) - { - continue; - } - long age = System.currentTimeMillis() - confirmedEntry.lastModified(); - if ( age / 1000 < 3600 * 24 * 8 ) - { - continue; - } - String hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; - int ilon = (int) ( id >> 32 ); - int ilat = (int) ( id & 0xffffffff ); - double dlon = ( ilon - 180000000 ) / 1000000.; - double dlat = ( ilat - 90000000 ) / 1000000.; - String url2 = "/brouter/suspects/" + countryId; - bw.write( "" + dlon + "," + dlat + "" + hint + "
\n" ); + if ( new File( "falsepositives/" + id ).exists() ) + { + continue; // known false positive } - r.close(); + File confirmedEntry = new File( "confirmednegatives/" + id ); + if ( !( isFixed( id, suspectFile ) && confirmedEntry.exists() ) ) + { + continue; + } + long age = System.currentTimeMillis() - confirmedEntry.lastModified(); + if ( age / 1000 < 3600 * 24 * 8 ) + { + continue; + } + String hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; + int ilon = (int) ( id >> 32 ); + int ilat = (int) ( id & 0xffffffff ); + double dlon = ( ilon - 180000000 ) / 1000000.; + double dlat = ( ilat - 90000000 ) / 1000000.; + String url2 = "/brouter/suspects/" + countryId; + bw.write( "" + dlon + "," + dlat + "" + hint + "
\n" ); } + r.close(); bw.write( "\n" ); bw.flush(); return; @@ -194,15 +198,20 @@ public class SuspectManager extends Thread if ( "fixed".equals( command ) ) { File fixedMarker = new File( "fixedsuspects/" + id ); - fixedMarker.createNewFile(); + if ( !fixedMarker.exists() ) + { + fixedMarker.createNewFile(); + } id = 0L; + int hideDays = 0; if ( tk.hasMoreTokens() ) { String param = tk.nextToken(); - int hideDays = Integer.parseInt( param ); + hideDays = Integer.parseInt( param ); fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L ); } + fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L ); } } if ( id != 0L ) @@ -252,8 +261,7 @@ public class SuspectManager extends Thread bw.write( "Open in Overpass / minus one week

\n" ); bw.write( "Open in Who-Did-It / last week

\n" ); bw.write( "
\n" ); - File fixedEntry = new File( "fixedsuspects/" + id ); - if ( fixedEntry.exists() ) + if ( isFixed( id, suspectFile ) ) { bw.write( "

back to watchlist

\n" ); } @@ -281,72 +289,68 @@ public class SuspectManager extends Thread } else { - File suspects = new File( "suspects/suspects_" + country + ".txt" ); bw.write( filter + " suspect list for " + country + "\n" ); bw.write( "
see watchlist\n" ); bw.write( "
back to country list

\n" ); - if ( suspects.exists() ) + int maxprio = 0; + for ( int pass = 1; pass <= 2; pass++ ) { - int maxprio = 0; - for ( int pass = 1; pass <= 2; pass++ ) + if ( pass == 2 ) { - if ( pass == 2 ) - { - bw.write( "current level: " + getLevelDecsription( maxprio ) + "

\n" ); - } - - BufferedReader r = new BufferedReader( new FileReader( suspects ) ); - for ( ;; ) - { - String line = r.readLine(); - if ( line == null ) - break; - StringTokenizer tk2 = new StringTokenizer( line ); - id = Long.parseLong( tk2.nextToken() ); - - int prio = Integer.parseInt( tk2.nextToken() ); - prio = ( ( prio + 1 ) / 2 ) * 2; // normalize (no link prios) - String countryId = country + "/" + filter + "/" + id; - - String hint = ""; - - if ( new File( "falsepositives/" + id ).exists() ) - { - continue; // known false positive - } - if ( new File( "fixedsuspects/" + id ).exists() ) - { - continue; // known fixed - } - if ( "new".equals( filter ) && new File( "suspectarchive/" + id ).exists() ) - { - continue; // known fixed - } - if ( pass == 1 ) - { - if ( prio > maxprio ) - maxprio = prio; - continue; - } - else - { - if ( prio < maxprio ) - continue; - } - File confirmedEntry = new File( "confirmednegatives/" + id ); - if ( confirmedEntry.exists() ) - { - hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; - } - int ilon = (int) ( id >> 32 ); - int ilat = (int) ( id & 0xffffffff ); - double dlon = ( ilon - 180000000 ) / 1000000.; - double dlat = ( ilat - 90000000 ) / 1000000.; - String url2 = "/brouter/suspects/" + countryId; - bw.write( "" + dlon + "," + dlat + "" + hint + "
\n" ); - } - r.close(); + bw.write( "current level: " + getLevelDecsription( maxprio ) + "

\n" ); } + + BufferedReader r = new BufferedReader( new FileReader( suspectFile ) ); + for ( ;; ) + { + String line = r.readLine(); + if ( line == null ) + break; + StringTokenizer tk2 = new StringTokenizer( line ); + id = Long.parseLong( tk2.nextToken() ); + + int prio = Integer.parseInt( tk2.nextToken() ); + prio = ( ( prio + 1 ) / 2 ) * 2; // normalize (no link prios) + String countryId = country + "/" + filter + "/" + id; + + String hint = ""; + + if ( new File( "falsepositives/" + id ).exists() ) + { + continue; // known false positive + } + if ( isFixed( id, suspectFile ) ) + { + continue; // known fixed + } + if ( "new".equals( filter ) && new File( "suspectarchive/" + id ).exists() ) + { + continue; // known fixed + } + if ( pass == 1 ) + { + if ( prio > maxprio ) + maxprio = prio; + continue; + } + else + { + if ( prio < maxprio ) + continue; + } + File confirmedEntry = new File( "confirmednegatives/" + id ); + if ( confirmedEntry.exists() ) + { + hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; + } + int ilon = (int) ( id >> 32 ); + int ilat = (int) ( id & 0xffffffff ); + double dlon = ( ilon - 180000000 ) / 1000000.; + double dlat = ( ilat - 90000000 ) / 1000000.; + String url2 = "/brouter/suspects/" + countryId; + bw.write( "" + dlon + "," + dlat + "" + hint + "
\n" ); + } + r.close(); } } bw.write( "\n" ); @@ -354,4 +358,11 @@ public class SuspectManager extends Thread return; } + + private static boolean isFixed( long id, File suspectFile ) + { + File fixedEntry = new File( "fixedsuspects/" + id ); + return fixedEntry.exists() && fixedEntry.lastModified() > suspectFile.lastModified(); + } + } From 235f8242e708c8b434378e50ae0632723fdd93e4 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sat, 1 Sep 2018 12:39:55 +0200 Subject: [PATCH 05/10] changed fixedsuspect expiry --- brouter-server/src/main/java/btools/server/SuspectManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 10ba3c3..2c13407 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -102,7 +102,7 @@ public class SuspectManager extends Thread } File suspectFile = new File( "suspects/suspects_" + country + ".txt" ); - if ( suspectFile.exists() ) + if ( !suspectFile.exists() ) { bw.write( "suspect file for country '" + country + "' not found\n" ); bw.write( "\n" ); From b9a13183dfccf7de3e141de96effaa75caa8cd5e Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sat, 1 Sep 2018 16:24:16 +0200 Subject: [PATCH 06/10] suspect-manager: who-did-it -> latest-changes --- .../src/main/java/btools/server/SuspectManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 2c13407..65ece8f 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -249,7 +249,7 @@ public class SuspectManager extends Thread String url4 = "https://overpass-turbo.eu/?Q=[date:"" + formatZ( weekAgo ) + "Z"];way[highway]({{bbox}});out meta geom;&C=" + dlat + ";" + dlon + ";18"; - String url5 = "https://simon04.dev.openstreetmap.org/whodidit/?zoom=13&lat=" + dlat + "&lon=" + dlon + "&layers=BTT"; + String url5 = "https://tyrasd.github.io/latest-changes/#16/" + dlat + "/" + dlon; if ( message != null ) { @@ -259,7 +259,7 @@ public class SuspectManager extends Thread bw.write( "Open in OpenStreetmap

\n" ); bw.write( "Open in JOSM (via remote control)

\n" ); bw.write( "Open in Overpass / minus one week

\n" ); - bw.write( "Open in Who-Did-It / last week

\n" ); + bw.write( "Open in Latest-Changes / last week

\n" ); bw.write( "
\n" ); if ( isFixed( id, suspectFile ) ) { From e25c531d2d3945ec40983b4cc222bb9f86d3674e Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Tue, 4 Sep 2018 20:39:17 +0200 Subject: [PATCH 07/10] SuspectManager: Node-Context, filter-speedup --- .../java/btools/server/SuspectManager.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 65ece8f..c89fa37 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -246,8 +246,11 @@ public class SuspectManager extends Thread + "&bottom=" + ( dlat - slat ) + "&right=" + ( dlon + slon ) + "&top=" + ( dlat + slat ); Date weekAgo = new Date( System.currentTimeMillis() - 604800000L ); - String url4 = "https://overpass-turbo.eu/?Q=[date:"" + formatZ( weekAgo ) + "Z"];way[highway]({{bbox}});out meta geom;&C=" - + dlat + ";" + dlon + ";18"; + String url4a = "https://overpass-turbo.eu/?Q=[date:"" + formatZ( weekAgo ) + "Z"];way[highway]({{bbox}});out meta geom;&C=" + + dlat + ";" + dlon + ";18&R"; + + String url4b = "https://overpass-turbo.eu/?Q=(node(around%3A1%2C%7B%7Bcenter%7D%7D)-%3E.n%3Bway(bn.n)%3Brel(bn.n%3A%22via%22)%5Btype%3Drestriction%5D%3B)%3Bout%20meta%3B%3E%3Bout%20skel%20qt%3B&C=" + + dlat + ";" + dlon + ";18&R"; String url5 = "https://tyrasd.github.io/latest-changes/#16/" + dlat + "/" + dlon; @@ -258,7 +261,7 @@ public class SuspectManager extends Thread bw.write( "Open in BRouter-Web

\n" ); bw.write( "Open in OpenStreetmap

\n" ); bw.write( "Open in JOSM (via remote control)

\n" ); - bw.write( "Open in Overpass / minus one week

\n" ); + bw.write( "Overpass: minus one week    node context

\n" ); bw.write( "Open in Latest-Changes / last week

\n" ); bw.write( "
\n" ); if ( isFixed( id, suspectFile ) ) @@ -307,12 +310,24 @@ public class SuspectManager extends Thread if ( line == null ) break; StringTokenizer tk2 = new StringTokenizer( line ); - id = Long.parseLong( tk2.nextToken() ); + String idString = tk2.nextToken(); int prio = Integer.parseInt( tk2.nextToken() ); prio = ( ( prio + 1 ) / 2 ) * 2; // normalize (no link prios) - String countryId = country + "/" + filter + "/" + id; + if ( pass == 1 ) + { + if ( prio <= maxprio ) + continue; + } + else + { + if ( prio < maxprio ) + continue; + } + + id = Long.parseLong( idString ); + String countryId = country + "/" + filter + "/" + id; String hint = ""; if ( new File( "falsepositives/" + id ).exists() ) @@ -329,15 +344,9 @@ public class SuspectManager extends Thread } if ( pass == 1 ) { - if ( prio > maxprio ) - maxprio = prio; + maxprio = prio; continue; } - else - { - if ( prio < maxprio ) - continue; - } File confirmedEntry = new File( "confirmednegatives/" + id ); if ( confirmedEntry.exists() ) { From d7578fee03cd5dd9c01a5be07eac6e3010d7ecf3 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Wed, 12 Sep 2018 20:29:37 +0200 Subject: [PATCH 08/10] suspect-manager: dynamic polygon check --- .../src/main/java/btools/server/Area.java | 76 ++++++++++++++++ .../src/main/java/btools/server/Polygon.java | 89 +++++++++++++++++++ .../java/btools/server/SuspectManager.java | 86 ++++++++++++------ 3 files changed, 223 insertions(+), 28 deletions(-) create mode 100644 brouter-server/src/main/java/btools/server/Area.java create mode 100644 brouter-server/src/main/java/btools/server/Polygon.java diff --git a/brouter-server/src/main/java/btools/server/Area.java b/brouter-server/src/main/java/btools/server/Area.java new file mode 100644 index 0000000..75075d8 --- /dev/null +++ b/brouter-server/src/main/java/btools/server/Area.java @@ -0,0 +1,76 @@ +package btools.server; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Area +{ + private List poslist = new ArrayList(); + private List neglist = new ArrayList(); + + public static void main( String[] args ) throws IOException + { + Area a = new Area( new File( args[0] ) ); + + System.out.println( args[1] + " is in " + args[0] + "=" + a.isInArea( Long.parseLong( args[1] ) ) ); + } + + public Area( File f ) throws IOException + { + BufferedReader br = new BufferedReader( new FileReader( f ) ); + br.readLine(); + + for(;;) + { + String head = br.readLine(); + if ( head == null || "END".equals( head ) ) + { + break; + } + Polygon pol = new Polygon( br ); + if ( head.startsWith( "!" ) ) + { + neglist.add( pol ); + } + else + { + poslist.add( pol ); + } + } + } + + public boolean isInArea( long id ) + { + for( int i=0; i lines = new ArrayList(); + + for(;;) + { + String line = br.readLine(); + if ( line == null || "END".equals( line ) ) + { + break; + } + lines.add( line ); + } + int n = lines.size(); + ax = new int[n]; + ay = new int[n]; + for( int i=0; i maxx ) maxx = x; + if ( y > maxy ) maxy = y; + } + } + + public boolean isInPolygon( long id ) + { + int x = (int) ( id >> 32 ); + int y = (int) ( id & 0xffffffff ); + + if ( x < minx || x > maxx || y < miny || y > maxy ) + { + return false; + } + + int n = ax.length-1; // these are closed polygons + + boolean inside = false; + int j = n - 1; + for (int i = 0 ;i < n ; j = i++) + { + if ( (ay[i] > y) != (ay[j] > y) ) + { + long v = ax[j] - ax[i]; + v *= y - ay[i]; + v /= ay[j] - ay[i]; + if ( x <= v + ax[i]) + { + inside = !inside; + } + } + } + return inside; + } + + public boolean isInBoundingBox( long id ) + { + int x = (int) ( id >> 32 ); + int y = (int) ( id & 0xffffffff ); + + return x >= minx && x <= maxx && y >= miny && y <= maxy; + } + +} diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index c89fa37..1ca6cac 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -61,39 +61,46 @@ public class SuspectManager extends Thread tk.nextToken(); tk.nextToken(); long id = 0L; - String country = null; + String country = ""; String filter = null; - if ( tk.hasMoreTokens() ) + while ( tk.hasMoreTokens() ) { - String ctry = tk.nextToken(); - if ( new File( "suspects/suspects_" + ctry + ".txt" ).exists() ) + String c = tk.nextToken(); + if ( "all".equals( c ) || "new".equals( c ) ) { - country = ctry; - - if ( tk.hasMoreTokens() ) - { - filter = tk.nextToken(); - } + filter = c; + break; } + country += "/" + c; } - if ( country == null ) // generate country list + + if ( filter == null ) // generate country list { bw.write( "\n" ); - File[] files = new File( "suspects" ).listFiles(); + File countryParent = new File( "worldpolys" + country ); + File[] files = countryParent.listFiles(); TreeSet names = new TreeSet(); for ( File f : files ) { String name = f.getName(); - if ( name.startsWith( "suspects_" ) && name.endsWith( ".txt" ) ) + if ( name.endsWith( ".poly" ) ) { - names.add( name.substring( 9, name.length() - 4 ) ); + names.add( name.substring( 0, name.length() - 5 ) ); } } - for ( String ctry : names ) + for ( String c : names ) { - String url2 = "/brouter/suspects/" + ctry; - bw.write( "\n" ); + String url2 = "/brouter/suspects" + country + "/" + c; + String linkNew = ""; + String linkAll = ""; + + String linkSub = ""; + if ( new File( countryParent, c ).exists() ) + { + linkSub = ""; + } + bw.write( "" + linkNew + linkAll + linkSub + "\n" ); } bw.write( "
" + ctry + " new  all  new  all  sub-regions 
" + c + "
\n" ); bw.write( "\n" ); @@ -101,10 +108,21 @@ public class SuspectManager extends Thread return; } - File suspectFile = new File( "suspects/suspects_" + country + ".txt" ); + File polyFile = new File( "worldpolys" + country + ".poly" ); + if ( !polyFile.exists() ) + { + bw.write( "polygon file for country '" + country + "' not found\n" ); + bw.write( "\n" ); + bw.flush(); + return; + } + + Area polygon = new Area( polyFile ); + + File suspectFile = new File( "worldsuspects.txt" ); if ( !suspectFile.exists() ) { - bw.write( "suspect file for country '" + country + "' not found\n" ); + bw.write( "suspect file worldsuspects.txt not found\n" ); bw.write( "\n" ); bw.flush(); return; @@ -152,12 +170,16 @@ public class SuspectManager extends Thread { continue; } + if ( !polygon.isInArea( id ) ) + { + continue; // not in selected polygon + } String hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; int ilon = (int) ( id >> 32 ); int ilat = (int) ( id & 0xffffffff ); double dlon = ( ilon - 180000000 ) / 1000000.; double dlat = ( ilat - 90000000 ) / 1000000.; - String url2 = "/brouter/suspects/" + countryId; + String url2 = "/brouter/suspects" + countryId; bw.write( "" + dlon + "," + dlat + "" + hint + "
\n" ); } r.close(); @@ -270,11 +292,11 @@ public class SuspectManager extends Thread } else { - bw.write( "mark false positive (=not an issue)

\n" ); + bw.write( "mark false positive (=not an issue)

\n" ); File confirmedEntry = new File( "confirmednegatives/" + id ); if ( confirmedEntry.exists() ) { - String prefix = "mark as fixed

\n" ); bw.write( "hide for " ); @@ -285,15 +307,15 @@ public class SuspectManager extends Thread } else { - bw.write( "mark as a confirmed issue

\n" ); + bw.write( "mark as a confirmed issue

\n" ); } - bw.write( "

back to issue list

\n" ); + bw.write( "

back to issue list

\n" ); } } else { bw.write( filter + " suspect list for " + country + "\n" ); - bw.write( "
see watchlist\n" ); + bw.write( "
see watchlist\n" ); bw.write( "
back to country list

\n" ); int maxprio = 0; for ( int pass = 1; pass <= 2; pass++ ) @@ -327,9 +349,11 @@ public class SuspectManager extends Thread } id = Long.parseLong( idString ); - String countryId = country + "/" + filter + "/" + id; - String hint = ""; + if ( !polygon.isInBoundingBox( id ) ) + { + continue; // not in selected polygon (pre-check) + } if ( new File( "falsepositives/" + id ).exists() ) { continue; // known false positive @@ -342,12 +366,18 @@ public class SuspectManager extends Thread { continue; // known fixed } + if ( !polygon.isInArea( id ) ) + { + continue; // not in selected polygon + } if ( pass == 1 ) { maxprio = prio; continue; } + String countryId = country + "/" + filter + "/" + id; File confirmedEntry = new File( "confirmednegatives/" + id ); + String hint = ""; if ( confirmedEntry.exists() ) { hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; @@ -356,7 +386,7 @@ public class SuspectManager extends Thread int ilat = (int) ( id & 0xffffffff ); double dlon = ( ilon - 180000000 ) / 1000000.; double dlat = ( ilat - 90000000 ) / 1000000.; - String url2 = "/brouter/suspects/" + countryId; + String url2 = "/brouter/suspects" + countryId; bw.write( "" + dlon + "," + dlat + "" + hint + "
\n" ); } r.close(); From 89b60cc54c826be695613439592ad2c5b8466cf1 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Thu, 13 Sep 2018 13:07:16 +0200 Subject: [PATCH 09/10] performance fix --- brouter-core/src/main/java/btools/router/ProfileCache.java | 2 +- brouter-core/src/main/java/btools/router/RoutingEngine.java | 3 +-- brouter-server/src/main/java/btools/server/BRouter.java | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/ProfileCache.java b/brouter-core/src/main/java/btools/router/ProfileCache.java index d823c96..4115004 100644 --- a/brouter-core/src/main/java/btools/router/ProfileCache.java +++ b/brouter-core/src/main/java/btools/router/ProfileCache.java @@ -78,7 +78,7 @@ public final class ProfileCache rc.expctxWay.setAllTagsUsed(); } - lastProfileTimestamp = profileFile.lastModified(); + lastProfileTimestamp = rc.profileTimestamp; lastLookupTimestamp = lookupFile.lastModified(); lastProfileFile = profileFile; lastLookupFile = lookupFile; diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 58e388a..4193842 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -288,8 +288,6 @@ public class RoutingEngine extends Thread listOne.add( seedPoint ); matchWaypointsToNodes( listOne ); - routingContext.countTraffic = true; - findTrack( "seededSearch", seedPoint, null, null, null, false ); } catch( IllegalArgumentException e) @@ -309,6 +307,7 @@ public class RoutingEngine extends Thread } finally { + ProfileCache.releaseProfile( routingContext ); if ( nodesCache != null ) { nodesCache.close(); diff --git a/brouter-server/src/main/java/btools/server/BRouter.java b/brouter-server/src/main/java/btools/server/BRouter.java index 8dbe265..1a288e9 100644 --- a/brouter-server/src/main/java/btools/server/BRouter.java +++ b/brouter-server/src/main/java/btools/server/BRouter.java @@ -114,6 +114,7 @@ public class BRouter re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc ); re.boundary = boundary; re.airDistanceCostFactor = rc.trafficDirectionFactor; + rc.countTraffic = true; re.doSearch(); if ( re.getErrorMessage() != null ) { From 5dcfa91ab922f6f31d9fb72e4064ac130c452d73 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Fri, 14 Sep 2018 13:45:38 +0200 Subject: [PATCH 10/10] performance fix --- .../java/btools/router/KinematicModel.java | 8 ++- .../btools/router/KinematicModelDummy.java | 64 ------------------- 2 files changed, 6 insertions(+), 66 deletions(-) delete mode 100644 brouter-core/src/main/java/btools/router/KinematicModelDummy.java diff --git a/brouter-core/src/main/java/btools/router/KinematicModel.java b/brouter-core/src/main/java/btools/router/KinematicModel.java index cf34abd..7c89c59 100644 --- a/brouter-core/src/main/java/btools/router/KinematicModel.java +++ b/brouter-core/src/main/java/btools/router/KinematicModel.java @@ -11,7 +11,7 @@ import btools.expressions.BExpressionContextNode; import btools.expressions.BExpressionContextWay; -class KinematicModel extends OsmPathModel +final class KinematicModel extends OsmPathModel { public OsmPrePath createPrePath() { @@ -119,7 +119,11 @@ class KinematicModel extends OsmPathModel */ public double getEffectiveSpeedLimit( ) { - return Math.min( getWayMaxspeed(), Math.max( getWayMinspeed(), vmax ) ); + // performance related inline coding + double minspeed = getWayMinspeed(); + double espeed = minspeed > vmax ? minspeed : vmax; + double maxspeed = getWayMaxspeed(); + return maxspeed < espeed ? maxspeed : espeed; } /** diff --git a/brouter-core/src/main/java/btools/router/KinematicModelDummy.java b/brouter-core/src/main/java/btools/router/KinematicModelDummy.java deleted file mode 100644 index af4c2b4..0000000 --- a/brouter-core/src/main/java/btools/router/KinematicModelDummy.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Container for link between two Osm nodes - * - * @author ab - */ -package btools.router; - -import java.util.Map; - -import btools.expressions.BExpressionContextNode; -import btools.expressions.BExpressionContextWay; - - -final class KinematicModelDummy extends KinematicModel -{ - public OsmPrePath createPrePath() - { - return null; - } - - public OsmPath createPath() - { - return null; - } - - public KinematicModelDummy() - { - turnAngleDecayLength = 50.; - f_roll = 232.; - f_air = 0.4; - f_recup = 600.; - p_standby = 250.; - recup_efficiency = 0.7; - totalweight = 1640.; - vmax = 60./ 3.6; - leftWaySpeed = 12.f / 3.6; - rightWaySpeed = 12.f / 3.6; - } - public boolean useNewtonApprox; - - // derived values - public double xweight = 1./( 2. * f_air * vmax * vmax * vmax - p_standby ); - public double timecost0 = 1./vmax + xweight*(f_roll + f_air*vmax*vmax + p_standby/vmax ); - - @Override - public void init( BExpressionContextWay expctxWay, BExpressionContextNode expctxNode, Map extraParams ) - { - } - - public float getWayMaxspeed() - { - return 100.f; - } - - public float getWayMinspeed() - { - return 0.f; - } - - public float getNodeMaxspeed() - { - return 999.f; - } -}