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

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

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

Tuple.getDouble介绍

[英]Returns the Double at position i in the tuple. If that field is not a Double, you will get a runtime error.
[中]返回元组中位置i处的Double。如果该字段不是双精度字段,则会出现运行时错误。

代码示例

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

@Override
  public int compare(Tuple o1, Tuple o2) {
    double score1 = o1.getDouble(1);
    double score2 = o2.getDouble(1);
    if (score1 < score2) {
      return -1;
    } else if (score1 > score2) {
      return 1;
    }
    return 0;
  }
});

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

String number  = input.getString(0);
long timestamp = input.getLong(1);
double rate    = input.getDouble(2);

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

/**
   * Identify the abnormal streams.
   * @return
   */
  private List<Tuple> identifyAbnormalStreams() {
    List<Tuple> abnormalStreamList = new ArrayList<>();

    int medianIdx = (int)Math.round(streamList.size() / 2);
    Tuple medianTuple = BFPRT.bfprt(streamList, medianIdx);
    double minScore = Double.MAX_VALUE;
    
    for (int i = 0; i < medianIdx; ++i) {
      double score = streamList.get(i).getDouble(1);
      if (score < minScore) {
        minScore = score; 
      }
    }

    double medianScore = medianTuple.getDouble(1);

    abnormalStreamList.addAll(streamList);
    return abnormalStreamList;
  }
}

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

/**
 * Find the ith-smallest elements in tupleList in O(n).
 * @param tupleList
 * @param i
 * @return
 */
public static Tuple bfprt(List<Tuple> tupleList, int i) {
  List<TupleWrapper> tupleWrapperList = new ArrayList<TupleWrapper>();
  for (Tuple tuple : tupleList) {
    tupleWrapperList.add(new TupleWrapper(tuple.getDouble(1), tuple));
  }
  // insertionSort(tupleWrapperList, 0, tupleWrapperList.size());
  // return tupleWrapperList.get(i).tuple;
  Tuple medianTuple = bfprtWrapper(tupleWrapperList, i, 0, tupleWrapperList.size() - 1).tuple;
  tupleList.clear();
  for (TupleWrapper wrapper : tupleWrapperList) {
    tupleList.add(wrapper.tuple);
  }
  return medianTuple;
}

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

@Override
//	update the stream 
public void execute(Tuple input) {
  long timestamp = input.getLong(1);
  set.add(timestamp);
  if (previousTimestamp != timestamp) { 
    if (previousTimestamp != 0) {
      System.out.println("\n\n\n\n\n\n" + output + "\n\n\n\n\n\n\n");
      output = "";
    }
    previousTimestamp = timestamp;
  }
  String entityId = input.getString(0);
  double dataInstanceScore = input.getDouble(2);
  Double streamScore = accumulateScores.get(entityId);
  if (streamScore == null) {
    streamScore = 0.0;
  }
  
  streamScore = dataInstanceScore + streamScore * Math.exp(-lambda * (previousTimestamp == 0? 1 : timestamp - previousTimestamp));
  accumulateScores.put(entityId, streamScore);
  output += "EntityID:" + entityId + "\t\tAccummulated Score:" + streamScore + "\n";
}

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

List<Tuple> abnormalStreams = identifyAbnormalStreams();
int medianIdx = (int)Math.round(streamList.size() / 2);
double minScore = abnormalStreams.get(0).getDouble(1);
double medianScore = abnormalStreams.get(medianIdx).getDouble(1);
  double streamScore = streamProfile.getDouble(1);
  boolean isAbnormal = false;
      streamProfile.getDouble(1), streamProfile.getLong(2), 
      isAbnormal, streamProfile.getValue(3)));

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

List<Tuple> abnormalStreams = this.identifyAbnormalStreams();
    int medianIdx = (int) streamList.size() / 2;
    double minScore = abnormalStreams.get(0).getDouble(1);
    double medianScore = abnormalStreams.get(medianIdx).getDouble(1);
      double streamScore = streamProfile.getDouble(1);
      double curDataInstScore = streamProfile.getDouble(4);
      boolean isAbnormal = false;
double dataInstScore = input.getDouble(4);
if (dataInstScore > maxDataInstanceScore) {
  maxDataInstanceScore = dataInstScore;

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

double dataInstanceAnomalyScore = input.getDouble(1);
      dataInstanceAnomalyScore, input.getDouble(1));

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

isAbnormal = true;
collector.emit(streamList, new Values(streamProfile.getString(0), streamProfile.getDouble(1), streamProfile.getLong(2), isAbnormal, streamProfile.getValue(3)));

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

