/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
public double getSum() { return sum.doubleValue(); }
@Override public double getSum() { return sum.doubleValue(); }
/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
/** * 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 */ @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(); } }
/** * 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 */ @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(); } }
val = (1 - nval.doubleValue() / e.getValue().doubleValue()) * 100; } else { val = 1 - nval.doubleValue() / e.getValue().doubleValue();
public void endWindow() { Map<String, Object> summary = new HashMap<String, Object>(); double avg; if (txnsInLastSecond.longValue() == 0) { avg = 0; } else { avg = amtInLastSecond.doubleValue() / txnsInLastSecond.longValue(); } summary.put("totalTxns", totalTxns); summary.put("txnsInLastSecond", txnsInLastSecond); summary.put("amtInLastSecond", amtFormatter.format(amtInLastSecond)); summary.put("avgAmtInLastSecond", amtFormatter.format(avg)); summaryTxnOutputPort.emit(summary); txnsInLastSecond.setValue(0); amtInLastSecond.setValue(0); }
@Override public void endWindow() { for (AverageAlertData data : alerts) { try { 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()); } } }
@Override public void endWindow() { int totalWindowsOccupied = cacheOject.size(); for (Map.Entry<String, Map<String, KeyValPair<MutableDouble, Integer>>> e : outputMap.entrySet()) { for (Map.Entry<String, KeyValPair<MutableDouble, Integer>> dimensionValObj : e.getValue().entrySet()) { Map<String, DimensionObject<String>> outputData = new HashMap<String, DimensionObject<String>>(); KeyValPair<MutableDouble, Integer> keyVal = dimensionValObj.getValue(); if (operationType == AggregateOperation.SUM) { outputData.put(e.getKey(), new DimensionObject<String>(keyVal.getKey(), dimensionValObj.getKey())); } else if (operationType == AggregateOperation.AVERAGE) { if (keyVal.getValue() != 0) { double totalCount = ((double)(totalWindowsOccupied * applicationWindowSize)) / 1000; outputData.put(e.getKey(), new DimensionObject<String>(new MutableDouble(keyVal.getKey().doubleValue() / totalCount), dimensionValObj.getKey())); } } if (!outputData.isEmpty()) { output.emit(outputData); } } } currentWindow = (currentWindow + 1) % windowSize; }
/** * Emit only at the end of windowSize window boundary. */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void endWindow() { boolean emit = (++windowCount) % windowSize == 0; if (!emit) { return; } // Emit only at the end of application window boundary. boolean dosum = sum.isConnected(); if (dosum) { for (Map.Entry<K, SumEntry> e : sums.entrySet()) { K key = e.getKey(); if (dosum) { sum.emit(new KeyValPair(key, getValue(e.getValue().sum.doubleValue()))); } } } // Clear cumulative sum at the end of application window boundary. sums.clear(); } }
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); //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))); } //} } } }
/** * Process each key, compute change or percent, and emit it. */ @Override public void process(KeyValPair<K, V> tuple) { K key = tuple.getKey(); if (!doprocessKey(key)) { return; } MutableDouble bval = basemap.get(key); if (bval != null) { // Only process keys that are in the basemap double cval = tuple.getValue().doubleValue() - bval.doubleValue(); change.emit(new KeyValPair<K, V>(cloneKey(key), getValue(cval))); percent.emit(new KeyValPair<K, Double>(cloneKey(key), (cval / bval.doubleValue()) * 100)); } } };
/** * Process each key, compute change or percent, and emit it. */ @Override public void process(KeyValPair<K, V> tuple) { K key = tuple.getKey(); if (!doprocessKey(key)) { return; } MutableDouble bval = basemap.get(key); if (bval != null) { // Only process keys that are in the basemap double cval = tuple.getValue().doubleValue() - bval.doubleValue(); change.emit(new KeyValPair<K, V>(cloneKey(key), getValue(cval))); percent.emit(new KeyValPair<K, Double>(cloneKey(key), (cval / bval.doubleValue()) * 100)); } } };
/** * Emits average for each key in end window. Data is computed during process * on input port Clears the internal data before return. */ @Override public void endWindow() { for (Map.Entry<K, MutableDouble> e : sums.entrySet()) { K key = e.getKey(); double d = e.getValue().doubleValue(); if (doubleAverage.isConnected()) { doubleAverage.emit(new KeyValPair<K, Double>(key, d / counts.get(key).doubleValue())); } if (intAverage.isConnected()) { intAverage.emit(new KeyValPair<K, Integer>(key, (int)d)); } if (longAverage.isConnected()) { longAverage.emit(new KeyValPair<K, Long>(key, (long)d)); } } sums.clear(); counts.clear(); } }
/** * Emits on all ports that are connected. Data is precomputed during process on input port and endWindow just emits it for each key. Clears the internal data. */ @Override public void endWindow() { for (Map.Entry<K, SumEntry> e: sums.entrySet()) { K key = e.getKey(); SumEntry val = e.getValue(); if (val.changed) { sum.emit(new KeyValPair<K, V>(key, getValue(val.sum.doubleValue()))); sumDouble.emit(new KeyValPair<K, Double>(key, val.sum.doubleValue())); sumInteger.emit(new KeyValPair<K, Integer>(key, val.sum.intValue())); sumFloat.emit(new KeyValPair<K, Float>(key, val.sum.floatValue())); sumShort.emit(new KeyValPair<K, Short>(key, val.sum.shortValue())); sumLong.emit(new KeyValPair<K, Long>(key, val.sum.longValue())); } } clearCache(); }