use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method createMinMaxAvgJFreeChart.
public JFreeChart createMinMaxAvgJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
TSTable info = this.getTSTable(tableName);
TimeSeries data = this.read(tableName, startTime, endTime);
return createMinMaxAvgJFreeChart(data, info);
}
use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method createHeatJFreeChart.
public JFreeChart createHeatJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
TSTable info = this.getTSTable(tableName);
TimeSeries data = this.read(tableName, startTime, endTime);
return createHeatJFreeChart(data, info);
}
use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method generateCharts.
/**
* Quantized recorders will have min, max avg charts and distribution charts generated. Counting recorders will have
* simple charts generated.
*
* @param startTimeMillis
* @param endTimeMillis
* @param width
* @param height
* @return
* @throws IOException
*/
@JmxExport(value = "generateChartsInterval", description = "generate charts for all measurements in specified interval")
public List<String> generateCharts(final long startTimeMillis, final long endTimeMillis, final int width, final int height) throws IOException {
try {
this.flush();
Collection<TSTable> columnsInfo = this.getTSTables();
List<String> result = new ArrayList<>(16);
for (TSTable info : columnsInfo) {
TimeSeries data = this.read(info.getTableName(), startTimeMillis, endTimeMillis);
if (data.getTimeStamps().length > 0) {
if (canGenerateMinMaxAvgCount(info)) {
result.add(generateMinMaxAvgCountChart(info, data, width, height));
}
if (canGenerateHeatChart(info)) {
result.add(generateHeatChart(info, data, width, height));
}
}
}
Multimap<String, TSTable> counters = getCounters(columnsInfo);
Map<String, Collection<TSTable>> asMap = counters.asMap();
for (Map.Entry<String, Collection<TSTable>> entry : asMap.entrySet()) {
Collection<TSTable> ltables = entry.getValue();
int l = ltables.size();
long[][] timestamps = new long[l][];
double[][] cdata = new double[l][];
double[][] cdata2 = new double[l][];
int i = 0;
String[] measurementNames = new String[cdata.length];
String[] measurementNames2 = new String[cdata2.length];
String uom1 = "count";
String uom2 = "";
for (TSTable colInfo : ltables) {
TimeSeries data = this.read(colInfo.getTableName(), startTimeMillis, endTimeMillis);
timestamps[i] = data.getTimeStamps();
final long[][] values = data.getValues();
cdata[i] = Arrays.getColumnAsDoubles(values, colInfo.getColumnIndex("count"));
cdata2[i] = Arrays.getColumnAsDoubles(values, colInfo.getColumnIndex("total"));
measurementNames[i] = colInfo.getTableName() + ".count";
measurementNames2[i] = colInfo.getTableName() + ".total";
uom2 = new String(colInfo.getTableMetaData(), StandardCharsets.UTF_8);
i++;
}
result.add(generateCountChart(entry.getKey(), timestamps, measurementNames, measurementNames2, uom1, uom2, cdata, cdata2, width, height));
}
return result;
} catch (IOException | RuntimeException ex) {
throw ex;
}
}
use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method tail.
@SuppressFBWarnings("MDM_THREAD_YIELD")
public void tail(final long pollMillis, final long from, final TSDataHandler handler) throws IOException {
Map<String, TSTable> lastState = new HashMap<>();
long lastSize = 0;
while (!Thread.currentThread().isInterrupted() && !handler.finish()) {
long currSize = this.file.length();
if (currSize > lastSize) {
// see if we have new Tables;
reReadTableInfos();
Map<String, TSTable> currState = getTsTables();
for (String tableName : Sets.difference(currState.keySet(), lastState.keySet())) {
handler.newTable(tableName, currState.get(tableName).getColumnNames());
}
for (TSTable table : currState.values()) {
final String tableName = table.getTableName();
TSTable prevTableState = lastState.get(tableName);
final long currLastDataFragment = table.getLastDataFragment();
if (prevTableState == null) {
long lastDataFragment = table.getFirstDataFragment();
if (lastDataFragment > 0) {
TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
handler.newData(tableName, data);
}
} else {
long lastDataFragment = prevTableState.getLastDataFragment();
if (lastDataFragment == 0) {
lastDataFragment = table.getFirstDataFragment();
if (lastDataFragment > 0) {
TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
handler.newData(tableName, data);
}
} else if (currLastDataFragment > lastDataFragment) {
TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, true);
handler.newData(tableName, data);
}
}
}
lastState = currState;
}
lastSize = currSize;
try {
Thread.sleep(pollMillis);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
break;
}
}
}
use of com.google.api.ads.admanager.axis.v202111.TimeSeries in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method createCountJFreeChart.
public JFreeChart createCountJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
TSTable info = this.getTSTable(tableName);
TimeSeries data = this.read(tableName, startTime, endTime);
return createCountJFreeChart(data, info);
}
Aggregations