本文整理汇总了Java中com.clearspring.analytics.stream.StreamSummary类的典型用法代码示例。如果您正苦于以下问题:Java StreamSummary类的具体用法?Java StreamSummary怎么用?Java StreamSummary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamSummary类属于com.clearspring.analytics.stream包,在下文中一共展示了StreamSummary类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enter
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void enter(Object value) {
Object[] params = (Object[]) value;
if (m_counter == null) {
m_capacity = (Integer) params[0];
m_topElementCnt = (Integer) params[1];
m_counter = new StreamSummary<Object>(m_capacity.intValue());
}
if (params[2] instanceof Map<?, ?>) {
Map<Object, Long> topCounters = (Map<Object, Long>) params[2];
Set<Object> topKeySet = topCounters.keySet();
for (Object key : topKeySet) {
m_counter.offer(key, topCounters.get(key).intValue());
}
}
}
示例2: readFrom
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
name = in.readString();
size = in.readInt();
int n;
if (in.readBoolean()) {
int capacity = in.readInt();
this.summary = new StreamSummary<>(capacity);
n = in.readInt();
byte[] bytes = new byte[n];
in.read(bytes);
try {
summary.fromBytes(bytes);
} catch (ClassNotFoundException e) {
throw new IOException("Failed to build summary", e);
}
}
n = in.readInt();
this.buckets = new ArrayList<>();
this.bucketsMap = null;
for (int i = 0; i < n; ++i) {
this.buckets.add(Bucket.readFrom(in));
}
// buckets are alreaduy sorted here
}
示例3: testStreamSummaryAccuracy
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Test
public void testStreamSummaryAccuracy() {
StreamSummary<Integer> vs = new StreamSummary<Integer>(5);
Random random = new Random();
random.setSeed(3128);
int maxItems = 5;
for (int i = 0; i < maxItems; i++) {
vs.offer(i, random.nextInt(2000));
}
int fetchTopK = 5;
List<Counter<Integer>> topK = vs.topK(fetchTopK);
for (Counter<Integer> c : topK) {
// System.out.println(c.toString());
}
}
示例4: enter
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Override
public void enter(Object value) {
Object[] values = (Object[]) value;
if (counter == null) {
capacity = (Integer) values[0];
topN = (Integer) values[1];
counter = new StreamSummary<Object>(capacity.intValue());
}
counter.offer(values[2]);
}
示例5: resortTopN
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
private List<String> resortTopN(DruidSpecs druidSpecs, String dimension,
List<Map<String, Object>> listOfResult) {
StreamSummary<String> topN = new StreamSummary<String>(TOPN_MAX);
for (Map<String, Object> map : listOfResult) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> resultList = (List<Map<String, Object>>) map
.get(RESULT);
if (resultList != null) {
for (Map<String, Object> result : resultList) {
Number metricNum = (Number) result.get(druidSpecs.getSort());
;
String dimStr = (String) result.get(dimension);
if (dimStr == null) {
dimStr = "";
}
topN.offer(dimStr, metricNum.intValue());
}
}
}
return FluentIterable.from(topN.topK(druidSpecs.getLimit()))
.transform(new Function<Counter<String>, String>() {
@Override
public String apply(Counter<String> input) {
return input.getItem();
}
}).toList();
}
示例6: enter
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Override
public void enter(Object value) {
Object[] params = (Object[]) value;
if (m_counter == null) {
m_capacity = (Integer) params[0];
m_topElementCnt = (Integer) params[1];
m_counter = new StreamSummary<Object>(m_capacity.intValue());
}
if (splitter == null) {
if (params[3] instanceof Character) {
splitter = Splitter.on((Character) params[3]);
} else if (params[3] instanceof String) {
splitter = Splitter.on((String) params[3]);
}
}
if (params[2] instanceof String && splitter != null) {
Iterable<String> it = splitter.split((String) params[2]);
for (String nested : it) {
m_counter.offer(nested);
}
} else {
m_counter.offer(params[2]);
}
}
示例7: InternalTopK
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
InternalTopK(String name, Number size, StreamSummary<Term> summary) {
super(name);
this.size = size;
this.summary = summary;
this.buckets = new ArrayList<>();
this.bucketsMap = null;
if (this.summary != null) {
List<Counter<Term>> counters = this.summary.topK(this.summary.size());
for (Counter<Term> c : counters) {
this.buckets.add(new TopK.Bucket(c.getItem().term, c.getCount(), c.getItem().bucketOrd, null));
}
this.sortBuckets();
}
}
示例8: buildAggregation
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Override
public InternalAggregation buildAggregation(long owningBucketOrdinal) {
StreamSummary<Term> summary = summaries == null || owningBucketOrdinal >= summaries.size() ? null : summaries.get(owningBucketOrdinal);
InternalTopK topk = new InternalTopK(name, size, summary);
for (TopK.Bucket bucket : topk.getBuckets()) {
bucket.aggregations = bucketAggregations(bucket.bucketOrd);
}
return topk;
}
示例9: testStringBuckets
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Test
public void testStringBuckets() {
StreamSummary<String> vs = new StreamSummary<String>(3);
String[] stream = {"X", "X", "Y", "Z", "A", "B", "C", "X", "X", "A", "C", "A", "A"};
for (String i : stream) {
vs.offer(i, 10);
}
List<Counter<String>> topK = vs.topK(3);
for (Counter<String> c : topK) {
// assertTrue(Arrays.asList("A", "C", "X").contains(c.getItem()));
// System.out.println(c.toString());
}
}
示例10: enter
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Override
public void enter(Object value) {
Object[] params = (Object[]) value;
if(m_counter == null) {
m_capacity = (Integer) params[0];
m_topElementCnt = (Integer) params[1];
m_counter = new StreamSummary<Object>(m_capacity.intValue());
}
m_counter.offer(params[2]);
}
示例11: run
import com.clearspring.analytics.stream.StreamSummary; //导入依赖的package包/类
@Override
public void run() {
m_topElementCounter = new StreamSummary<Object>(1000);
long prevTime = System.currentTimeMillis();
while (!isShutDown()) {
long currTime = System.currentTimeMillis();
if ((currTime - prevTime) > 30000) {
// every 15 secs we will create a new summary
prevTime = currTime;
m_topElementCounter = new StreamSummary<Object>(1000);
}
try {
m_topElementCounter.offer(m_queue.take());
} catch (Throwable e) {
// swallow the exception
}
refreshTopNRegistry();
}
}