@Override
public void execute(Tuple input) {
  CallDetailRecord cdr = (CallDetailRecord) input.getValueByField(Field.RECORD);
  Source src     = parseComponentId(input.getSourceComponent());
  String caller  = cdr.getCallingNumber();
  long timestamp = cdr.getAnswerTime().getMillis()/1000;
  double score   = input.getDouble(2);
  String key     = String.format("%s:%d", caller, timestamp);
  
  if (map.containsKey(key)) {
    Entry e = map.get(key);
    
    if (e.isFull()) {
      double mainScore = sum(e.getValues(), weights);
      
      LOG.debug(String.format("Score=%f; Scores=%s", mainScore, Arrays.toString(e.getValues())));
      
      collector.emit(new Values(caller, timestamp, mainScore, cdr));
    } else {
      e.set(src, score);
    }
  } else {
    Entry e = new Entry(cdr);
    e.set(src, score);
    map.put(key, e);
  }
}

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

String number  = input.getString(0);
long timestamp = input.getLong(1);
double rate    = input.getDouble(2);

代码示例来源:origin: dongeforever/middlewarerace

@Override
public void execute(Tuple tuple) {
  int type = tuple.getInteger(0);
  Long key = tuple.getLong(1);
  double value = RaceUtils.round(tuple.getDouble(2));
  LOG.info("FLUSH_TO_TAIR type:{} key:{} value:{}",type, key, value);
  switch (type){
    case  RaceConfig.RATIO:
      tairOperator.write(RaceConfig.prex_ratio+key,value);
      break;
    case RaceConfig.TB_PAY:
      tairOperator.write(RaceConfig.prex_taobao+key,value);
      break;
    case RaceConfig.TM_PAY:
      tairOperator.write(RaceConfig.prex_tmall+key,value);
      break;
    default:
      LOG.info("unknown value type {}",type);
  }
  collector.ack(tuple);
  updateSendTps();
}

代码示例来源:origin: dongeforever/middlewarerace

@Override
public void execute(Tuple tuple) {
  Long orderId = tuple.getLong(0);
  int from = tuple.getInteger(1);
  Long ctime = tuple.getLong(2);
  double amount = tuple.getDouble(3);
  collector.ack(tuple);
  collector.emit(new Values(orderId,from,ctime,amount));
  updateSendTps();
}

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

String number  = input.getString(0);
long timestamp = input.getLong(1);
double rate    = input.getDouble(2);

代码示例来源:origin: dongeforever/middlewarerace

@Override
public void execute(Tuple tuple) {
  int from = tuple.getInteger(0);
  Long ctime = tuple.getLong(1);
  double amount = tuple.getDouble(2);
  collector.ack(tuple);
  if(from == RaceConfig.TBORDER ){
    this.tbPayMap.merge(new Item().amount(amount).key(RaceUtils.getMinuteTime(ctime)));
  }else if (from == RaceConfig.TMORDER){
    this.tmPayMap.merge(new Item().amount(amount).key(RaceUtils.getMinuteTime(ctime)));
  }else {
    LOG.info("unknown from {}",from);
  }
  updateSendTps();
}

代码示例来源:origin: dongeforever/middlewarerace

@Override
public void execute(Tuple tuple) {
  Long ctime = tuple.getLong(0);
  short platform = tuple.getShort(1);
  double amount = tuple.getDouble(2);
  collector.ack(tuple);
  Long key = RaceUtils.getMinuteTime(ctime);
  //LOG.info("PAT_RATIO_RECEIVE ctime:{} platform:{} amout:{}",ctime,platform,amount);
  if(platform == 0){
    payRatioArray.merge(new PayRatio().key(key).pcPay(amount));
  }else if(platform == 1){
    payRatioArray.merge(new PayRatio().key(key).wxPay(amount));
  }else {
    LOG.info("Pay ratio unknown platform {}",platform);
  }
  updateSendTps();
}

代码示例来源:origin: dongeforever/middlewarerace

@Override
public void execute(Tuple tuple) {
  collector.ack(tuple);
  Long orderId = tuple.getLong(0);
  int from = tuple.getInteger(1);
  Long ctime = tuple.getLong(2);
  double amount = tuple.getDouble(3);
  //LOG.info("OrderJoinReceive orderId:{} from:{} amount:{}",orderId, from, amount);
  if (from > 0){
    orderJoinMap.merge(new OrderJoinItem(orderId).from(from).totalPrice(amount).ctime(ctime));
  }else {
    orderJoinMap.merge(new OrderJoinItem(orderId).from(from).totalPay(amount).ctime(ctime));
  }
  updateSendTps();
}

相关文章