public void reduce(Text key, Iterable<Text> values, Context context)
      throws IOException, InterruptedException {

    // 편차값에 대한 카운트를 저장할 Map 선언 <편차값,aws갯수>
    TreeMap<Double, String> awsCountDev = new TreeMap<Double, String>();

    for (Text val : values) {

      try {

        CsvParser parser = new CsvParser();
        parser.parse(val.toString());

        // Values에 포함된 기상요소 편차 값
        double deviation = Double.parseDouble(parser.get(1));
        // aws 조합
        String awsSet = parser.get(0) + DELIMITER + parser.get(1) + DELIMITER + parser.get(2);

        // 편차 값이 이미 저장되어 있으면 값 1 증가, 저장된 편차 값이 없으면 최초값 1 부여
        if (awsCountDev.containsKey(deviation)) {
          awsCountDev.put(deviation, awsCountDev.get(deviation) + "|" + awsSet);
        } else {
          awsCountDev.put(deviation, awsSet);
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    int writeCnt = 0;

    String awsSetList = "";
    Iterator<Double> iterator = awsCountDev.descendingKeySet().iterator();

    while (iterator.hasNext()) {

      Double valuesDev = iterator.next();

      String[] arr = StringUtil.myToken(awsCountDev.get(valuesDev), "|");

      int awsCount = arr.length;
      for (int i = 0; i < awsCount; i++) {

        awsSetList += DELIMITER + arr[i];
        writeCnt++;
      }

      if (writeCnt >= returnCnt) break;
    }

    context.write(new Text(key + DELIMITER + writeCnt + awsSetList), NullWritable.get());
  }
Ejemplo n.º 2
0
  public void reduce(Text key, Iterable<Text> values, Context context)
      throws IOException, InterruptedException {

    HashMap<String, String> hm = new HashMap<String, String>();
    for (Text val : values) {
      String retValue = val.toString();
      hm.put(retValue.substring(1, 2), retValue.substring(3));
    }

    if ((hm.size() == 2) && (hm.containsKey("F")) && (hm.containsKey("T"))) {

      CsvParser parserFrom = new CsvParser();
      CsvParser parserTo = new CsvParser();

      try {
        parserFrom.parse(hm.get("F"));
        parserTo.parse(hm.get("T"));

        if (parserFrom.getSize() == 13 && parserTo.getSize() == 13) {
          context.write(
              key,
              new Text(
                  calcDeviation(parserFrom.get(0), parserTo.get(0))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(1), parserTo.get(1))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(2), parserTo.get(2))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(3), parserTo.get(3))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(4), parserTo.get(4))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(5), parserTo.get(5))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(6), parserTo.get(6))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(7), parserTo.get(7))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(8), parserTo.get(8))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(9), parserTo.get(9))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(10), parserTo.get(10))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(11), parserTo.get(11))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(12), parserTo.get(12))
                      + DELIMITER
                      + calcDeviation(parserFrom.get(13), parserTo.get(13))));
        }

      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }