Exemplo n.º 1
0
  private void fillUpData(Date from, String device, String type)
      throws MongoException, PersistenceException {

    metricsSerie = new MetricSerieDB();
    MetricSerie serie = metricsSerie.getMetricSerie(device, type, true);
    System.out.println("Metric serie: " + serie);

    // Date nextDate = DateUtility.getHourDate(DateUtility.getNextHour(from));
    Date nextDate = DateUtility.getHourDate(DateUtility.getNextDay(from));

    while (nextDate.getTime() < new Date().getTime()) {

      Metric metric = new Metric(nextDate, device, type, new Random().nextDouble() * 50 + 50);

      DBObject object = null;

      try {
        object = metrics.insertMetric(metric);
      } catch (PersistenceException e) {
        e.printStackTrace();
        break;
      }

      System.out.println("Inserted: " + object);

      // nextDate = DateUtility.getHourDate(DateUtility.getNextHour(nextDate));
      nextDate = DateUtility.getHourDate(DateUtility.getNextDay(nextDate));
    }
  }
Exemplo n.º 2
0
  public MongoInsertFakeData() throws PersistenceException {

    this.metrics = new MetricDB();

    String deviceToken = "device";
    String measureType = "metrics";

    // Clean all (fake data)
    metrics.dropDataOfDevice(null, null);
    // metrics.dropDataOfDevice(deviceToken, measureType);

    // Last date found
    DBObject object = metrics.getLastMetric(deviceToken, measureType);

    System.out.println("Last metric found: " + object);

    Metric metric = Transformer.transformDBObjectInMetric(object);

    System.out.println("Last metric found: " + metric);

    Date lastDate = null;

    if (metric != null) lastDate = metric.getDate();

    System.out.println("Last date found: " + lastDate);

    if (lastDate == null) lastDate = DateUtility.getHourDate(DateUtility.getPastYear(new Date()));

    fillUpData(lastDate, deviceToken, measureType);

    dumpAllData(deviceToken, measureType);

    System.out.println("Metric: '" + deviceToken + "', Type: '" + measureType + "'");
    System.out.println(
        "First date: "
            + new Date((Long) metrics.getFirstMetric(deviceToken, measureType).get("date")));
    System.out.println(
        "Last date: "
            + new Date((Long) metrics.getLastMetric(deviceToken, measureType).get("date")));
  }