From a61ebef90a6b6bef80cb09a5e1f8d42651e4a1ec Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sat, 22 Sep 2018 21:00:11 +0200 Subject: [PATCH] suspect-manager: some fixes --- .../java/btools/server/SuspectManager.java | 89 +++++++++++++------ 1 file changed, 61 insertions(+), 28 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 31ed0c3..926f942 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -24,7 +24,11 @@ public class SuspectManager extends Thread private static String formatAge( File f ) { - long age = System.currentTimeMillis() - f.lastModified(); + return formatAge( System.currentTimeMillis() - f.lastModified() ); + } + + private static String formatAge( long age ) + { long minutes = age / 60000; if ( minutes < 60 ) { @@ -67,7 +71,7 @@ public class SuspectManager extends Thread while ( tk.hasMoreTokens() ) { String c = tk.nextToken(); - if ( "all".equals( c ) || "new".equals( c ) ) + if ( "all".equals( c ) || "new".equals( c ) || "confirmed".equals( c ) ) { filter = c; break; @@ -93,6 +97,7 @@ public class SuspectManager extends Thread { String url2 = "/brouter/suspects" + country + "/" + c; String linkNew = " new "; + String linkCnf = " confirmed "; String linkAll = " all "; String linkSub = ""; @@ -100,7 +105,7 @@ public class SuspectManager extends Thread { linkSub = " sub-regions "; } - bw.write( "" + c + "" + linkNew + linkAll + linkSub + "\n" ); + bw.write( "" + c + "" + linkNew + linkCnf + linkAll + linkSub + "\n" ); } bw.write( "\n" ); bw.write( "\n" ); @@ -127,6 +132,7 @@ public class SuspectManager extends Thread bw.flush(); return; } + SuspectList suspects = getAllSuspects( suspectFile ); boolean showWatchList = false; if ( tk.hasMoreTokens() ) @@ -146,8 +152,9 @@ public class SuspectManager extends Thread { bw.write( "watchlist for " + country + "\n" ); bw.write( "
back to country list

\n" ); + + long timeNow = System.currentTimeMillis(); - SuspectList suspects = getAllSuspects( suspectFile ); for( int isuspect = 0; isuspect suspects.timestamp ) + { + continue; // that would be under current suspects + } } if ( !polygon.isInArea( id ) ) { continue; // not in selected polygon } + String countryId = country + "/" + filter + "/" + id; - String hint = "   confirmed " + formatAge( confirmedEntry ) + " ago"; + String dueTime = hideTime < 0 ? "(asap)" : formatAge( hideTime + 43200000 ); + String hint = "   due in " + dueTime; int ilon = (int) ( id >> 32 ); int ilat = (int) ( id & 0xffffffff ); double dlon = ( ilon - 180000000 ) / 1000000.; @@ -230,8 +248,15 @@ public class SuspectManager extends Thread if ( tk.hasMoreTokens() ) { String param = tk.nextToken(); - hideDays = Integer.parseInt( param ); - fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L ); + hideDays = Integer.parseInt( param ); // hiding, not fixing + } + else // touch the confirmed entry when marking fixed + { + File confirmedEntry = new File( "confirmednegatives/" + id ); + if ( confirmedEntry.exists() ) + { + confirmedEntry.setLastModified( System.currentTimeMillis() ); + } } fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L ); } @@ -271,7 +296,7 @@ public class SuspectManager extends Thread 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=" + String url4b = "https://overpass-turbo.eu/?Q=(node(around%3A1%2C%7B%7Bcenter%7D%7D)-%3E.n%3Bway(bn.n)%5Bhighway%5D%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; @@ -286,7 +311,7 @@ public class SuspectManager extends Thread 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 ) ) + if ( isFixed( id, suspects.timestamp ) ) { bw.write( "

back to watchlist

\n" ); } @@ -299,11 +324,17 @@ public class SuspectManager extends Thread 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" ); + bw.write( "hide for: weeks:" ); + bw.write( prefix2 + "/7\">1w" ); + bw.write( prefix2 + "/14\">2w" ); + bw.write( prefix2 + "/21\">3w" ); + bw.write( "     months:" ); + bw.write( prefix2 + "/30\">1m" ); + bw.write( prefix2 + "/61\">2m" ); + bw.write( prefix2 + "/91\">3m" ); + bw.write( prefix2 + "/122\">4m" ); + bw.write( prefix2 + "/152\">5m" ); + bw.write( prefix2 + "/183\">6m

\n" ); } else { @@ -319,7 +350,6 @@ public class SuspectManager extends Thread bw.write( "
back to country list

\n" ); int maxprio = 0; { - SuspectList suspects = getAllSuspects( suspectFile ); for( int isuspect = 0; isuspect suspectFile.lastModified(); + return fixedEntry.exists() && fixedEntry.lastModified() > timestamp; } @@ -392,8 +426,9 @@ public class SuspectManager extends Thread int cnt; long[] ids; int[] prios; + long timestamp; - SuspectList( int count ) + SuspectList( int count, long time ) { cnt = count; ids = new long[cnt]; @@ -403,17 +438,15 @@ public class SuspectManager extends Thread private static SuspectList allSuspects; private static Object allSuspectsSync = new Object(); - private static long allSuspectsTimestamp; private static SuspectList getAllSuspects( File suspectFile ) throws IOException { synchronized( allSuspectsSync ) { - if ( suspectFile.lastModified() == allSuspectsTimestamp ) + if ( allSuspects != null && suspectFile.lastModified() == allSuspects.timestamp ) { return allSuspects; } - allSuspectsTimestamp = suspectFile.lastModified(); // count prios int[] prioCount = new int[100]; @@ -440,7 +473,7 @@ public class SuspectManager extends Thread } // sort into suspect list - allSuspects = new SuspectList( pointer ); + allSuspects = new SuspectList( pointer, suspectFile.lastModified() ); r = new BufferedReader( new FileReader( suspectFile ) ); for ( ;; ) {