}
public static Heatmap getHeatmap(String tableName, String family, String column,
long startTime, long endTime, double max, double scale, int height) {
final long MINUTE = TimeUnit.MINUTES.toMillis(1);
Heatmap heatmap = new Heatmap();
HTableInterface table = pool.getTable(tableName);
try {
Scan scan = new Scan();
ColumnPrefixFilter cpf = new ColumnPrefixFilter(column.getBytes());
scan.addFamily(family.getBytes());
scan.setFilter(cpf);
scan.setTimeRange(startTime, endTime);
scan.setBatch(10000);
ResultScanner results = table.getScanner(scan);
Iterator<Result> it = results.iterator();
int index = 0;
// Series display in y axis
int y = 0;
HashMap<String, Integer> keyMap = new HashMap<String, Integer>();
while(it.hasNext()) {
Result result = it.next();
List<KeyValue> kvList = result.list();
for(KeyValue kv : kvList) {
String key = parseRowKey(result.getRow());
StringBuilder tmp = new StringBuilder();
tmp.append(key);
tmp.append(":");
tmp.append(new String(kv.getQualifier()));
String seriesName = tmp.toString();
long time = parseTime(result.getRow());
// Time display in x axis
int x = (int) ((time - startTime) / MINUTE);
if(keyMap.containsKey(seriesName)) {
y = keyMap.get(seriesName);
} else {
keyMap.put(seriesName, new Integer(index));
y = index;
index++;
}
double v = Double.parseDouble(new String(kv.getValue()));
heatmap.put(x, y, v);
if(v > max) {
max = v;
}
}
}
results.close();
table.close();
int radius = height / index;
// Usually scale max from 0 to 100 for visualization
heatmap.putMax(scale);
for(HeatMapPoint point : heatmap.getHeatmap()) {
double round = point.count / max * scale;
round = Math.round(round * 100.0) / 100.0;
point.put(point.x, point.y * radius, round);
}
heatmap.putRadius(radius);
heatmap.putSeries(index);
} catch (IOException e) {
log.error(ExceptionUtil.getStackTrace(e));
}
return heatmap;
}