use of com.att.aro.core.peripheral.pojo.BluetoothInfo.BluetoothState in project VideoOptimzer by attdevsupport.
the class BluetoothInfoReaderImpl method readData.
@Override
public List<BluetoothInfo> readData(String directory, double startTime, double traceDuration) {
List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>();
this.activeBluetoothDuration = 0;
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BLUETOOTH_FILE;
if (!filereader.fileExist(filepath)) {
return bluetoothInfos;
}
double beginTime = 0.0;
double endTime;
double dLastTimeStamp = 0.0;
double dActiveDuration = 0.0;
BluetoothState prevBtState = null;
BluetoothState btState = null;
BluetoothState lastState = null;
String firstLine;
String strLineBuf;
String[] lines = null;
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed reading Bluetooth info file: " + filepath);
}
if (lines != null && lines.length > 0) {
firstLine = lines[0];
String[] strFieldsFirstLine = firstLine.split(" ");
if (strFieldsFirstLine.length == 2) {
try {
beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime);
if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFieldsFirstLine[1])) {
prevBtState = BluetoothState.BLUETOOTH_CONNECTED;
} else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFieldsFirstLine[1])) {
prevBtState = BluetoothState.BLUETOOTH_DISCONNECTED;
} else if (TraceDataConst.BLUETOOTH_OFF.equals(strFieldsFirstLine[1])) {
prevBtState = BluetoothState.BLUETOOTH_TURNED_OFF;
} else if (TraceDataConst.BLUETOOTH_ON.equals(strFieldsFirstLine[1])) {
prevBtState = BluetoothState.BLUETOOTH_TURNED_ON;
} else {
LOGGER.warn("Unknown bluetooth state: " + firstLine);
prevBtState = BluetoothState.BLUETOOTH_UNKNOWN;
}
// It is not possible for lastState to not be null at this point
// if (lastState == BluetoothState.BLUETOOTH_CONNECTED) {
// dActiveDuration += (beginTime - dLastTimeStamp);
// }
lastState = prevBtState;
dLastTimeStamp = beginTime;
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing bluetooth event: " + firstLine, e);
}
} else {
LOGGER.warn("Invalid Bluetooth trace entry: " + firstLine);
}
for (int i = 1; i < lines.length; i++) {
strLineBuf = lines[i];
String[] strFields = strLineBuf.split(" ");
if (strFields.length == 2) {
try {
endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime);
if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFields[1])) {
btState = BluetoothState.BLUETOOTH_CONNECTED;
} else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFields[1])) {
btState = BluetoothState.BLUETOOTH_DISCONNECTED;
} else if (TraceDataConst.BLUETOOTH_OFF.equals(strFields[1])) {
btState = BluetoothState.BLUETOOTH_TURNED_OFF;
} else if (TraceDataConst.BLUETOOTH_ON.equals(strFields[1])) {
btState = BluetoothState.BLUETOOTH_TURNED_ON;
} else {
LOGGER.warn("Unknown bluetooth state: " + strLineBuf);
btState = BluetoothState.BLUETOOTH_UNKNOWN;
}
bluetoothInfos.add(new BluetoothInfo(beginTime, endTime, prevBtState));
if (lastState == BluetoothState.BLUETOOTH_CONNECTED) {
dActiveDuration += (endTime - dLastTimeStamp);
}
lastState = btState;
dLastTimeStamp = endTime;
prevBtState = btState;
beginTime = endTime;
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing bluetooth event: " + strLineBuf, e);
}
} else {
LOGGER.warn("Invalid Bluetooth trace entry: " + strLineBuf);
}
}
bluetoothInfos.add(new BluetoothInfo(beginTime, traceDuration, prevBtState));
// Duration calculation should probably be done in analysis
if (lastState == BluetoothState.BLUETOOTH_CONNECTED) {
dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp);
}
this.activeBluetoothDuration = dActiveDuration;
}
return bluetoothInfos;
}
use of com.att.aro.core.peripheral.pojo.BluetoothInfo.BluetoothState in project VideoOptimzer by attdevsupport.
the class BluetoothPlot method populate.
@Override
public void populate(XYPlot plot, AROTraceData analysis) {
if (analysis != null) {
bluetoothData.removeAllSeries();
XYIntervalSeries bluetoothConnected = new XYIntervalSeries(BluetoothState.BLUETOOTH_CONNECTED);
XYIntervalSeries bluetoothDisconnected = new XYIntervalSeries(BluetoothState.BLUETOOTH_DISCONNECTED);
XYIntervalSeries bluetoothOff = new XYIntervalSeries(BluetoothState.BLUETOOTH_TURNED_OFF);
XYIntervalSeries bluetoothOn = new XYIntervalSeries(BluetoothState.BLUETOOTH_TURNED_ON);
XYIntervalSeries bluetoothUnknown = new XYIntervalSeries(BluetoothState.BLUETOOTH_UNKNOWN);
bluetoothData.addSeries(bluetoothConnected);
bluetoothData.addSeries(bluetoothDisconnected);
bluetoothData.addSeries(bluetoothOff);
bluetoothData.addSeries(bluetoothOn);
bluetoothData.addSeries(bluetoothUnknown);
// Populate the data set
Iterator<BluetoothInfo> iter = analysis.getAnalyzerResult().getTraceresult().getBluetoothInfos().iterator();
XYIntervalSeries series;
if (iter.hasNext()) {
while (iter.hasNext()) {
BluetoothInfo btEvent = iter.next();
if (btEvent.getBluetoothState() == null) {
series = bluetoothUnknown;
} else {
switch(btEvent.getBluetoothState()) {
case BLUETOOTH_CONNECTED:
series = bluetoothConnected;
break;
case BLUETOOTH_DISCONNECTED:
series = bluetoothDisconnected;
break;
case BLUETOOTH_TURNED_ON:
series = bluetoothOn;
break;
case BLUETOOTH_TURNED_OFF:
series = bluetoothOff;
break;
default:
series = bluetoothUnknown;
break;
}
}
series.add(btEvent.getBeginTimeStamp(), btEvent.getBeginTimeStamp(), btEvent.getEndTimeStamp(), 0.5, 0, 1);
}
}
XYItemRenderer renderer = plot.getRenderer();
renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_CONNECTED), new Color(34, 177, 76));
renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_DISCONNECTED), Color.YELLOW);
renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_TURNED_OFF), new Color(216, 132, 138));
renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_TURNED_ON), new Color(162, 226, 98));
renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_UNKNOWN), new Color(154, 154, 154));
// Assign ToolTip to renderer
renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
BluetoothState eventType = (BluetoothState) bluetoothData.getSeries(series).getKey();
return MessageFormat.format(ResourceBundleHelper.getMessageString("bluetooth.tooltip"), dataset.getX(series, item), ResourceBundleHelper.getEnumString(eventType));
}
});
}
plot.setDataset(bluetoothData);
// return plot;
}
Aggregations