Пример #1
0
  /**
   * Test choosing the "closest" event to associate a product to based on the lat, lon, and
   * eventTime values. This method creates a product with some lat, lon and time values then it
   * creates 3 events whose parameters only differ slightly from the product. It then chooses the
   * event whose Euclidean distance is lowest.
   *
   * @see #createEvent(BigDecimal, BigDecimal, Date)
   * @see gov.usgs.earthquake.indexer.DefaultAssociator#chooseMostSimilar(ProductSummary, List)
   */
  @Test
  public void testChooseMostSimilar() {
    Date d = new Date();
    double lat = 10.0;
    double lon = 10.0;

    // Make a product with location and time
    ProductSummary product = new ProductSummary();
    product.setEventLatitude(new BigDecimal(lat));
    product.setEventLongitude(new BigDecimal(lon));
    product.setEventTime(d);

    // Make 3 events with similar locations and times
    Event e1 =
        createEvent(
            "test",
            "1",
            new BigDecimal(lat + 0.1),
            new BigDecimal(lon + 0.1),
            new Date(d.getTime() + 10));

    Event e2 =
        createEvent(
            "test",
            "2",
            new BigDecimal(lat - 0.5),
            new BigDecimal(lon),
            new Date(d.getTime() + 50));

    Event e3 = createEvent("test", "3", new BigDecimal(lat + 1), new BigDecimal(lon + 1), d);

    // Now add the events to a list, and find the most similar
    List<Event> events = new ArrayList<Event>();
    events.add(e1);
    events.add(e2);
    events.add(e3);

    // Calculate which event is most similar to the product
    DefaultAssociator associator = new DefaultAssociator();
    Event mostSimilar = associator.chooseMostSimilar(product, events);
    Assert.assertEquals(e1, mostSimilar);
  }