use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.
the class Charts method createHeatJFreeChart.
public static JFreeChart createHeatJFreeChart(final TimeSeries data, final TableDef info) {
Pair<long[], double[][]> mData = fillGaps(data.getTimeStamps(), data.getValues(), info.getSampleTime(), info.getColumns().size());
ColumnDef columnDef = TSDBQuery.getColumnDef(info, "total");
return org.spf4j.perf.impl.chart.Charts.createHeatJFreeChart(TSDBQuery.getColumnNames(info), mData.getSecond(), data.getTimeStamps()[0], info.getSampleTime(), columnDef.getUnitOfMeasurement(), "Measurements distribution for " + info.getName() + ", sampleTime " + info.getSampleTime() + "ms, generated by spf4j");
}
use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.
the class Charts method createJFreeCharts.
public static List<JFreeChart> createJFreeCharts(final TimeSeries data, final TableDef info) {
long[][] vals = data.getValues();
Map<String, Pair<List<String>, List<double[]>>> measurementsByUom = new HashMap<>();
// String[] columnMetaData = TSDBQuery.getColumnUnitsOfMeasurement(info);
int i = 0;
for (ColumnDef colDef : info.getColumns()) {
String uom = colDef.getUnitOfMeasurement();
Pair<List<String>, List<double[]>> meas = measurementsByUom.get(uom);
if (meas == null) {
meas = Pair.of((List<String>) new ArrayList<String>(), (List<double[]>) new ArrayList<double[]>());
measurementsByUom.put(uom, meas);
}
meas.getFirst().add(colDef.getName());
meas.getSecond().add(Arrays.getColumnAsDoubles(vals, i));
i++;
}
long[] timestamps = data.getTimeStamps();
List<JFreeChart> result = new ArrayList<>(measurementsByUom.size());
for (Map.Entry<String, Pair<List<String>, List<double[]>>> entry : measurementsByUom.entrySet()) {
Pair<List<String>, List<double[]>> p = entry.getValue();
final List<String> measurementNames = p.getFirst();
final List<double[]> measurements = p.getSecond();
result.add(org.spf4j.perf.impl.chart.Charts.createTimeSeriesJFreeChart("chart for " + info.getName() + ", sampleTime " + info.getSampleTime() + " ms, generated by spf4j", timestamps, measurementNames.toArray(new String[measurementNames.size()]), entry.getKey(), measurements.toArray(new double[measurements.size()][])));
}
return result;
}
use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method tail.
@SuppressFBWarnings("MDM_THREAD_YIELD")
public void tail(final long pollMillis, final long from, final TSDataHandler handler) throws IOException {
Map<String, TSTable> lastState = new HashMap<>();
long lastSize = 0;
while (!Thread.currentThread().isInterrupted() && !handler.finish()) {
long currSize = this.file.length();
if (currSize > lastSize) {
// see if we have new Tables;
reReadTableInfos();
Map<String, TSTable> currState = getTsTables();
for (String tableName : Sets.difference(currState.keySet(), lastState.keySet())) {
handler.newTable(tableName, currState.get(tableName).getColumnNames());
}
for (TSTable table : currState.values()) {
final String tableName = table.getTableName();
TSTable prevTableState = lastState.get(tableName);
final long currLastDataFragment = table.getLastDataFragment();
if (prevTableState == null) {
long lastDataFragment = table.getFirstDataFragment();
if (lastDataFragment > 0) {
TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
handler.newData(tableName, data);
}
} else {
long lastDataFragment = prevTableState.getLastDataFragment();
if (lastDataFragment == 0) {
lastDataFragment = table.getFirstDataFragment();
if (lastDataFragment > 0) {
TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
handler.newData(tableName, data);
}
} else if (currLastDataFragment > lastDataFragment) {
TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, true);
handler.newData(tableName, data);
}
}
}
lastState = currState;
}
lastSize = currSize;
try {
Thread.sleep(pollMillis);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
break;
}
}
}
use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method createHeatJFreeChart.
public JFreeChart createHeatJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
TSTable info = this.getTSTable(tableName);
TimeSeries data = this.read(tableName, startTime, endTime);
return createHeatJFreeChart(data, info);
}
use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method createCountJFreeChart.
public JFreeChart createCountJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
TSTable info = this.getTSTable(tableName);
TimeSeries data = this.read(tableName, startTime, endTime);
return createCountJFreeChart(data, info);
}
Aggregations