List of usage examples for org.apache.commons.lang.mutable MutableDouble doubleValue
public double doubleValue()
From source file:eu.project.ttc.models.Context.java
public double getOccurrences(String coTerm) { MutableDouble occ = occurrences.get(coTerm); return occ == null ? 0.0 : occ.doubleValue(); }
From source file:com.datatorrent.lib.math.SumMap.java
/** * Emits on all ports that are connected. Data is precomputed during process on input port * endWindow just emits it for each key//from w ww .j a va 2 s.c o m * Clears the internal data before return */ @Override public void endWindow() { HashMap<K, V> tuples = new HashMap<K, V>(); HashMap<K, Double> dtuples = new HashMap<K, Double>(); HashMap<K, Integer> ituples = new HashMap<K, Integer>(); HashMap<K, Float> ftuples = new HashMap<K, Float>(); HashMap<K, Long> ltuples = new HashMap<K, Long>(); HashMap<K, Short> stuples = new HashMap<K, Short>(); for (Map.Entry<K, MutableDouble> e : sums.entrySet()) { K key = e.getKey(); MutableDouble val = e.getValue(); tuples.put(key, getValue(val.doubleValue())); dtuples.put(key, val.doubleValue()); ituples.put(key, val.intValue()); ltuples.put(key, val.longValue()); stuples.put(key, val.shortValue()); ftuples.put(key, val.floatValue()); } sum.emit(tuples); sumDouble.emit(dtuples); sumInteger.emit(ituples); sumFloat.emit(ftuples); sumLong.emit(ltuples); sumShort.emit(stuples); clearCache(); }
From source file:com.datatorrent.contrib.frauddetect.AverageAlertingOperator.java
private void processTuple(KeyValPair<MerchantKey, Long> tuple) { MerchantKey merchantKey = tuple.getKey(); MutableDouble lastSma = lastSMAMap.get(tuple.getKey()); long txValue = tuple.getValue(); if (lastSma != null && txValue > lastSma.doubleValue()) { double lastSmaValue = lastSma.doubleValue(); double change = txValue - lastSmaValue; if (change > threshold) { // generate an alert AverageAlertData data = getOutputData(merchantKey, txValue, change, lastSmaValue); alerts.add(data);// ww w. j ava 2s. c om //if (userGenerated) { // if its user generated only the pass it to WebSocket if (merchantKey.merchantType == MerchantTransaction.MerchantType.BRICK_AND_MORTAR) { avgAlertNotificationPort.emit(getOutputData(data, String.format(brickMortarAlertMsg, txValue, change, lastSmaValue, merchantKey.merchantId, merchantKey.terminalId))); } else { // its internet based avgAlertNotificationPort.emit(getOutputData(data, String.format(internetAlertMsg, txValue, change, lastSmaValue, merchantKey.merchantId))); } //} } } }
From source file:com.datatorrent.contrib.frauddetect.AverageAlertingOperator.java
@Override public void endWindow() { for (AverageAlertData data : alerts) { try {/*from w w w .ja v a2 s. co m*/ avgAlertOutputPort.emit(JsonUtils.toJson(data)); } catch (IOException e) { logger.warn("Exception while converting object to JSON", e); } } alerts.clear(); for (Map.Entry<MerchantKey, MutableDouble> entry : currentSMAMap.entrySet()) { MerchantKey key = entry.getKey(); MutableDouble currentSma = entry.getValue(); MutableDouble lastSma = lastSMAMap.get(key); if (lastSma == null) { lastSma = new MutableDouble(currentSma.doubleValue()); lastSMAMap.put(key, lastSma); } else { lastSma.setValue(currentSma.getValue()); } } }
From source file:com.datatorrent.lib.math.SumCountMap.java
/** * Emits on all ports that are connected. Data is precomputed during process * on input port endWindow just emits it for each key Clears the internal data * before return/*from w ww.j a va 2 s. c o m*/ */ @Override public void endWindow() { // Should allow users to send each key as a separate tuple to load balance // This is an aggregate node, so load balancing would most likely not be // needed HashMap<K, V> tuples = new HashMap<K, V>(); HashMap<K, Integer> ctuples = new HashMap<K, Integer>(); HashMap<K, Double> dtuples = new HashMap<K, Double>(); HashMap<K, Integer> ituples = new HashMap<K, Integer>(); HashMap<K, Float> ftuples = new HashMap<K, Float>(); HashMap<K, Long> ltuples = new HashMap<K, Long>(); HashMap<K, Short> stuples = new HashMap<K, Short>(); for (Map.Entry<K, MutableDouble> e : sums.entrySet()) { K key = e.getKey(); MutableDouble val = e.getValue(); tuples.put(key, getValue(val.doubleValue())); dtuples.put(key, val.doubleValue()); ituples.put(key, val.intValue()); ftuples.put(key, val.floatValue()); ltuples.put(key, val.longValue()); stuples.put(key, val.shortValue()); // ctuples.put(key, counts.get(e.getKey()).toInteger()); MutableInt c = counts.get(e.getKey()); if (c != null) { ctuples.put(key, c.toInteger()); } } sum.emit(tuples); sumDouble.emit(dtuples); sumInteger.emit(ituples); sumLong.emit(ltuples); sumShort.emit(stuples); sumFloat.emit(ftuples); count.emit(ctuples); clearCache(); }
From source file:eu.project.ttc.models.Context.java
public String toString() { StringBuilder builder = new StringBuilder(); int index = 0; Map<String, MutableDouble> occurrences = this.sort(); int size = occurrences.size(); for (String key : occurrences.keySet()) { index++;/*from ww w . j a v a 2 s . c o m*/ MutableDouble occ = occurrences.get(key); if (occ == null) { continue; } else { builder.append(key); builder.append('\t'); double value = occ.doubleValue(); builder.append(value); } if (index < size) { builder.append('\n'); } } return builder.toString(); }
From source file:eu.project.ttc.models.Context.java
public void setCoOccurrences(String term, double coOccurrences, int mode) { if (!occurrences.containsKey(term)) occurrences.put(term, new MutableDouble(0.0)); MutableDouble coOcc = occurrences.get(term); if (mode == DEL_MODE) { coOcc.setValue(coOccurrences);//from w w w .ja v a2 s . c o m } else if (mode == ADD_MODE) { coOcc.add(coOccurrences); } else if (mode == MAX_MODE && coOccurrences > coOcc.doubleValue()) { coOcc.setValue(coOccurrences); } else if (mode == MIN_MODE && coOccurrences < coOcc.doubleValue()) { coOcc.setValue(coOccurrences); } }
From source file:com.datatorrent.lib.math.QuotientMap.java
/** * Generates tuples for each key and emits them. Only keys that are in the * denominator are iterated on If the key is only in the numerator, it gets * ignored (cannot do divide by 0) Clears internal data *///ww w. ja va 2 s .c o m @Override public void endWindow() { HashMap<K, Double> tuples = new HashMap<K, Double>(); for (Map.Entry<K, MutableDouble> e : denominators.entrySet()) { MutableDouble nval = numerators.get(e.getKey()); if (nval == null) { tuples.put(e.getKey(), new Double(0.0)); } else { tuples.put(e.getKey(), new Double((nval.doubleValue() / e.getValue().doubleValue()) * mult_by)); } } if (!tuples.isEmpty()) { quotient.emit(tuples); } numerators.clear(); denominators.clear(); }
From source file:com.datatorrent.lib.counters.BasicCountersTest.java
@Test public void testBasicCounters() throws InstantiationException, IllegalAccessException { BasicCounters<MutableDouble> doubleBasicCounters = new BasicCounters<MutableDouble>(MutableDouble.class); MutableDouble counterA = doubleBasicCounters.findCounter(CounterKeys.A); counterA.increment();/*w ww . j av a2s. c om*/ MutableDouble counterAInCounters = doubleBasicCounters.getCounter(CounterKeys.A); Assert.assertNotNull("null", doubleBasicCounters.getCounter(CounterKeys.A)); Assert.assertTrue("equality", counterAInCounters.equals(counterA)); Assert.assertEquals(counterA.doubleValue(), 1.0, 0); }
From source file:com.datatorrent.lib.math.MarginMap.java
/** * Generates tuples for each key and emits them. Only keys that are in the denominator are iterated on * If the key is only in the numerator, it gets ignored (cannot do divide by 0) * Clears internal data//from w w w .j a v a 2s . com */ @Override public void endWindow() { HashMap<K, V> tuples = new HashMap<K, V>(); Double val; for (Map.Entry<K, MutableDouble> e : denominators.entrySet()) { MutableDouble nval = numerators.get(e.getKey()); if (nval == null) { nval = new MutableDouble(0.0); } else { numerators.remove(e.getKey()); // so that all left over keys can be reported } if (percent) { val = (1 - nval.doubleValue() / e.getValue().doubleValue()) * 100; } else { val = 1 - nval.doubleValue() / e.getValue().doubleValue(); } tuples.put(e.getKey(), getValue(val.doubleValue())); } if (!tuples.isEmpty()) { margin.emit(tuples); } numerators.clear(); denominators.clear(); }