use of com.alibaba.otter.manager.biz.statistics.table.param.BehaviorHistoryInfo in project otter by alibaba.
the class BehaviorHistoryCurve method execute.
public void execute(@Param("d5221") String startTime, @Param("d5222") String endTime, @Param("dataMediaPairId") Long dataMediaPairId, HttpSession session, Context context) throws Exception {
Date end = null;
Date start = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
start = new Date(System.currentTimeMillis() / 60000 * 60000 - 24 * 60 * 60 * 1000);
end = new Date(System.currentTimeMillis() / 60000 * 60000);
} else {
// 当前24小时,时间取整分钟
sdf.setLenient(false);
if (null != startTime && null != endTime) {
start = sdf.parse(startTime);
end = sdf.parse(endTime);
}
}
DataMediaPair dataMediaPair = dataMediaPairService.findById(dataMediaPairId);
Channel channel = channelService.findByPipelineId(dataMediaPair.getPipelineId());
Map<Long, BehaviorHistoryInfo> behaviourHistoryInfos = new LinkedHashMap<Long, BehaviorHistoryInfo>();
TimelineBehaviorHistoryCondition condition = new TimelineBehaviorHistoryCondition();
if (null != start && null != end) {
condition.setStart(start);
condition.setEnd(end);
condition.setPairId(dataMediaPairId);
behaviourHistoryInfos = tableStatService.listTimelineBehaviorHistory(condition);
}
Long totalInsert = 0L;
Long totalUpdate = 0L;
Long totalDelete = 0L;
Long totalFileCount = 0L;
Long totalFileSize = 0L;
for (BehaviorHistoryInfo info : behaviourHistoryInfos.values()) {
totalInsert += info.getInsertNumber();
totalUpdate += info.getUpdateNumber();
totalDelete += info.getDeleteNumber();
totalFileCount += info.getFileNumber();
totalFileSize += info.getFileSize();
}
context.put("totalInsert", totalInsert);
context.put("totalUpdate", totalUpdate);
context.put("totalDelete", totalDelete);
context.put("totalFileCount", totalFileCount);
context.put("totalFileSize", totalFileSize);
context.put("behaviourHistoryInfos", behaviourHistoryInfos);
context.put("start", sdf.format(start));
context.put("end", sdf.format(end));
context.put("dataMediaPair", dataMediaPair);
context.put("channel", channel);
}
use of com.alibaba.otter.manager.biz.statistics.table.param.BehaviorHistoryInfo in project otter by alibaba.
the class TableStatServiceImpl method listTimelineBehaviorHistory.
/**
* 列出pairId下,start-end时间段下的tableStat, 首先从数据库中取出这一段时间所有数据,该数据都是根据end_time倒排序的, 每隔1分钟将这些数据分组
*/
public Map<Long, BehaviorHistoryInfo> listTimelineBehaviorHistory(TimelineBehaviorHistoryCondition condition) {
Assert.assertNotNull(condition);
Map<Long, BehaviorHistoryInfo> behaviorHistoryInfos = new LinkedHashMap<Long, BehaviorHistoryInfo>();
List<TableHistoryStatDO> tableHistoryStatDOs = tableHistoryStatDao.listTimelineTableStat(condition);
int size = tableHistoryStatDOs.size();
int k = size - 1;
for (Long i = condition.getStart().getTime(); i <= condition.getEnd().getTime(); i += 60 * 1000) {
BehaviorHistoryInfo behaviorHistoryInfo = new BehaviorHistoryInfo();
List<TableStat> tableStat = new ArrayList<TableStat>();
// 取出每个时间点i以内的数据,k是一个游标,每次遍历时前面已经取过了的数据就不用再遍历了
for (int j = k; j >= 0; --j) {
if ((i - tableHistoryStatDOs.get(j).getEndTime().getTime() <= 60 * 1000) && (i - tableHistoryStatDOs.get(j).getEndTime().getTime() >= 0)) {
tableStat.add(tableHistoryStatDOToModel(tableHistoryStatDOs.get(j)));
k = j - 1;
} else // 如果不满足if条件,则后面的数据也不用再遍历
{
break;
}
}
if (tableStat.size() > 0) {
behaviorHistoryInfo.setItems(tableStat);
behaviorHistoryInfos.put(i, behaviorHistoryInfo);
}
}
return behaviorHistoryInfos;
}
Aggregations