Search in sources :

Example 1 with ColumnDef

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;
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef)

Example 2 with ColumnDef

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');
    }
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) TableDef(org.spf4j.tsdb2.avro.TableDef)

Example 3 with ColumnDef

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) JFreeChart(org.jfree.chart.JFreeChart) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.spf4j.base.Pair)

Example 4 with ColumnDef

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");
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef)

Example 5 with ColumnDef

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);
}
Also used : ArrayList(java.util.ArrayList) ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) TableDef(org.spf4j.tsdb2.avro.TableDef)

Aggregations

ColumnDef (org.spf4j.tsdb2.avro.ColumnDef)7 TableDef (org.spf4j.tsdb2.avro.TableDef)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TLongObjectMap (gnu.trove.map.TLongObjectMap)1 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JFreeChart (org.jfree.chart.JFreeChart)1 Pair (org.spf4j.base.Pair)1