Пример #1
0
 public void setFields(String[] fields) {
   super.setFields(fields);
   int length = fields.length;
   this.loginTime = StringUtil.convertInt(fields[length - 3], 0);
   this.onlineTime = StringUtil.convertInt(fields[length - 2], 0);
   this.level = StringUtil.convertInt(fields[length - 1], 0);
 }
Пример #2
0
  @Override
  protected void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {
    String[] valueArr = value.toString().split(MRConstants.SEPERATOR_IN);

    int loginTime = StringUtil.convertInt(valueArr[Index_LoginTime], 0);
    int onlineTime = StringUtil.convertInt(valueArr[Index_OnlineTime], 0);

    Calendar calendar = Calendar.getInstance();
    Date date = ConfigManager.getInitialDate(context.getConfiguration());
    if (date != null) {
      calendar.setTime(date);
    }
    calendar.add(Calendar.HOUR_OF_DAY, -1); // 默认取调度初始化时间的前一个小时
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    int startPoint = (int) (calendar.getTimeInMillis() / 1000); // 找出起始时间点

    if (loginTime > 0 && onlineTime > 0) {
      for (int i = 0; i < 12; i++) {
        int point = startPoint + i * 5 * 60; // 5分钟为步长
        if (loginTime <= point && onlineTime > (point - loginTime)) {
          // 登陆时间在point点之前且在线时长大于point点-登陆时间记为一次在线
          /*
           * ACU/PCU 计算调整为不分渠道统计,只按区服统计
           * 在分区服统计的同时,另加一个不分区服的全量统计
          String[] keyFields = new String[] { valueArr[Index_Appid],
          									valueArr[Index_Platform],
          									valueArr[Index_Channel],
          									valueArr[Index_gameServer],
          									point + "" };*/

          // 分区服的统计
          String[] keyFields =
              new String[] {
                valueArr[Index_Appid],
                valueArr[Index_Platform],
                valueArr[Index_gameServer],
                point + ""
              };
          mapKeyObj.setOutFields(keyFields);
          context.write(mapKeyObj, one);

          // 不分区服的统计,gameServer 以 '-' 代替
          String[] keyFieldsAll =
              new String[] {
                valueArr[Index_Appid],
                valueArr[Index_Platform],
                MRConstants.INVALID_PLACE_HOLDER_CHAR,
                point + ""
              };
          mapKeyObj.setOutFields(keyFieldsAll);
          context.write(mapKeyObj, one);
        }
      }
    }
  }
Пример #3
0
 public OnlineLog(String[] fields) throws Exception {
   super(fields);
   int length = fields.length;
   if (26 != length) {
     throw new Exception("Crush data...");
   }
   this.loginTime = StringUtil.convertInt(fields[length - 3], 0);
   this.onlineTime = StringUtil.convertInt(fields[length - 2], 0);
   this.level = StringUtil.convertInt(fields[length - 1], 0);
 }
  @Override
  protected void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {

    String[] paraArr = value.toString().split(MRConstants.SEPERATOR_IN);
    OnlineDayLog2 onlineDayLog2 = new OnlineDayLog2(paraArr);

    // 新增活跃玩家数、登录次数、在线时长
    String[] keyFields =
        new String[] {
          onlineDayLog2.getAppId(),
          onlineDayLog2.getAppVer(),
          onlineDayLog2.getPlatform(),
          onlineDayLog2.getChannel(),
          onlineDayLog2.getExtendsHelper().getCnty(),
          onlineDayLog2.getExtendsHelper().getProv(),
          Constants.PLAYER_TYPE_ONLINE
        };
    String[] valFields =
        new String[] {
          onlineDayLog2.getTotalLoginTimes() + "", onlineDayLog2.getTotalOnlineTime() + ""
        };
    keyObj.setOutFields(keyFields);
    valObj.setOutFields(valFields);
    keyObj.setSuffix(Constants.SUFFIX_CHANNEL_ONLINE_SUM);
    context.write(keyObj, valObj);
    if ("Y".equals(onlineDayLog2.getIsNewPlayer())) {
      keyFields[keyFields.length - 1] = Constants.PLAYER_TYPE_NEWADD;
      context.write(keyObj, valObj);
    }

    // 机型分布
    String brand = onlineDayLog2.getExtendsHelper().getBrand();
    writeLayout(
        onlineDayLog2,
        Constants.DIM_TYPE_BRAND_DIS + "",
        brand,
        Constants.SUFFIX_CHANNEL_LAYOUT_EQUIP,
        context);

    // 网络分布
    String netType = onlineDayLog2.getExtendsHelper().getNetwork(); // 网络类型
    String netOp = onlineDayLog2.getExtendsHelper().getNetop(); // 宽带运营商
    String mobileOp = onlineDayLog2.getExtendsHelper().getMobileop(); // 移动运营商
    mobileOp = StringUtil.isEmpty(mobileOp) ? "-" : mobileOp;
    writeLayout(
        onlineDayLog2,
        Constants.DIM_TYPE_NET_TYPE_DIS + "",
        netType,
        Constants.SUFFIX_CHANNEL_LAYOUT_EQUIP,
        context);
    writeLayout(
        onlineDayLog2,
        Constants.DIM_TYPE_BROAD_OPER_DIS + "",
        netOp,
        Constants.SUFFIX_CHANNEL_LAYOUT_EQUIP,
        context);
    writeLayout(
        onlineDayLog2,
        Constants.DIM_TYPE_MOBILE_OPER_DIS + "",
        mobileOp,
        Constants.SUFFIX_CHANNEL_LAYOUT_EQUIP,
        context);

    // 登录时段分布
    String onlineRecoeds = onlineDayLog2.getOnlineRecords();
    Map<Integer, Integer> map = StringUtil.getMapFromJson(onlineRecoeds, type);
    if (null != map && !map.isEmpty()) {
      int minLoginTime = 0;
      for (int loginTime : map.keySet()) {
        // 计算得到一天登录的最小时间
        if (0 == minLoginTime) {
          minLoginTime = loginTime;
        }
        minLoginTime = Math.min(loginTime, minLoginTime);
      }
      cal.setTimeInMillis(1000L * minLoginTime);
      int hour = cal.get(Calendar.HOUR_OF_DAY);
      writeLayout(
          onlineDayLog2,
          Constants.DIM_TYPE_LOGIN_HOUR_DIS + "",
          hour + "",
          Constants.SUFFIX_CHANNEL_LAYOUT_ONLINE,
          context);
    }

    // 登录次数
    int loginTimes = onlineDayLog2.getTotalLoginTimes();
    int loginTimesRange = EnumConstants.getItval4DayLoginTimes(loginTimes);
    writeLayout(
        onlineDayLog2,
        Constants.DIM_TYPE_LOGIN_TIMES_DIS + "",
        loginTimesRange + "",
        Constants.SUFFIX_CHANNEL_LAYOUT_ONLINE,
        context);

    // 用户城市分布
    String city = onlineDayLog2.getExtendsHelper().getCity();
    writeLayout(
        onlineDayLog2,
        Constants.DIM_TYPE_CITY_NUM_DIS + "",
        city,
        Constants.SUFFIX_CHANNEL_LAYOUT_ONLINE,
        context);
  }
