private void changeMapToPB( HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap, Builder mergeValueBuilder) { Long time = System.currentTimeMillis() / 1000; ArrayList<Long> sortList = new ArrayList<Long>(detailMap.keySet()); Collections.sort( sortList, new Comparator<Long>() { @Override public int compare(Long arg0, Long arg1) { if (arg1.longValue() > arg0.longValue()) { return 1; } else { return -1; } } }); for (Long timeId : sortList) { if (timeId < Utils.getDateByTime(time - dataExpireTime)) { continue; } Recommend.UserActiveDetail.TimeSegment.Builder timeBuilder = Recommend.UserActiveDetail.TimeSegment.newBuilder(); timeBuilder.setTimeId(timeId); int count = 0; for (String item : detailMap.get(timeId).keySet()) { count++; if (count > topNum) { break; } Recommend.UserActiveDetail.TimeSegment.ItemInfo.Builder itemBuilder = Recommend.UserActiveDetail.TimeSegment.ItemInfo.newBuilder(); itemBuilder.setItem(item); float maxWeight = 0; for (Integer act : detailMap.get(timeId).get(item).keySet()) { ActType actValue = detailMap.get(timeId).get(item).get(act); float actWeight = Utils.getActionWeight(actValue.getActType()); if (actWeight > maxWeight) { maxWeight = actWeight; } itemBuilder.addActs(actValue); } if (maxWeight > 0) { timeBuilder.addItems(itemBuilder); } } mergeValueBuilder.addTsegs(timeBuilder.build()); } }
private void mergeToHeap( ActionCombinerValue newValueList, UserActiveDetail oldValueHeap, UserActiveDetail.Builder mergeValueBuilder) { HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap = new HashMap<Long, HashMap<String, HashMap<Integer, ActType>>>(); if (oldValueHeap != null && oldValueHeap.getTsegsCount() > 0) { mergeOldToMap(oldValueHeap, detailMap); if (debug) { logger.info("add old values,now size=" + oldValueHeap.getTsegsCount()); } } for (String item : newValueList.getActRecodeMap().keySet()) { ActiveRecord action = newValueList.getActRecodeMap().get(item); Long winId = Utils.getDateByTime(action.getActTime()); mergeNewRecordsToMap(winId, item, action, detailMap); if (debug) { logger.info("add new values,size=" + detailMap.get(winId).size()); } } changeMapToPB(detailMap, mergeValueBuilder); }