Esempio n. 1
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);
        }
      }
    }
  }
 private int getStatDate(Context cxt) {
   Date date = ConfigManager.getInitialDate(cxt.getConfiguration());
   Calendar calendar = Calendar.getInstance();
   if (date != null) {
     calendar.setTime(date);
   }
   calendar.add(Calendar.DAY_OF_MONTH, -1); // 结算时间默认调度时间的前一天
   calendar.set(Calendar.HOUR_OF_DAY, 0);
   calendar.set(Calendar.MINUTE, 0);
   calendar.set(Calendar.SECOND, 0);
   return (int) (calendar.getTimeInMillis() / 1000);
 }