@Override
 public void process(KeyValPair<MerchantKey, Double> tuple) {
   MutableDouble currentSma = currentSMAMap.get(tuple.getKey());
   if (currentSma == null) { // first sma for the given key
     double sma = tuple.getValue();
     currentSMAMap.put(tuple.getKey(), new MutableDouble(sma));
     // lastSMAMap.put(tuple.getKey(), new MutableDouble(sma));
   } else { // move the current SMA value to the last SMA Map
     // lastSMAMap.get(tuple.getKey()).setValue(currentSma.getValue());
     currentSma.setValue(tuple.getValue()); // update the current SMA value
   }
 }
Exemple #2
0
 /** For each tuple (a key value pair) Adds the values for each key. */
 @Override
 public void process(KeyValPair<K, V> tuple) {
   K key = tuple.getKey();
   if (!doprocessKey(key)) {
     return;
   }
   SumEntry val = sums.get(key);
   if (val == null) {
     val = new SumEntry(new MutableDouble(tuple.getValue().doubleValue()), true);
   } else {
     val.sum.add(tuple.getValue().doubleValue());
     val.changed = true;
   }
   sums.put(cloneKey(key), val);
 }
 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)));
       }
       // }
     }
   }
 }