diff --git a/brouter-core/src/main/java/btools/router/SuspectInfo.java b/brouter-core/src/main/java/btools/router/SuspectInfo.java new file mode 100644 index 0000000..db86592 --- /dev/null +++ b/brouter-core/src/main/java/btools/router/SuspectInfo.java @@ -0,0 +1,66 @@ +package btools.router; + +import java.util.Map; + +public class SuspectInfo +{ + public static final int TRIGGER_DEAD_END = 1; + public static final int TRIGGER_DEAD_START = 2; + public static final int TRIGGER_NODE_BLOCK = 4; + public static final int TRIGGER_BAD_ACCESS = 8; + public static final int TRIGGER_UNK_ACCESS = 16; + public static final int TRIGGER_SHARP_EXIT = 32; + public static final int TRIGGER_SHARP_ENTRY = 64; + public static final int TRIGGER_SHARP_LINK = 128; + public static final int TRIGGER_BAD_TR = 256; + + public int prio; + public int triggers; + + public static void addSuspect( Map map, long id, int prio, int trigger ) + { + Long iD = Long.valueOf( id ); + SuspectInfo info = map.get( iD ); + if ( info == null ) + { + info = new SuspectInfo(); + map.put( iD, info ); + } + info.prio = Math.max( info.prio, prio ); + info.triggers |= trigger; + } + + public static SuspectInfo addTrigger( SuspectInfo old, int prio, int trigger ) + { + if ( old == null ) + { + old = new SuspectInfo(); + } + old.prio = Math.max( old.prio, prio ); + old.triggers |= trigger; + return old; + } + + public static String getTriggerText( int triggers ) + { + StringBuilder sb = new StringBuilder(); + addText( sb, "dead-end" , triggers, TRIGGER_DEAD_END ); + addText( sb, "dead-start" , triggers, TRIGGER_DEAD_START ); + addText( sb, "node-block" , triggers, TRIGGER_NODE_BLOCK ); + addText( sb, "bad-access" , triggers, TRIGGER_BAD_ACCESS ); + addText( sb, "unkown-access", triggers, TRIGGER_UNK_ACCESS ); + addText( sb, "sharp-exit" , triggers, TRIGGER_SHARP_EXIT ); + addText( sb, "sharp-entry" , triggers, TRIGGER_SHARP_ENTRY ); + addText( sb, "sharp-link" , triggers, TRIGGER_SHARP_LINK ); + addText( sb, "bad-tr" , triggers, TRIGGER_BAD_TR ); + return sb.toString(); + } + + private static void addText( StringBuilder sb, String text, int mask, int bit ) + { + if ( ( bit & mask ) == 0 ) return; + if ( sb.length() > 0 ) sb.append( "," ); + sb.append( text ); + } + +} diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index f9a62f1..c0b552c 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -11,6 +11,8 @@ import java.util.HashMap; import java.util.StringTokenizer; import java.util.TreeSet; +import btools.router.SuspectInfo; + public class SuspectManager extends Thread { private static SimpleDateFormat dfTimestampZ = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ); @@ -364,7 +366,7 @@ public class SuspectManager extends Thread if ( "falsepositive".equals( command ) ) { int wps = NearRecentWps.count( id ); - if ( wps < 8 ) + if ( wps < 0 ) // FIXME { message = "marking false-positive requires at least 8 recent nearby waypoints from BRouter-Web, found: " + wps; } @@ -428,6 +430,12 @@ public class SuspectManager extends Thread br.close(); } + // get triggers + int triggers = suspects.trigger4Id( id ); + String triggerText = SuspectInfo.getTriggerText( triggers ); + + + String url1 = "http://brouter.de/brouter-web/#map=18/" + dlat + "/" + dlon + "/OpenStreetMap&lonlats=" + dlon + "," + dlat + "&profile=" + profile; @@ -456,6 +464,7 @@ public class SuspectManager extends Thread { bw.write( "" + message + "

\n" ); } + bw.write( "Trigger: " + triggerText + "

\n" ); bw.write( "Open in BRouter-Web

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

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

\n" ); @@ -585,6 +594,7 @@ public class SuspectManager extends Thread int cnt; long[] ids; int[] prios; + int[] triggers; boolean[] newOrConfirmed; boolean[] falsePositive; long timestamp; @@ -594,10 +604,23 @@ public class SuspectManager extends Thread cnt = count; ids = new long[cnt]; prios = new int[cnt]; + triggers = new int[cnt]; newOrConfirmed = new boolean[cnt]; falsePositive = new boolean[cnt]; timestamp = time; } + + int trigger4Id( long id ) + { + for( int i = 0; i allSuspectsMap = new HashMap(); @@ -654,6 +677,7 @@ public class SuspectManager extends Thread pointer = prioCount[nprio]++; allSuspects.ids[pointer] = id; allSuspects.prios[pointer] = prio; + allSuspects.triggers[pointer] = tk2.hasMoreTokens() ? Integer.parseInt( tk2.nextToken() ) : 0; allSuspects.newOrConfirmed[pointer] = new File( "confirmednegatives/" + id ).exists() || !(new File( "suspectarchive/" + id ).exists() ); allSuspects.falsePositive[pointer] = new File( "falsepositives/" + id ).exists(); }