backtype.storm.tuple.Tuple.getDoubleByField()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(65)

本文整理了Java中backtype.storm.tuple.Tuple.getDoubleByField()方法的一些代码示例,展示了Tuple.getDoubleByField()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.getDoubleByField()方法的具体详情如下:
包路径:backtype.storm.tuple.Tuple
类名称:Tuple
方法名:getDoubleByField

Tuple.getDoubleByField介绍

暂无

代码示例

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple input) {
  String deviceID = input.getStringByField(Field.DEVICE_ID);
  double movingAverageInstant = input.getDoubleByField(Field.MOVING_AVG);
  double nextDouble = input.getDoubleByField(Field.VALUE);
  
  if (Math.abs(nextDouble - movingAverageInstant) > spikeThreshold * movingAverageInstant) {
    collector.emit(input, new Values(deviceID, movingAverageInstant, nextDouble, "spike detected"));
  }
  
  collector.ack(input);
}

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple tuple) {
  String component = tuple.getSourceComponent();
  
  if (component.equals(Component.GLOBAL_MEDIAN)) {
    long timestamp = tuple.getLongByField(Field.TIMESTAMP);
    double globalMedianLoad = tuple.getDoubleByField(Field.GLOBAL_MEDIAN_LOAD);
    
    globalMedianBacklog.put(timestamp, globalMedianLoad);
    
    // ordered based on the timestamps
    while (!unprocessedMessages.isEmpty() &&
        unprocessedMessages.peek().tuple.getLongByField(Field.TIMESTAMP).equals(timestamp)) {
      Tuple perPlugMedianTuple = unprocessedMessages.poll().tuple;
      processPerPlugMedianTuple(perPlugMedianTuple);
    }
  } else {
    processPerPlugMedianTuple(tuple);
  }
}

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple input) {
  long timestamp = input.getLongByField(Field.TIMESTAMP);
  String id = input.getStringByField(Field.ID);
  double dataInstanceAnomalyScore = input.getDoubleByField(Field.DATAINST_ANOMALY_SCORE);
  
  Queue<Double> slidingWindow = slidingWindowMap.get(id);
  if (slidingWindow == null) {
    slidingWindow = new LinkedList<>();
  }
  // update sliding window
  slidingWindow.add(dataInstanceAnomalyScore);
  if (slidingWindow.size() > this.windowLength) {
      slidingWindow.poll();
  }
  slidingWindowMap.put(id, slidingWindow);
  double sumScore = 0.0;
  for (double score : slidingWindow) {
    sumScore += score;
  }
  
  collector.emit(new Values(id, sumScore, timestamp, input.getValue(3), dataInstanceAnomalyScore));
  collector.ack(input);
}

代码示例来源:origin: jasonTangxd/recommendSys

itemId=tuple.getIntegerByField("itemId");
  feature=tuple.getIntegerByField("feature");
  score=tuple.getDoubleByField("score");
} catch (Exception e) {
  logger.error(e.getMessage());

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple input) {
  try {
    int speed        = input.getIntegerByField(Field.SPEED);
    int bearing      = input.getIntegerByField(Field.BEARING);
    double latitude  = input.getDoubleByField(Field.LATITUDE);
    double longitude = input.getDoubleByField(Field.LONGITUDE);
    
    if (speed <= 0) return;
    if (longitude > lonMax || longitude < lonMin || latitude > latMax || latitude < latMin) return;
    
    GPSRecord record = new GPSRecord(longitude, latitude, speed, bearing);
    
    int roadID = sectors.fetchRoadID(record);
    
    if (roadID != -1) {
      List<Object> values = input.getValues();
      values.add(roadID);
      
      collector.emit(input, values);
    }
    
    collector.ack(input);
  } catch (SQLException ex) {
    LOG.error("Unable to fetch road ID", ex);
  }
}

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple tuple) {
  int operation  = tuple.getIntegerByField(Field.SLIDING_WINDOW_ACTION);
  double value   = tuple.getDoubleByField(Field.VALUE);
  long timestamp = tuple.getLongByField(Field.TIMESTAMP);
  String key     = getKey(tuple);
  RunningMedianCalculator medianCalc = runningMedians.get(key);
  if (medianCalc == null) {
    medianCalc =  new RunningMedianCalculator();
    runningMedians.put(key, medianCalc);
  }
  
  Long lastUpdatedTs = lastUpdatedTsMap.get(key);
  if (lastUpdatedTs == null) {
    lastUpdatedTs = 0l;
  }
  if (operation == SlidingWindowAction.ADD){
    double median = medianCalc.getMedian(value);
    if (lastUpdatedTs < timestamp) {
      // the sliding window has moved
      lastUpdatedTsMap.put(key, timestamp);
      collector.emit(new Values(key, timestamp, median));
    }
  } else {
    medianCalc.remove(value);
  }
}

