--- android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java 2010/06/07 08:55:34 799 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java 2010/06/07 10:02:26 800 @@ -5,7 +5,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -27,7 +30,7 @@ class RequestPosition { public String ip; - public String time; + public Date time; public String lat; public String lng; } @@ -41,6 +44,8 @@ FileInputStream fis = new FileInputStream("/var/log/apache2/app_access.log"); BufferedReader in = new BufferedReader( new InputStreamReader(fis) ); + SimpleDateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss"); + String line; while ( (line=in.readLine()) != null) { if (line.indexOf("LocateStation") == -1 ){ @@ -54,16 +59,21 @@ String toks[] = line.split(" "); pos.ip = toks[0]; - pos.time = toks[3].replace("[", ""); + + pos.time = df.parse( toks[3].replace("[", "") ); + String argpart = toks[6].split("\\?")[1]; String args[] = argpart.split("&"); pos.lat = args[0].split("=")[1]; pos.lng = args[1].split("=")[1]; - + positions.add(pos); } + } catch (ParseException pe) { + log.log(Level.SEVERE, "parseException", pe); + throw new IOException(pe); } catch (IOException e) { log.log(Level.SEVERE, "getKml()", e); throw e; @@ -78,9 +88,39 @@ sb.append( "\n" ); sb.append( "\n" ); sb.append( "\n" ); + + + sb.append( " \n"); + + sb.append( " \n" ); + sb.append( " \n\n" ); + + + + + Date now = new Date(); for(RequestPosition current : list) { + + String style; + long timediff = now.getTime() - current.time.getTime(); + + if ( timediff < (3*60*60*1000) ) { + style = "#red"; + } else if ( timediff < (24*60*60*1000)) { + style = "#yellow"; + } else { + style = "#green"; + } + sb.append( " \n" ); + sb.append( " " + style + "\n" ); sb.append( " IP=" + current.ip + " Time=" + current.time + "\n" ); sb.append( " " + current.lng + "," + current.lat + ",0\n" ); sb.append( " \n" );