Ejemplo n.º 1
0
  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();
  }
Ejemplo n.º 2
0
  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;
  }