Exemple #1
0
    public void map(LongWritable key, Text value, Context context)
        throws IOException, InterruptedException {
      String line = value.toString();
      String[] fields = line.split(",");
      // data
      String date = fields[BootStrap.DATE_ID.ordinal()];
      // mac
      String mac = fields[BootStrap.MAC.ordinal()];
      // plat
      String plat = null;
      if ("0".equals(type)) {
        // 计算所有用户
        if (filePath.toString().contains("bootstrap")) {
          plat = fields[BootStrap.PLAT_ID.ordinal()];

        } else {
          plat = fields[Exit.PLAT_ID.ordinal()];
        }
      } else if ("1".equals(type)) {
        // 计算在线用户
        if (filePath.toString().contains("bootstrap")) {
          if (!ntOK(fields[BootStrap.NT.ordinal()], "1")) return;
          plat = getPlat(fields[BootStrap.DEV.ordinal()]);

        } else {
          if (!ntOK(fields[Exit.NT.ordinal()], "1")) return;
          plat = getPlat(fields[Exit.DEV.ordinal()]);
        }
      } else if ("2".equals(type)) {
        // 计算离线用户
        if (filePath.toString().contains("bootstrap")) {
          if (!ntOK(fields[BootStrap.NT.ordinal()], "2")) return;
          plat = getPlat(fields[BootStrap.DEV.ordinal()]);

        } else {
          if (!ntOK(fields[Exit.NT.ordinal()], "2")) return;
          plat = getPlat(fields[Exit.DEV.ordinal()]);
        }
      }
      context.write(new Text(date + "\t" + plat), new Text(mac));
    }
    public void map(LongWritable key, Text value, Context context)
        throws IOException, InterruptedException {
      try {

        String line = value.toString();
        String sep = ",";
        if (filePath.toString().contains("offline")) {
          sep = "\t";
        }
        String[] fields = line.split(sep);
        // data
        String date = fields[BootStrap.TIMESTAMP.ordinal()];
        // mac
        String mac = null;
        // plat
        String plat = null;

        if (filePath.toString().contains("bootstrap")) {
          plat = fields[BootStrap.DEV.ordinal()];
          plat =
              String.valueOf(dmPlatyRuleDAO.getDMOjb(PlatTypeFormatUtil.getFormatPlatType(plat)));
          long versionId = IPFormatUtil.ip2long(fields[BootStrap.VER.ordinal()]);
          mac =
              FormatMobileUtil.getMac(
                  fields, Integer.parseInt(plat), versionId, BootStrap.class.getName());

        } else {
          plat = fields[Exit.DEV.ordinal()];
          plat =
              String.valueOf(dmPlatyRuleDAO.getDMOjb(PlatTypeFormatUtil.getFormatPlatType(plat)));
          long versionId = IPFormatUtil.ip2long(fields[Exit.VER.ordinal()]);
          mac =
              FormatMobileUtil.getMac(
                  fields, Integer.parseInt(plat), versionId, BootStrap.class.getName());
        }

        if ("0".equals(type)) {
          // 对于所有用户,只有iphone需要用到离线日志
          if (!"4".equals(plat)) {
            if (filePath.toString().contains("offline")) return;
          }

        } else if ("1".equals(type)) {
          // 计算在线用户
          if (filePath.toString().contains("bootstrap")) {
            if (!ntOK(fields[BootStrap.NT.ordinal()], "1")) return;
          } else {
            if (!ntOK(fields[Exit.NT.ordinal()], "1")) return;
          }
        } else if ("2".equals(type)) {

          // 对于所有用户,只有iphone需要用到离线日志
          if ("4".equals(plat)) {
            if (!filePath.toString().contains("offline")) return;
          } else {
            if (filePath.toString().contains("offline")) return;
          }

          // 计算离线用户
          if (filePath.toString().contains("bootstrap")) {
            if (!ntOK(fields[BootStrap.NT.ordinal()], "2")) return;
          } else {
            if (!ntOK(fields[Exit.NT.ordinal()], "2")) return;
          }
        }
        Map<ConstantEnum, String> formatTimesMap = TimestampFormatUtil.formatTimestamp(date);
        // dataId
        date = formatTimesMap.get(ConstantEnum.DATE_ID);
        context.write(new Text(date + "\t" + plat), new Text(mac));
      } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        System.out.println(value.toString());
      }
    }