public void updateGraph( List<ClusterRectangle> clusterRectangles, List<Period> indoorPeriods, String android_id) { // Graph Update // Make Graph Configuration conf = new BaseConfiguration(); conf.setProperty("storage.backend", "cassandra"); conf.setProperty("storage.hostname", "127.0.0.1"); TitanGraph g = TitanFactory.open(conf); // Get Smartphone Vertex Vertex v = TitanHelper.getVertex(g, "android_id", android_id); if (v == null) { v = g.addVertex(null); v.setProperty("android_id", android_id); v.setProperty("ltype", "Object"); } // Process Outdoor Cluster for (int i = 0; i < clusterRectangles.size(); i++) { ClusterRectangle clusterRectangle = clusterRectangles.get(i); double minLon = clusterRectangle.getMinLon(); double minLat = clusterRectangle.getMinLat(); double maxLon = clusterRectangle.getMaxLon(); double maxLat = clusterRectangle.getMaxLat(); for (int j = 0; j < clusterRectangle.getPeriods().size(); j++) { Vertex place = g.addVertex(null); place.setProperty("ltype", "Place.outdoor"); place.setProperty("minLon", minLon); place.setProperty("minLat", minLat); place.setProperty("maxLon", maxLon); place.setProperty("maxLat", maxLat); Period period = clusterRectangle.getPeriods().get(j); long from = period.getFrom() * 1000; long to = period.getTo() * 1000; Edge isLocatedIn = g.addEdge(null, v, place, "isLocatedIn"); Edge isContaining = g.addEdge(null, place, v, "isContaining"); isLocatedIn.setProperty("from", from); isLocatedIn.setProperty("to", to); isContaining.setProperty("from", from); isContaining.setProperty("to", to); } } // Process Indoor Points for (int i = 0; i < indoorPeriods.size(); i++) { Period indoor = indoorPeriods.get(i); Vertex place = g.addVertex(null); place.setProperty("ltype", "Place.indoor"); place.setProperty("longitude", indoor.getLongitude()); place.setProperty("latitude", indoor.getLatitude()); place.setProperty("from", indoor.getFrom()); place.setProperty("to", indoor.getTo()); } g.commit(); g.shutdown(); }
/** * @param string * @param indoorPeriods */ private void makeRIndoorPoint(String path, List<Period> indoorPeriods) { String outStr = "lon\tlat\n"; for (int i = 0; i < indoorPeriods.size(); i++) { Period period = indoorPeriods.get(i); double longitude = period.getLongitude(); double latitude = period.getLatitude(); outStr += "\t" + longitude + "\t" + latitude + "\n"; } try { BufferedWriter writer = new BufferedWriter(new FileWriter(path)); writer.write(outStr); writer.close(); } catch (Exception ex) { } }
@SuppressWarnings("unused") public void doVisualization( List<String> clusterMembers, String manipulatedString, List<Period> indoorPeriods, HttpServletRequest request) throws IOException { System.out.println(" [Location Clusterer] : Make Regions for Clusters............."); List<ClusterRectangle> clusterRectangles = new ArrayList<ClusterRectangle>(); for (int i = 0; i < clusterMembers.size(); i++) { makeRLocationData("/home/jack/RTest/Data" + i + ".txt", clusterMembers.get(i)); makeRLocationClusters("/home/jack/RTest/Cluster" + i + ".txt", clusterMembers.get(i)); } makeRIndoorPoint("/home/jack/RTest/Indoor.txt", indoorPeriods); System.out.println( " [Location Clusterer] : [Debug] Getting Time periods for each cluster............."); for (int i = 0; i < clusterRectangles.size(); i++) { ClusterRectangle cr = clusterRectangles.get(i); List<Period> ps = cr.getPeriods(); System.out.println(cr.toString()); for (int j = 0; j < ps.size(); j++) { Period p = ps.get(j); System.out.print("\t"); System.out.println(p.toString()); } } System.out.println(" [Location Clusterer] : Make R Script for Visualization............."); int zoom = 14; if (request.getParameter("zoom") != null) zoom = Integer.parseInt(request.getParameter("zoom")); makeRScript("/home/jack/RTest/Script.txt", manipulatedString, clusterMembers, zoom); System.out.println(" [Location Clusterer] : Invoke R Command............."); String[] cmd = new String[] {"R", "CMD", "BATCH", "/home/jack/RTest/Script.txt"}; Process process = new ProcessBuilder(cmd).start(); }
public List<Period> getIndoorData(String manipulatedString) { /* * 127.36504046 36.3742216 9.0 1407381330 * 127.36506211 36.37423924 11.0 1407381340 * 127.36496859 36.37421911 11.0 1407381350 * 127.3648429 36.37416071 11.0 1407381360 * 127.36469597 36.37409721 11.0 1407381370 */ List<Period> indoorPeriods = new ArrayList<Period>(); String[] lines = manipulatedString.split("\n"); boolean isIndoorStart = false; Period period = new Period(); long lastPeriod = 0; for (int i = 0; i < lines.length; i++) { String line = lines[i]; String[] elements = line.split("\t"); if (elements.length == 4) { int numSatellites = (int) Double.parseDouble(elements[2]); if (isIndoorStart == false && numSatellites < 6) { isIndoorStart = true; period = new Period(); period.setLongitude(Double.parseDouble(elements[0])); period.setLatitude(Double.parseDouble(elements[1])); period.setFrom(Long.parseLong(elements[3])); } else if (isIndoorStart == false && numSatellites != 0) { // Keep going } else if (isIndoorStart == true && numSatellites == 0) { // Keep going } else if (isIndoorStart == true && numSatellites >= 6) { isIndoorStart = false; period.setTo(Long.parseLong(elements[3])); // We assume that Staying a place over 10 minutes is indoor if (period.getTo() - period.getFrom() >= 600) { // System.out.println(" [Location Clusterer] : [DEBUG] Success " + (period.getTo() - // period.getFrom())); indoorPeriods.add(period); } else { // System.out.println(" [Location Clusterer] : [DEBUG] Fail " + (period.getTo() - // period.getFrom())); } } lastPeriod = Long.parseLong(elements[3]); } } if (isIndoorStart == true) { period.setTo(lastPeriod); // We assume that Staying a place over 10 minutes is indoor if (period.getTo() - period.getFrom() >= 600) { // System.out.println(" [Location Clusterer] : [DEBUG] Success " + (period.getTo() - // period.getFrom())); indoorPeriods.add(period); } else { // System.out.println(" [Location Clusterer] : [DEBUG] Fail " + (period.getTo() - // period.getFrom())); } } return indoorPeriods; }