use of org.spf4j.tsdb2.avro.ColumnDef in project spf4j by zolyfarkas.
the class TSDBQuery method getColumnNames.
public static String[] getColumnNames(final TableDef td) {
List<ColumnDef> columns = td.getColumns();
String[] result = new String[columns.size()];
int i = 0;
for (ColumnDef cd : columns) {
result[i++] = cd.getName();
}
return result;
}
use of org.spf4j.tsdb2.avro.ColumnDef in project spf4j by zolyfarkas.
the class TSDBQuery method writeAsCsv.
public static void writeAsCsv(final Appendable writer, final File tsDB, final String tableName) throws IOException {
List<TableDef> tableDefs = getTableDef(tsDB, tableName);
TimeSeries data = getTimeSeries(tsDB, getIds(tableDefs), 0, Long.MAX_VALUE);
Csv.writeCsvElement("timestamp", writer);
for (ColumnDef col : tableDefs.get(0).getColumns()) {
writer.append(',');
Csv.writeCsvElement(col.getName(), writer);
}
writer.append('\n');
long[] timestamps = data.getTimeStamps();
long[][] values = data.getValues();
for (int i = 0; i < timestamps.length; i++) {
Csv.writeCsvElement(DateTimeFormats.TS_FORMAT.format(Instant.ofEpochMilli(timestamps[i])), writer);
for (long val : values[i]) {
writer.append(',');
Csv.writeCsvElement(Long.toString(val), writer);
}
writer.append('\n');
}
}
use of org.spf4j.tsdb2.avro.ColumnDef 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.ColumnDef 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.ColumnDef 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