/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 799 by torben, Mon Jun 7 08:55:34 2010 UTC revision 800 by torben, Mon Jun 7 10:02:26 2010 UTC
# Line 5  import java.io.ByteArrayOutputStream; Line 5  import java.io.ByteArrayOutputStream;
5  import java.io.FileInputStream;  import java.io.FileInputStream;
6  import java.io.IOException;  import java.io.IOException;
7  import java.io.InputStreamReader;  import java.io.InputStreamReader;
8    import java.text.ParseException;
9    import java.text.SimpleDateFormat;
10  import java.util.ArrayList;  import java.util.ArrayList;
11    import java.util.Date;
12  import java.util.List;  import java.util.List;
13  import java.util.logging.Level;  import java.util.logging.Level;
14  import java.util.logging.Logger;  import java.util.logging.Logger;
# Line 27  public class RequestPlotter extends Http Line 30  public class RequestPlotter extends Http
30    
31          class RequestPosition {          class RequestPosition {
32                  public String ip;                  public String ip;
33                  public String time;                  public Date time;
34                  public String lat;                  public String lat;
35                  public String lng;                  public String lng;
36          }          }
# Line 41  public class RequestPlotter extends Http Line 44  public class RequestPlotter extends Http
44                          FileInputStream fis = new FileInputStream("/var/log/apache2/app_access.log");                          FileInputStream fis = new FileInputStream("/var/log/apache2/app_access.log");
45                          BufferedReader in = new BufferedReader( new InputStreamReader(fis) );                          BufferedReader in = new BufferedReader( new InputStreamReader(fis) );
46    
47                            SimpleDateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss");
48    
49                          String line;                          String line;
50                          while ( (line=in.readLine()) != null) {                          while ( (line=in.readLine()) != null) {
51                                  if (line.indexOf("LocateStation") == -1 ){                                  if (line.indexOf("LocateStation") == -1 ){
# Line 54  public class RequestPlotter extends Http Line 59  public class RequestPlotter extends Http
59    
60                                  String toks[] = line.split(" ");                                  String toks[] = line.split(" ");
61                                  pos.ip = toks[0];                                  pos.ip = toks[0];
62                                  pos.time = toks[3].replace("[", "");  
63                                    pos.time = df.parse( toks[3].replace("[", "") );
64    
65                                  String argpart = toks[6].split("\\?")[1];                                  String argpart = toks[6].split("\\?")[1];
66    
67                                  String args[] = argpart.split("&");                                  String args[] = argpart.split("&");
68    
69                                  pos.lat = args[0].split("=")[1];                                  pos.lat = args[0].split("=")[1];
70                                  pos.lng = args[1].split("=")[1];                                  pos.lng = args[1].split("=")[1];
71                                    
72                                  positions.add(pos);                                  positions.add(pos);
73                          }                          }
74                    } catch (ParseException pe) {
75                            log.log(Level.SEVERE, "parseException", pe);
76                            throw new IOException(pe);
77                  } catch (IOException e) {                  } catch (IOException e) {
78                          log.log(Level.SEVERE, "getKml()", e);                          log.log(Level.SEVERE, "getKml()", e);
79                          throw e;                          throw e;
# Line 78  public class RequestPlotter extends Http Line 88  public class RequestPlotter extends Http
88                  sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );                  sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
89                  sb.append( "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" );                  sb.append( "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" );
90                  sb.append( "<Document>\n" );                              sb.append( "<Document>\n" );            
91                    
92                    
93                    sb.append( " <Style id=\"red\">\n" );
94                    sb.append( "  <IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/paddle/red-circle.png</href></Icon></IconStyle>\n" );
95                    sb.append( " </Style>\n");
96    
97                    sb.append( " <Style id=\"yellow\">\n" );
98                    sb.append( "  <IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/paddle/ylw-circle.png</href></Icon></IconStyle>\n" );
99                    sb.append( " </Style>\n" );
100    
101                    sb.append( " <Style id=\"green\">\n" );
102                    sb.append( "  <IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/paddle/grn-circle.png</href></Icon></IconStyle>\n" );
103                    sb.append( " </Style>\n\n" );          
104    
105    
106    
107    
108                    Date now = new Date();
109                  for(RequestPosition current : list) {                  for(RequestPosition current : list) {
110                            
111                            String style;
112                            long timediff = now.getTime() - current.time.getTime();
113                            
114                            if ( timediff < (3*60*60*1000) ) {
115                                    style = "#red";
116                            } else if ( timediff < (24*60*60*1000)) {
117                                    style = "#yellow";
118                            } else {
119                                    style = "#green";
120                            }
121                            
122                          sb.append( " <Placemark>\n" );                          sb.append( " <Placemark>\n" );
123                            sb.append( "  <styleUrl>" + style + "</styleUrl>\n" );
124                          sb.append( "  <description>IP=" + current.ip + "  Time=" + current.time + "</description>\n" );                          sb.append( "  <description>IP=" + current.ip + "  Time=" + current.time + "</description>\n" );
125                          sb.append( "  <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" );                          sb.append( "  <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" );
126                          sb.append( " </Placemark>\n" );                                          sb.append( " </Placemark>\n" );                

Legend:
Removed from v.799  
changed lines
  Added in v.800

  ViewVC Help
Powered by ViewVC 1.1.20