Search in sources :

Example 6 with TableDef

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);
        }
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) Dimension(java.awt.Dimension) TableDef(org.spf4j.tsdb2.avro.TableDef) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart)

Example 7 with TableDef

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);
}
Also used : TSDBWriter(org.spf4j.tsdb2.TSDBWriter) TimeSeries(org.spf4j.tsdb2.TimeSeries) File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with TableDef

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;
}
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 9 with TableDef

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

Example 10 with TableDef

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

Aggregations

TableDef (org.spf4j.tsdb2.avro.TableDef)14 ColumnDef (org.spf4j.tsdb2.avro.ColumnDef)7 DataBlock (org.spf4j.tsdb2.avro.DataBlock)6 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 IOException (java.io.IOException)2 Map (java.util.Map)2 JFreeChart (org.jfree.chart.JFreeChart)2 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)2 TSDBWriter (org.spf4j.tsdb2.TSDBWriter)2 DataRow (org.spf4j.tsdb2.avro.DataRow)2 TLongList (gnu.trove.list.TLongList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongObjectMap (gnu.trove.map.TLongObjectMap)1 Dimension (java.awt.Dimension)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1