DistortionGroupManagement { public <T> int retainBestGroups( final AnalyticItemWrapperFactory<T> itemWrapperFactory, final String dataTypeId, final String indexId, final String batchId, final int level) { try { final Map<String, DistortionGroup> groupDistortions = new HashMap<>(); try (CloseableIterator<DistortionEntry> it = (CloseableIterator) dataStore.query( QueryBuilder.newBuilder().addTypeName( DistortionDataAdapter.ADAPTER_TYPE_NAME).indexName( DISTORTIONS_INDEX.getName()).constraints( new BatchIdQuery(batchId)).build())) { while (it.hasNext()) { final DistortionEntry entry = it.next(); final String groupID = entry.getGroupId(); final Integer clusterCount = entry.getClusterCount(); final Double distortion = entry.getDistortionValue(); DistortionGroup grp = groupDistortions.get(groupID); if (grp == null) { grp = new DistortionGroup(groupID); groupDistortions.put(groupID, grp); } grp.addPair(clusterCount, distortion); } } final CentroidManagerGeoWave<T> centroidManager = new CentroidManagerGeoWave<>( dataStore, indexStore, adapterStore, itemWrapperFactory, dataTypeId, internalAdapterStore.getAdapterId(dataTypeId), indexId, batchId, level); for (final DistortionGroup grp : groupDistortions.values()) { final int optimalK = grp.bestCount(); final String kbatchId = batchId + "_" + optimalK; centroidManager.transferBatch(kbatchId, grp.getGroupID()); } } catch (final RuntimeException ex) { throw ex; } catch (final Exception ex) { LOGGER.error("Cannot determine groups for batch", ex); return 1; } return 0; } DistortionGroupManagement(final DataStorePluginOptions dataStoreOptions); int retainBestGroups(
      final AnalyticItemWrapperFactory<T> itemWrapperFactory,
      final String dataTypeId,
      final String indexId,
      final String batchId,
      final int level); static final Index DISTORTIONS_INDEX; static final String[] DISTORTIONS_INDEX_ARRAY; }
@Test public void test() throws IOException { final DistortionGroupManagement distortionGroupManagement = new DistortionGroupManagement(storePluginOptions); distortionGroupManagement.retainBestGroups( new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), index.getName(), "b1", 1); final CentroidManagerGeoWave<SimpleFeature> centroidManager = new CentroidManagerGeoWave<>( storePluginOptions.createDataStore(), storePluginOptions.createIndexStore(), storePluginOptions.createAdapterStore(), new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), storePluginOptions.createInternalAdapterStore().getAdapterId(adapter.getTypeName()), index.getName(), "b1", 1); final List<String> groups = centroidManager.getAllCentroidGroups(); assertEquals(2, groups.size()); final boolean groupFound[] = new boolean[2]; for (final String grpId : groups) { final List<AnalyticItemWrapper<SimpleFeature>> items = centroidManager.getCentroidsForGroup(grpId); assertEquals(2, items.size()); if ("grp1".equals(grpId)) { groupFound[0] = true; assertTrue("pearl".equals(items.get(0).getName()) || "roxy".equals(items.get(0).getName())); } else if ("grp2".equals(grpId)) { groupFound[1] = true; assertTrue( "chip".equals(items.get(0).getName()) || "bamm-bamm".equals(items.get(0).getName())); } } int c = 0; for (final boolean gf : groupFound) { c += (gf ? 1 : 0); } assertEquals(2, c); }