use of org.spf4j.tsdb2.TableDefs in project spf4j by zolyfarkas.
the class TSDBQuery method getIds.
public static long[] getIds(final Collection<TableDef> tableDefs) {
long[] result = new long[tableDefs.size()];
int i = 0;
for (TableDef tdef : tableDefs) {
result[i++] = tdef.getId();
}
return result;
}
use of org.spf4j.tsdb2.TableDefs 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');
}
}