Пример #5
0
  protected void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {
    if (fileSuffix.contains(Constants.SUFFIX_WAREHOUSE_ONLINE_DAY)) {
      String[] paramsArr = value.toString().split(MRConstants.SEPERATOR_IN);
      WHOnlineLog log = null;
      try {
        log = new WHOnlineLog(paramsArr);
      } catch (Exception e) {
        return;
      }
      String uid = log.getUid();
      String accountId = log.getAccountId();
      String appId = log.getAppId();
      String mac = log.getMac();
      String imei = log.getImei();
      String idfa = log.getIdfa();
      String imsi = log.getImsi();
      byte platform = log.getPlatform();
      String brand = log.getBrand();
      String resolution = log.getResolution();
      int loginDate = StringUtil.truncateDate(log.getTs(), statDate);

      // 账户
      keyFields.setSuffix(Constants.SUFFIX_WAREHOUSE_ACCOUNT_ROLLING);
      keyFields.setOutFields(new String[] {accountId, uid, appId});
      valFields.setOutFields(new String[] {loginDate + ""});
      context.write(keyFields, valFields);

      // UID
      keyFields.setSuffix(Constants.SUFFIX_WAREHOUSE_DEVICE_ROLLING);
      keyFields.setOutFields(new String[] {uid, mac, idfa, imei, platform + "", brand, resolution});
      valFields.setOutFields(new String[] {loginDate + ""});
      context.write(keyFields, valFields);

      // UID + IMSI
      keyFields.setSuffix(Constants.SUFFIX_WAREHOUSE_IMSI_ROLLING);
      keyFields.setOutFields(new String[] {uid, imsi});
      valFields.setOutFields(new String[] {loginDate + ""});
      context.write(keyFields, valFields);
    } else if (fileSuffix.contains(Constants.SUFFIX_WAREHOUSE_ACCOUNT_ROLLING)) {
      String[] paramsArr = value.toString().split(MRConstants.SEPERATOR_IN);
      String accountId = paramsArr[0];
      String uid = paramsArr[1];
      String appId = paramsArr[2];
      String firstLoginDate = paramsArr[3];
      keyFields.setSuffix(Constants.SUFFIX_WAREHOUSE_ACCOUNT_ROLLING);
      keyFields.setOutFields(new String[] {accountId, uid, appId});
      valFields.setOutFields(new String[] {firstLoginDate});
      context.write(keyFields, valFields);
    } else if (fileSuffix.contains(Constants.SUFFIX_WAREHOUSE_DEVICE_ROLLING)) {
      String[] paramsArr = value.toString().split(MRConstants.SEPERATOR_IN);
      String uid = paramsArr[0];
      String mac = paramsArr[1];
      String idfa = paramsArr[2];
      String imei = paramsArr[3];
      String platform = paramsArr[4];
      String brand = paramsArr[5];
      String resolution = paramsArr[6];
      String firstLoginDate = paramsArr[7];
      keyFields.setSuffix(Constants.SUFFIX_WAREHOUSE_DEVICE_ROLLING);
      keyFields.setOutFields(new String[] {uid, mac, idfa, imei, platform, brand, resolution});
      valFields.setOutFields(new String[] {firstLoginDate});
      context.write(keyFields, valFields);
    } else if (fileSuffix.contains(Constants.SUFFIX_WAREHOUSE_IMSI_ROLLING)) {
      String[] paramsArr = value.toString().split(MRConstants.SEPERATOR_IN);
      String uid = paramsArr[0];
      String imsi = paramsArr[1];
      String firstLoginDate = paramsArr[2];
      keyFields.setSuffix(Constants.SUFFIX_WAREHOUSE_IMSI_ROLLING);
      keyFields.setOutFields(new String[] {uid, imsi});
      valFields.setOutFields(new String[] {firstLoginDate});
      context.write(keyFields, valFields);
    }
  }