public static MultiVariatePieceWiseLinearFunction createSenseSleepFunctionVerbose(
      ScenarioProperties scenario, List<SensorProperties> sensorProperties) {

    NCube domain = createDomain(sensorProperties, scenario);

    // max(0, min(x1 + l1, x2 + l2) - max(x1, x2))

    MultiVariatePieceWiseLinearFunction zero =
        MultiVariatePieceWiseLinearFunctionUtilities.createZeroFunction(domain);

    double l = scenario.getScheduleIntervalLength();

    StopWatch watch = new StopWatch();

    watch.start();
    MultiVariatePieceWiseLinearFunction maxStart = createMaxStartFunction(domain);
    watch.stop();
    System.out.println(
        "Created maxStart in "
            + watch.getTime()
            + ". Simplices "
            + maxStart.getPartitioning().getSimplices().size());

    watch.reset();
    watch.start();
    MultiVariatePieceWiseLinearFunction minEnd = createMinEndFunction(domain, sensorProperties);
    watch.stop();
    System.out.println(
        "Created minEnd in "
            + watch.getTime()
            + ". Simplices "
            + minEnd.getPartitioning().getSimplices().size());

    watch.reset();
    watch.start();
    MultiVariatePieceWiseLinearFunction minMinusMax = minEnd.subtract(maxStart);
    watch.stop();
    System.out.println(
        "Created minMinusMax in "
            + watch.getTime()
            + ". Simplices "
            + minMinusMax.getPartitioning().getSimplices().size());

    watch.reset();
    watch.start();
    MultiVariatePieceWiseLinearFunction overlap = minMinusMax.max(zero);
    System.out.println(
        "Created overlap in "
            + watch.getTime()
            + ". Simplices "
            + overlap.getPartitioning().getSimplices().size());

    MultiVariatePieceWiseLinearFunction result = overlap.subtract(l).multiply(-1.0);

    System.out.println("Simplices " + result.getPartitioning().getSimplices().size());

    return result;
  }
 @Override
 public Observable<Void> reset() {
   stopWatch.reset();
   return Observable.just(null);
 }
Esempio n. 3
0
  @Test
  public void testPutQueryDelete() throws ExecutionException, InterruptedException {
    int numItems = 1;
    String x;
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    PerformanceTestObject o = new PerformanceTestObject();
    o.setS1("first to create domain");
    em.persist(o);
    StopWatch stopWatch = new StopWatch();

    String s1a = "attribute1";
    String s2a = "attribute2";
    Future<PerformanceTestObject> lastFuture = null;
    stopWatch.start();
    for (int i = 0; i < numItems; i++) {
      o = new PerformanceTestObject();
      o.setS1(s1a);
      o.setS2(s2a);
      lastFuture = em.persistAsync(o);
    }
    lastFuture.get(); // not 100% accurate, but good enough
    stopWatch.stop();
    System.out.println(
        "puts duration="
            + stopWatch.getTime()
            + ", "
            + em.getTotalOpStats().getPuts()
            + " items put.");

    Thread.sleep(5000);

    stopWatch.reset();
    stopWatch.start();
    Query query = em.createQuery("select o from PerformanceTestObject o");
    List<PerformanceTestObject> resultList = query.getResultList();
    System.out.println("iterating result list...");
    int i = 0;
    for (PerformanceTestObject performanceTestObject : resultList) {

      i++;
      if (i % 100 == 0) {
        System.out.println(i);
      }
    }
    stopWatch.stop();
    System.out.println(
        "query ALL duration="
            + stopWatch.getTime()
            + ", "
            + em.getTotalOpStats().getGets()
            + " items got.");

    stopWatch.reset();
    stopWatch.start();
    System.out.println("Deleting ALL...");
    for (PerformanceTestObject performanceTestObject : resultList) {
      lastFuture = em.removeAsync(o);
    }
    lastFuture.get();
    stopWatch.stop();
    System.out.println(
        "delete duration=" + stopWatch.getTime() + ", " + resultList.size() + " items deleted.");
    System.out.println("sleeping...");
    Thread.sleep(30000);

    em.close();
  }
Esempio n. 4
0
  public void resolveNames(Long batchSize) {
    StopWatch watchForEntireRun = new StopWatch();
    watchForEntireRun.start();
    StopWatch watchForBatch = new StopWatch();
    watchForBatch.start();
    Long count = 0L;

    Index<Node> studyIndex = graphService.index().forNodes("studies");
    IndexHits<Node> studies = studyIndex.query("title", "*");
    for (Node studyNode : studies) {
      final Study study1 = new Study(studyNode);
      final Iterable<Relationship> specimens = study1.getSpecimens();
      for (Relationship collected : specimens) {
        Specimen specimen = new Specimen(collected.getEndNode());
        final Relationship classifiedAs =
            specimen
                .getUnderlyingNode()
                .getSingleRelationship(RelTypes.CLASSIFIED_AS, Direction.OUTGOING);
        if (classifiedAs == null) {
          final Relationship describedAs =
              specimen
                  .getUnderlyingNode()
                  .getSingleRelationship(RelTypes.ORIGINALLY_DESCRIBED_AS, Direction.OUTGOING);
          final TaxonNode describedAsTaxon = new TaxonNode(describedAs.getEndNode());
          try {
            if (taxonFilter.shouldInclude(describedAsTaxon)) {
              TaxonNode resolvedTaxon = taxonIndex.getOrCreateTaxon(describedAsTaxon);
              if (resolvedTaxon != null) {
                specimen.classifyAs(resolvedTaxon);
              }
            }
          } catch (NodeFactoryException e) {
            LOG.warn(
                "failed to create taxon with name ["
                    + describedAsTaxon.getName()
                    + "] and id ["
                    + describedAsTaxon.getExternalId()
                    + "]",
                e);
          } finally {
            count++;
            if (count % batchSize == 0) {
              watchForBatch.stop();
              final long duration = watchForBatch.getTime();
              if (duration > 0) {
                LOG.info(
                    "resolved batch of ["
                        + batchSize
                        + "] names in "
                        + getProgressMsg(batchSize, duration));
              }
              watchForBatch.reset();
              watchForBatch.start();
            }
          }
        }
      }
    }
    studies.close();
    watchForEntireRun.stop();
    LOG.info(
        "resolved [" + count + "] names in " + getProgressMsg(count, watchForEntireRun.getTime()));
  }