use of org.spf4j.perf.TimeSeriesRecord in project spf4j by zolyfarkas.
the class TableDefs method toRecord.
public static TimeSeriesRecord toRecord(final Schema rSchema, final Observation row) {
GenericRecord rec = new GenericData.Record(rSchema);
rec.put(0, Instant.ofEpochMilli(row.getRelTimeStamp()));
List<Long> nrs = row.getData();
List<Schema.Field> fields = rSchema.getFields();
for (int i = 1, l = fields.size(), j = 0; i < l; i++, j++) {
Schema.Type type = fields.get(i).schema().getType();
switch(type) {
case DOUBLE:
rec.put(i, Double.longBitsToDouble(nrs.get(j)));
break;
case LONG:
rec.put(i, nrs.get(j));
break;
default:
throw new IllegalStateException("Unsupported data type: " + type);
}
}
return TimeSeriesRecord.from(rec);
}
use of org.spf4j.perf.TimeSeriesRecord in project spf4j by zolyfarkas.
the class MStoreViewJInternalFrame method exportButtonActionPerformed.
// GEN-LAST:event_plotButtonActionPerformed
@SuppressFBWarnings("UP_UNUSED_PARAMETER")
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_exportButtonActionPerformed
TreePath[] selectionPaths = measurementTree.getSelectionPaths();
Set<Schema> selectedTables = getSelectedTables(selectionPaths);
if (!selectedTables.isEmpty()) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
int returnVal = chooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
for (Schema metric : selectedTables) {
try (AvroCloseableIterable<TimeSeriesRecord> obs = reader.getMeasurementData(metric, Instant.EPOCH, Instant.now())) {
CsvWriter writer = Csv.CSV.writer(Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8));
CsvEncoder encoder = new CsvEncoder(writer, Schema.createArray(metric));
encoder.writeHeader();
GenericDatumWriter dw = new GenericDatumWriter(metric);
for (TimeSeriesRecord o : obs) {
dw.write(o, encoder);
}
encoder.flush();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
}
}
}
use of org.spf4j.perf.TimeSeriesRecord in project spf4j by zolyfarkas.
the class TSDBQueryTest method testTsDbQuery.
@Test
public void testTsDbQuery() throws IOException {
File testFile = File.createTempFile("test", ".tsdb2");
try (TSDBWriter writer = new TSDBWriter(testFile, 4, "test", false)) {
long tableId = writer.writeTableDef(tableDef);
writer.writeDataRow(tableId, System.currentTimeMillis(), 0, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 1, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 2, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 3, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 4, 1, 2);
writer.flush();
writer.writeDataRow(tableId, System.currentTimeMillis(), 0, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 1, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 2, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 3, 1, 2);
writer.writeDataRow(tableId, System.currentTimeMillis(), 4, 1, 2);
}
try (CloseableIterable<TimeSeriesRecord> res = TSDBQuery.getTimeSeriesData(testFile, "test", System.currentTimeMillis() - 10000, System.currentTimeMillis())) {
int i = 0;
for (TimeSeriesRecord rec : res) {
LOG.debug("measurement", rec);
i++;
}
Assert.assertEquals(10, i);
}
}
use of org.spf4j.perf.TimeSeriesRecord in project spf4j by zolyfarkas.
the class AvroMeasurementStoreTest method getMetrics.
public static List<TimeSeriesRecord> getMetrics(final MeasurementStoreQuery query, final Schema metric, final Instant from, final Instant to, final int aggMillis) throws IOException {
List<TimeSeriesRecord> results = new ArrayList<>();
try (AvroCloseableIterable<TimeSeriesRecord> data = query.getAggregatedMeasurementData(metric, from, to, aggMillis, TimeUnit.MILLISECONDS)) {
for (TimeSeriesRecord rec : data) {
LOG.debug("agg", rec);
results.add(rec);
}
}
return results;
}
use of org.spf4j.perf.TimeSeriesRecord in project spf4j by zolyfarkas.
the class TableDefs method toRecord.
public static TimeSeriesRecord toRecord(final Schema rSchema, final long baseTs, final DataRow row) {
GenericRecord rec = new GenericData.Record(rSchema);
long ts = baseTs + row.getRelTimeStamp();
rec.put(0, Instant.ofEpochMilli(ts));
List<Long> nrs = row.getData();
List<Schema.Field> fields = rSchema.getFields();
for (int i = 1, l = fields.size(), j = 0; i < l; i++, j++) {
Schema.Type type = fields.get(i).schema().getType();
switch(type) {
case DOUBLE:
rec.put(i, Double.longBitsToDouble(nrs.get(j)));
break;
case LONG:
rec.put(i, nrs.get(j));
break;
default:
throw new IllegalStateException("Unsupported data type: " + type);
}
}
return TimeSeriesRecord.from(rec);
}
Aggregations