suspect-manager: display trigger-list

This commit is contained in:
Arndt Brenschede 2022-02-12 21:48:26 +01:00
parent 182426a4a2
commit 96ab3bf5c2
2 changed files with 91 additions and 1 deletions

View file

@ -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<Long,SuspectInfo> 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 );
}
}

View file

@ -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( "<strong>" + message + "</strong><br><br>\n" );
}
bw.write( "Trigger: " + triggerText + "<br><br>\n" );
bw.write( "<a href=\"" + url1 + "\">Open in BRouter-Web</a><br><br>\n" );
bw.write( "<a href=\"" + url2 + "\">Open in OpenStreetmap</a><br><br>\n" );
bw.write( "<a href=\"" + url3 + "\">Open in JOSM (via remote control)</a><br><br>\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<cnt; i++ )
{
if ( id == ids[i] )
{
return triggers[i];
}
}
return 0;
}
}
private static HashMap<String,SuspectList> allSuspectsMap = new HashMap<String,SuspectList>();
@ -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();
}