osmoscope/brouter_suspects integration
This commit is contained in:
parent
0ca83f5bfc
commit
5ba717bcbb
2 changed files with 117 additions and 26 deletions
|
@ -173,7 +173,7 @@ public class RouteServer extends Thread
|
||||||
}
|
}
|
||||||
else if ( url.startsWith( "/brouter/suspects" ) )
|
else if ( url.startsWith( "/brouter/suspects" ) )
|
||||||
{
|
{
|
||||||
writeHttpHeader(bw, "text/html");
|
writeHttpHeader(bw, url.endsWith( ".json" ) ? "application/json" : "text/html");
|
||||||
SuspectManager.process( url, bw );
|
SuspectManager.process( url, bw );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,79 @@ public class SuspectManager extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void newAndConfirmedJson( BufferedWriter bw ) throws IOException
|
||||||
|
{
|
||||||
|
SuspectList suspects = getAllSuspects( new File( "worldsuspects.txt" ) );
|
||||||
|
|
||||||
|
bw.write( "{\n" );
|
||||||
|
bw.write( "\"type\": \"FeatureCollection\",\n" );
|
||||||
|
bw.write( "\"features\": [" );
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
for( int isuspect = 0; isuspect<suspects.cnt; isuspect++ )
|
||||||
|
{
|
||||||
|
long id = suspects.ids[isuspect];
|
||||||
|
if ( !suspects.newOrConfirmed[isuspect] )
|
||||||
|
{
|
||||||
|
continue; // known archived
|
||||||
|
}
|
||||||
|
if ( new File( "falsepositives/" + id ).exists() )
|
||||||
|
{
|
||||||
|
continue; // known false positive
|
||||||
|
}
|
||||||
|
if ( isFixed( id, suspects.timestamp ) )
|
||||||
|
{
|
||||||
|
continue; // known fixed
|
||||||
|
}
|
||||||
|
File confirmedEntry = new File( "confirmednegatives/" + id );
|
||||||
|
String status = "new";
|
||||||
|
if ( confirmedEntry.exists() )
|
||||||
|
{
|
||||||
|
status = "confirmed " + formatAge( confirmedEntry ) + " ago";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( n > 0 )
|
||||||
|
{
|
||||||
|
bw.write( "," );
|
||||||
|
}
|
||||||
|
|
||||||
|
int ilon = (int) ( id >> 32 );
|
||||||
|
int ilat = (int) ( id & 0xffffffff );
|
||||||
|
double dlon = ( ilon - 180000000 ) / 1000000.;
|
||||||
|
double dlat = ( ilat - 90000000 ) / 1000000.;
|
||||||
|
|
||||||
|
int prio = suspects.prios[isuspect];
|
||||||
|
int nprio = ( ( prio + 1 ) / 2 ) * 2; // normalize (no link prios)
|
||||||
|
String level = getLevelDecsription( nprio );
|
||||||
|
|
||||||
|
bw.write( "\n{\n" );
|
||||||
|
bw.write( " \"id\": " + n + ",\n" );
|
||||||
|
bw.write( " \"type\": \"Feature\",\n" );
|
||||||
|
bw.write( " \"properties\": {\n" );
|
||||||
|
bw.write( " \"issue_id\": " + id + ",\n" );
|
||||||
|
bw.write( " \"Status\": \"" + status + "\",\n" );
|
||||||
|
bw.write( " \"Level\": \"" + level + "\"\n" );
|
||||||
|
bw.write( " },\n" );
|
||||||
|
bw.write( " \"geometry\": {\n" );
|
||||||
|
bw.write( " \"type\": \"Point\",\n" );
|
||||||
|
bw.write( " \"coordinates\": [\n" );
|
||||||
|
bw.write( " " + dlon + ",\n" );
|
||||||
|
bw.write( " " + dlat + "\n" );
|
||||||
|
bw.write( " ]\n" );
|
||||||
|
bw.write( " }\n" );
|
||||||
|
bw.write( "}" );
|
||||||
|
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
bw.write( "\n ]\n" );
|
||||||
|
bw.write( "}\n" );
|
||||||
|
bw.flush();
|
||||||
|
}
|
||||||
|
|
||||||
public static void process( String url, BufferedWriter bw ) throws IOException
|
public static void process( String url, BufferedWriter bw ) throws IOException
|
||||||
{
|
{
|
||||||
bw.write( "<html><body>\n" );
|
|
||||||
bw.write( "BRouter suspect manager. <a href=\"http://brouter.de/brouter/suspect_manager_help.html\">Help</a><br><br>\n" );
|
|
||||||
|
|
||||||
StringTokenizer tk = new StringTokenizer( url, "/" );
|
StringTokenizer tk = new StringTokenizer( url, "/" );
|
||||||
tk.nextToken();
|
tk.nextToken();
|
||||||
tk.nextToken();
|
tk.nextToken();
|
||||||
|
@ -71,7 +139,7 @@ public class SuspectManager extends Thread
|
||||||
while ( tk.hasMoreTokens() )
|
while ( tk.hasMoreTokens() )
|
||||||
{
|
{
|
||||||
String c = tk.nextToken();
|
String c = tk.nextToken();
|
||||||
if ( "all".equals( c ) || "new".equals( c ) || "confirmed".equals( c ) )
|
if ( "all".equals( c ) || "new".equals( c ) || "confirmed".equals( c ) || "newandconfirmed.json".equals( c ) )
|
||||||
{
|
{
|
||||||
filter = c;
|
filter = c;
|
||||||
break;
|
break;
|
||||||
|
@ -79,6 +147,15 @@ public class SuspectManager extends Thread
|
||||||
country += "/" + c;
|
country += "/" + c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( "newandconfirmed.json".equals( filter ) )
|
||||||
|
{
|
||||||
|
newAndConfirmedJson( bw );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bw.write( "<html><body>\n" );
|
||||||
|
bw.write( "BRouter suspect manager. <a href=\"http://brouter.de/brouter/suspect_manager_help.html\">Help</a><br><br>\n" );
|
||||||
|
|
||||||
if ( filter == null ) // generate country list
|
if ( filter == null ) // generate country list
|
||||||
{
|
{
|
||||||
bw.write( "<table>\n" );
|
bw.write( "<table>\n" );
|
||||||
|
@ -113,16 +190,19 @@ public class SuspectManager extends Thread
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File polyFile = new File( "worldpolys" + country + ".poly" );
|
Area polygon = null;
|
||||||
if ( !polyFile.exists() )
|
if ( !"/world".equals( country ) )
|
||||||
{
|
{
|
||||||
bw.write( "polygon file for country '" + country + "' not found\n" );
|
File polyFile = new File( "worldpolys" + country + ".poly" );
|
||||||
bw.write( "</body></html>\n" );
|
if ( !polyFile.exists() )
|
||||||
bw.flush();
|
{
|
||||||
return;
|
bw.write( "polygon file for country '" + country + "' not found\n" );
|
||||||
|
bw.write( "</body></html>\n" );
|
||||||
|
bw.flush();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
polygon = new Area( polyFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
Area polygon = new Area( polyFile );
|
|
||||||
|
|
||||||
File suspectFile = new File( "worldsuspects.txt" );
|
File suspectFile = new File( "worldsuspects.txt" );
|
||||||
if ( !suspectFile.exists() )
|
if ( !suspectFile.exists() )
|
||||||
|
@ -159,7 +239,7 @@ public class SuspectManager extends Thread
|
||||||
{
|
{
|
||||||
id = suspects.ids[isuspect];
|
id = suspects.ids[isuspect];
|
||||||
|
|
||||||
if ( !polygon.isInBoundingBox( id ) )
|
if ( polygon != null && !polygon.isInBoundingBox( id ) )
|
||||||
{
|
{
|
||||||
continue; // not in selected polygon (pre-check)
|
continue; // not in selected polygon (pre-check)
|
||||||
}
|
}
|
||||||
|
@ -186,7 +266,7 @@ public class SuspectManager extends Thread
|
||||||
continue; // that would be under current suspects
|
continue; // that would be under current suspects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !polygon.isInArea( id ) )
|
if ( polygon != null && !polygon.isInArea( id ) )
|
||||||
{
|
{
|
||||||
continue; // not in selected polygon
|
continue; // not in selected polygon
|
||||||
}
|
}
|
||||||
|
@ -220,6 +300,7 @@ public class SuspectManager extends Thread
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new File( "falsepositives/" + id ).createNewFile();
|
new File( "falsepositives/" + id ).createNewFile();
|
||||||
|
message = "Marked issue " + id + " as false-positive";
|
||||||
id = 0L;
|
id = 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,22 +323,19 @@ public class SuspectManager extends Thread
|
||||||
{
|
{
|
||||||
fixedMarker.createNewFile();
|
fixedMarker.createNewFile();
|
||||||
}
|
}
|
||||||
id = 0L;
|
|
||||||
|
|
||||||
int hideDays = 0;
|
int hideDays = 0;
|
||||||
if ( tk.hasMoreTokens() )
|
if ( tk.hasMoreTokens() )
|
||||||
{
|
{
|
||||||
String param = tk.nextToken();
|
String param = tk.nextToken();
|
||||||
hideDays = Integer.parseInt( param ); // hiding, not fixing
|
hideDays = Integer.parseInt( param ); // hiding, not fixing
|
||||||
|
message = "Hide issue " + id + " for " + hideDays + " days";
|
||||||
}
|
}
|
||||||
else // touch the confirmed entry when marking fixed
|
else
|
||||||
{
|
{
|
||||||
File confirmedEntry = new File( "confirmednegatives/" + id );
|
message = "Marked issue " + id + " as fixed";
|
||||||
if ( confirmedEntry.exists() )
|
|
||||||
{
|
|
||||||
confirmedEntry.setLastModified( System.currentTimeMillis() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
id = 0L;
|
||||||
fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L );
|
fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,9 +418,16 @@ public class SuspectManager extends Thread
|
||||||
{
|
{
|
||||||
bw.write( "<a href=\"/brouter/suspects" + countryId + "/confirm\">mark as a confirmed issue</a><br><br>\n" );
|
bw.write( "<a href=\"/brouter/suspects" + countryId + "/confirm\">mark as a confirmed issue</a><br><br>\n" );
|
||||||
}
|
}
|
||||||
bw.write( "<br><br><a href=\"/brouter/suspects" + country + "/" + filter + "\">back to issue list</a><br><br>\n" );
|
if ( polygon != null )
|
||||||
|
{
|
||||||
|
bw.write( "<br><br><a href=\"/brouter/suspects" + country + "/" + filter + "\">back to issue list</a><br><br>\n" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( polygon == null )
|
||||||
|
{
|
||||||
|
bw.write( message + "<br>\n" );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bw.write( filter + " suspect list for " + country + "\n" );
|
bw.write( filter + " suspect list for " + country + "\n" );
|
||||||
|
@ -363,7 +448,7 @@ public class SuspectManager extends Thread
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( !polygon.isInBoundingBox( id ) )
|
if ( polygon != null && !polygon.isInBoundingBox( id ) )
|
||||||
{
|
{
|
||||||
continue; // not in selected polygon (pre-check)
|
continue; // not in selected polygon (pre-check)
|
||||||
}
|
}
|
||||||
|
@ -383,7 +468,7 @@ public class SuspectManager extends Thread
|
||||||
{
|
{
|
||||||
continue; // showing confirmed suspects only
|
continue; // showing confirmed suspects only
|
||||||
}
|
}
|
||||||
if ( !polygon.isInArea( id ) )
|
if ( polygon != null && !polygon.isInArea( id ) )
|
||||||
{
|
{
|
||||||
continue; // not in selected polygon
|
continue; // not in selected polygon
|
||||||
}
|
}
|
||||||
|
@ -426,6 +511,7 @@ public class SuspectManager extends Thread
|
||||||
int cnt;
|
int cnt;
|
||||||
long[] ids;
|
long[] ids;
|
||||||
int[] prios;
|
int[] prios;
|
||||||
|
boolean[] newOrConfirmed;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
|
|
||||||
SuspectList( int count, long time )
|
SuspectList( int count, long time )
|
||||||
|
@ -433,6 +519,7 @@ public class SuspectManager extends Thread
|
||||||
cnt = count;
|
cnt = count;
|
||||||
ids = new long[cnt];
|
ids = new long[cnt];
|
||||||
prios = new int[cnt];
|
prios = new int[cnt];
|
||||||
|
newOrConfirmed = new boolean[cnt];
|
||||||
timestamp = time;
|
timestamp = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,6 +559,9 @@ public class SuspectManager extends Thread
|
||||||
prioCount[i] = pointer;
|
prioCount[i] = pointer;
|
||||||
pointer += cnt;
|
pointer += cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// sort into suspect list
|
// sort into suspect list
|
||||||
allSuspects = new SuspectList( pointer, suspectFile.lastModified() );
|
allSuspects = new SuspectList( pointer, suspectFile.lastModified() );
|
||||||
|
@ -487,6 +577,7 @@ public class SuspectManager extends Thread
|
||||||
pointer = prioCount[nprio]++;
|
pointer = prioCount[nprio]++;
|
||||||
allSuspects.ids[pointer] = id;
|
allSuspects.ids[pointer] = id;
|
||||||
allSuspects.prios[pointer] = prio;
|
allSuspects.prios[pointer] = prio;
|
||||||
|
allSuspects.newOrConfirmed[pointer] = new File( "confirmednegatives/" + id ).exists() || !(new File( "suspectarchive/" + id ).exists() );
|
||||||
}
|
}
|
||||||
r.close();
|
r.close();
|
||||||
return allSuspects;
|
return allSuspects;
|
||||||
|
|
Loading…
Reference in a new issue