private void mergeToHeap( ActionCombinerValue newValList, UserActiveHistory oldVal, UserActiveHistory.Builder updatedBuilder) { HashSet<String> alreadyIn = new HashSet<String>(); for (String newItem : newValList.getActRecodeMap().keySet()) { if (updatedBuilder.getActRecordsCount() >= topNum) { break; } if (!alreadyIn.contains(newItem)) { updatedBuilder.addActRecords(newValList.getActRecodeMap().get(newItem)); alreadyIn.add(newItem); } } if (oldVal != null) { for (Recommend.UserActiveHistory.ActiveRecord eachOldVal : oldVal.getActRecordsList()) { if (updatedBuilder.getActRecordsCount() >= topNum) { break; } if (alreadyIn.contains(eachOldVal.getItem())) { continue; } updatedBuilder.addActRecords(eachOldVal); } } }
@Override public void processEvent(String sid, Tuple tuple) { try { String bid = tuple.getStringByField("bid"); String qq = tuple.getStringByField("qq"); String uid = tuple.getStringByField("uid"); String itemId = tuple.getStringByField("item_id"); String actionType = tuple.getStringByField("action_type"); String actionTime = tuple.getStringByField("action_time"); String lbsInfo = tuple.getStringByField("lbs_info"); String platform = tuple.getStringByField("platform"); Long bigType = tuple.getLongByField("big_type"); Long midType = tuple.getLongByField("mid_type"); Long smallType = tuple.getLongByField("small_type"); Long itemTime = tuple.getLongByField("item_time"); String shopId = tuple.getStringByField("shop_id"); if (!Utils.isItemIdValid(itemId) || Utils.isRecommendAction(actionType)) { return; } if (qq.equals("389687043") || qq.equals("475182144")) { logger.info("--input to combiner---" + tuple.toString()); } Recommend.UserActiveHistory.ActiveRecord.Builder actBuilder = Recommend.UserActiveHistory.ActiveRecord.newBuilder(); actBuilder .setItem(itemId) .setActTime(Long.valueOf(actionTime)) .setActType(Integer.valueOf(actionType)) .setBigType(bigType) .setMiddleType(midType) .setSmallType(smallType) .setLBSInfo(lbsInfo) .setPlatForm(platform) .setShopId(shopId) .setItemTime(itemTime); ActionCombinerValue value = new ActionCombinerValue(); value.init(itemId, actBuilder.build()); if (Utils.isQNumValid(qq)) { String key = bid + "#" + qq + "#" + Constants.topN_alg_name; combinerKeys(key, value); } else if (!uid.equals("0") && !uid.equals("")) { String key = bid + "#" + uid + "#" + Constants.topN_Noqq_alg_name; if (debug) { logger.info("input ,key=" + key); } combinerKeys(key, value); } } catch (Exception e) { logger.error(e.getMessage(), e); } }
@Override public void processEvent(String sid, Tuple tuple) { try { String bid = tuple.getStringByField("bid"); String adpos = Constants.DEFAULT_ADPOS; String qq = tuple.getStringByField("qq"); String itemId = tuple.getStringByField("item_id"); if (!Utils.isQNumValid(qq)) { return; } if (qq.equals("389687043") || qq.equals("475182144")) { logger.info("--input to combiner---" + tuple.toString()); } String actionType = tuple.getStringByField("action_type"); String actionTime = tuple.getStringByField("action_time"); String lbsInfo = tuple.getStringByField("lbs_info"); String platform = tuple.getStringByField("platform"); if (sid.equals(Constants.recommend_action_stream) && Utils.isRecommendAction(actionType)) { String actionResult = tuple.getStringByField("action_result"); String[] items = actionResult.split(";", -1); for (String resultItem : items) { if (resultItem.endsWith("#1") || resultItem.endsWith("#2")) { resultItem = resultItem.substring(0, resultItem.length() - 2); } if (Utils.isItemIdValid(resultItem)) { Recommend.UserActiveHistory.ActiveRecord.Builder actBuilder = Recommend.UserActiveHistory.ActiveRecord.newBuilder(); actBuilder .setItem(resultItem) .setActTime(Long.valueOf(actionTime)) .setActType(Integer.valueOf(actionType)) .setLBSInfo(lbsInfo) .setPlatForm(platform); ActionCombinerValue value = new ActionCombinerValue(); value.init(resultItem, actBuilder.build()); UpdateKey key = new UpdateKey(bid, Long.valueOf(qq), 0, adpos, resultItem); if (qq.equals("389687043") || qq.equals("475182144")) { logger.info( "--input impress to combiner---,itemId=" + resultItem + ",key=" + key.getDetailKey()); } combinerKeys(key.getDetailKey(), value); } } } else if (sid.equals(Constants.actions_stream) && !Utils.isRecommendAction(actionType)) { Recommend.UserActiveHistory.ActiveRecord.Builder actBuilder = Recommend.UserActiveHistory.ActiveRecord.newBuilder(); actBuilder .setItem(itemId) .setActTime(Long.valueOf(actionTime)) .setActType(Integer.valueOf(actionType)) .setLBSInfo(lbsInfo) .setPlatForm(platform); if (Utils.isItemIdValid(itemId)) { ActionCombinerValue value = new ActionCombinerValue(); value.init(itemId, actBuilder.build()); UpdateKey key = new UpdateKey(bid, Long.valueOf(qq), 0, adpos, itemId); combinerKeys(key.getDetailKey(), value); } } } catch (Exception e) { logger.error(e.getMessage(), e); } }