Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
      }
    }
  }
Ejemplo n.º 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);
 }