use of org.spf4j.tsdb2.avro.TableDef in project spf4j by zolyfarkas.
the class TSDB2ViewJInternalFrame method addChartToPanel.
private void addChartToPanel(final String tableName, final JPanel content) throws IOException {
List<TableDef> info = TSDBQuery.getTableDef(tsDb, tableName);
long startTime = ((Date) startDate.getValue()).getTime();
long endTime = ((Date) endDate.getValue()).getTime();
if (Charts.canGenerateHeatChart(info.get(0))) {
JFreeChart chart = Charts.createHeatJFreeChart(tsDb, info, startTime, endTime);
ChartPanel pannel = new ChartPanel(chart);
pannel.setPreferredSize(new Dimension(600, 800));
pannel.setDomainZoomable(false);
pannel.setMouseZoomable(false);
pannel.setRangeZoomable(false);
pannel.setZoomAroundAnchor(false);
pannel.setZoomInFactor(1);
pannel.setZoomOutFactor(1);
content.add(pannel);
}
if (Charts.canGenerateMinMaxAvgCount(info.get(0))) {
JFreeChart chart = Charts.createMinMaxAvgJFreeChart(tsDb, info, startTime, endTime);
ChartPanel pannel = new ChartPanel(chart);
pannel.setPreferredSize(new Dimension(600, 600));
content.add(pannel);
}
if (Charts.canGenerateCount(info.get(0))) {
JFreeChart chart = Charts.createCountJFreeChart(tsDb, info, startTime, endTime);
ChartPanel pannel = new ChartPanel(chart);
pannel.setPreferredSize(new Dimension(600, 600));
content.add(pannel);
} else {
List<JFreeChart> createJFreeCharts = Charts.createJFreeCharts(tsDb, info, startTime, endTime);
for (JFreeChart chart : createJFreeCharts) {
ChartPanel pannel = new ChartPanel(chart);
pannel.setPreferredSize(new Dimension(600, 600));
content.add(pannel);
}
}
}
use of org.spf4j.tsdb2.avro.TableDef in project spf4j by zolyfarkas.
the class RecorderFactoryTest method assertData.
@SuppressFBWarnings("CLI_CONSTANT_LIST_INDEX")
public static void assertData(final String forWhat, final long expectedValue) throws IOException {
TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
dbWriter.flush();
final File file = dbWriter.getFile();
List<TableDef> tableDefs = TSDBQuery.getTableDef(file, forWhat);
TableDef tableDef = tableDefs.get(0);
TimeSeries timeSeries = TSDBQuery.getTimeSeries(file, new long[] { tableDef.id }, 0, Long.MAX_VALUE);
long sum = 0;
long[][] values = timeSeries.getValues();
for (long[] row : values) {
sum += row[0];
}
Assert.assertEquals(expectedValue, sum);
}
use of org.spf4j.tsdb2.avro.TableDef 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.avro.TableDef 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.avro.TableDef in project spf4j by zolyfarkas.
the class TSDBMeasurementStore method alocateMeasurements.
@Override
public long alocateMeasurements(final MeasurementsInfo measurement, final int sampleTimeMillis) throws IOException {
TableDef td = TableDef.newBuilder().setName(measurement.getMeasuredEntity().toString()).setSampleTime(sampleTimeMillis).setId(-1).build();
int numberOfMeasurements = measurement.getNumberOfMeasurements();
List<ColumnDef> columns = new ArrayList<>(numberOfMeasurements);
for (int i = 0; i < numberOfMeasurements; i++) {
String mname = measurement.getMeasurementName(i);
String unit = measurement.getMeasurementUnit(i);
ColumnDef cd = new ColumnDef();
cd.name = mname;
cd.unitOfMeasurement = unit;
cd.type = Type.LONG;
cd.description = "";
columns.add(cd);
}
td.columns = columns;
return database.writeTableDef(td);
}
Aggregations