示例#1
0
  public void map(long recordNum, Record record, TaskContext context) throws IOException {

    if (record.getString(4).equals("cart")) return;

    key.set("session", record.getBigint(0));
    key.set("user_id", record.getString(1));

    value.set("item_id", record.getBigint(2).toString());
    value.set("bundle", record.getString(3));
    value.set("action", record.getString(4));
    value.set("vtime", record.getString(5));

    context.write(key, value);
  }
示例#2
0
  public void map(long recordNum, Record record, TaskContext context) throws IOException {
    key.set("user_id", record.getString(0));
    long type = record.getBigint(3);
    long date = record.getBigint(5);

    //    	  user_item last 1 day buy times
    if (type == 4 && date == 30) {
      value.set("ui_l1_buy", 1);
    } else {
      value.set("ui_l1_buy", 0);
    }

    //    	  user_item last 3 days click times
    if (type == 1 && (date >= 28 && date <= 30)) {
      value.set("ui_l3_clk", 1);
    } else {
      value.set("ui_l3_clk", 0);
    }

    //    	  user_item last 5 days action times
    if (date >= 26 && date <= 30) {
      value.set("ui_l5_act", 1);
    } else {
      value.set("ui_l5_act", 0);
    }

    context.write(key, value);
  }
 public void reduce(Record key, Iterator<Record> values, TaskContext context) throws IOException {
   long c = 0;
   while (values.hasNext()) {
     Record val = values.next();
     c += val.getBigint(0);
   }
   count.set(0, c);
   context.write(key, count);
 }
 public void reduce(Record key, Iterator<Record> values, TaskContext context) throws IOException {
   long count = 0;
   while (values.hasNext()) {
     Record val = values.next();
     count += val.getBigint(0);
   }
   result.set(0, key.get(0));
   result.set(1, count);
   context.write(result);
 }
示例#5
0
  public void reduce(Record key, Iterator<Record> values, TaskContext context) throws IOException {

    Map<String, Integer> frqCountMap = new HashMap<String, Integer>();
    String itemBought = "";
    List<Object[]> rList = new ArrayList<Object[]>();
    while (values.hasNext()) {
      Record val = values.next();
      String itemTemp = val.getString("item");
      if (val.getString("action").equals("alipay")) {
        itemBought = itemTemp;
        continue;
      }

      if (frqCountMap.containsKey(itemTemp)) {
        frqCountMap.put(itemTemp, frqCountMap.get(itemTemp));
      } else {
        frqCountMap.put(itemTemp, 1);
      }

      rList.add(val.toArray().clone());
    }

    int sessionLen = rList.size();
    int itemNum = frqCountMap.keySet().size();

    if (sessionLen < 4 || itemNum < 2) return;

    Collections.sort(
        rList,
        new Comparator<Object[]>() {
          public int compare(Object[] r1, Object[] r2) {
            return r2[2].toString().compareTo(r1[2].toString());
          }
        });

    if (frqCountMap.containsKey(itemBought) == false) {
      output.set(0, key.getBigint("session"));
      output.set(1, key.getString("user_id"));

      output.set(2, 0.99);
      output.set(3, 0.99);
      context.write(output);
      return;
    }

    output.set(0, key.getBigint("session"));
    output.set(1, key.getString("user_id"));

    int i = 0;
    while (i < sessionLen) {
      if (rList.get(i)[0].toString().equals(itemBought)) {
        output.set(2, i / (double) sessionLen);
        break;
      }
      i++;
    }

    List<Map.Entry<String, Integer>> frqList =
        new ArrayList<Map.Entry<String, Integer>>(frqCountMap.entrySet());

    Collections.sort(
        frqList,
        new Comparator<Map.Entry<String, Integer>>() {
          public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o2.getValue().compareTo(o1.getValue());
          }
        });

    i = 0;
    while (i < itemNum) {
      if (rList.get(i)[0].toString().equals(itemBought)) {
        output.set(3, i / (double) itemNum);
        break;
      }
      i++;
    }

    context.write(output);
  }