代码示例来源:origin: mayconbordin/storm-applications

double askPrice = input.getDoubleByField(Field.PRICE);
int askSize     = input.getIntegerByField(Field.VOLUME);
DateTime date   = (DateTime) input.getValueByField(Field.DATE);

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple input) {
  String deviceID = input.getStringByField(Field.DEVICE_ID);
  double nextDouble = input.getDoubleByField(Field.VALUE);
  double movingAvergeInstant = movingAverage(deviceID, nextDouble);
  
  collector.emit(input, new Values(deviceID, movingAvergeInstant, nextDouble));
  collector.ack(input);
}

代码示例来源:origin: mayconbordin/storm-applications

avg = input.getDoubleByField(Field.AVERAGE);
} else {
  CallDetailRecord cdr = (CallDetailRecord) input.getValueByField(Field.RECORD);

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple tuple) {
  int operation  = tuple.getIntegerByField(Field.SLIDING_WINDOW_ACTION);
  double value   = tuple.getDoubleByField(Field.VALUE);
  long timestamp = tuple.getLongByField(Field.TIMESTAMP);
  
  if (operation == SlidingWindowAction.ADD){
    double median = medianCalc.getMedian(value);
    if (lastUpdatedTs < timestamp) {
      // the sliding window has moved
      lastUpdatedTs = timestamp;
      collector.emit(new Values(timestamp, median));
    }
  } else {
    medianCalc.remove(value);
  }
}

代码示例来源:origin: mayconbordin/storm-applications

String houseId = key.split(":")[0];
long timestamp = tuple.getLongByField(Field.TIMESTAMP);
double value   = tuple.getDoubleByField(Field.PER_PLUG_MEDIAN);

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple tuple) {
  int type = tuple.getIntegerByField(Field.PROPERTY);
  
  // we are interested only in load
  if (type == Measurement.WORK) {
    return;
  }
  
  SlidingWindowEntryImpl windowEntry = new SlidingWindowEntryImpl(
      tuple.getLongByField(Field.TIMESTAMP), tuple.getDoubleByField(Field.VALUE),
      tuple.getStringByField(Field.HOUSE_ID), tuple.getStringByField(Field.HOUSEHOLD_ID),
      tuple.getStringByField(Field.PLUG_ID));
  
  window.add(windowEntry, new SlidingWindowCallback() {
    @Override
    public void remove(List<SlidingWindowEntry> entries) {
      for (SlidingWindowEntry e : entries) {
        SlidingWindowEntryImpl entry = (SlidingWindowEntryImpl) e;
        collector.emit(new Values(entry.ts, entry.houseId, entry.houseHoldId,
            entry.plugId, entry.value, SlidingWindowAction.REMOVE));
      }
    }
  });
  
  collector.emit(new Values(windowEntry.ts, windowEntry.houseId, windowEntry.houseHoldId,
      windowEntry.plugId, windowEntry.value, SlidingWindowAction.ADD));
}

代码示例来源:origin: mayconbordin/storm-applications

double value   = tuple.getDoubleByField(Field.VALUE);

代码示例来源:origin: mayconbordin/storm-applications

@Override
public void execute(Tuple input) {
  String stock  = input.getStringByField(Field.STOCK);
  double price  = (double) input.getDoubleByField(Field.PRICE);
  int volume    = (int) input.getIntegerByField(Field.VOLUME);
  DateTime date = (DateTime) input.getValueByField(Field.DATE);
  int inteval   = input.getIntegerByField(Field.INTERVAL);
  Vwap vwap = stocks.get(stock);
  if (withinPeriod(vwap, date)) {
    vwap.update(volume, price, date.plusSeconds(inteval));
    collector.emit(input, new Values(stock, vwap.getVwap(), vwap.getStartDate(), vwap.getEndDate()));
  } else {
    if (vwap != null) {
      collector.emit(new Values(stock, vwap.getVwap(), vwap.getStartDate(), vwap.getEndDate()));
    }
    
    vwap = new Vwap(volume, price, date, date.plusSeconds(inteval));
    stocks.put(stock, vwap);
    collector.emit(input, new Values(stock, vwap.getVwap(), vwap.getStartDate(), vwap.getEndDate()));
  }
  
  collector.ack(input);
}

相关文章