use of com.att.aro.core.peripheral.pojo.WifiInfo in project VideoOptimzer by attdevsupport.
the class WifiInfoReaderImpl method readData.
@Override
public List<WifiInfo> readData(String directory, double startTime, double traceDuration) {
this.wifiActiveDuration = 0;
List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>();
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE;
if (!filereader.fileExist(filepath)) {
return wifiInfos;
}
double dLastTimeStamp = 0.0;
double dActiveDuration = 0.0;
double beginTime = 0.0;
double endTime = 0.0;
String prevMacAddress = null;
String prevRssi = null;
String prevSsid = null;
WifiState prevWifiState = null;
WifiState lastWifiState = null;
String firstLine;
String strLineBuf;
String[] lines = null;
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed to read Wifi info file: " + filepath);
}
if (lines != null && lines.length > 0) {
firstLine = lines[0];
try {
String[] strFieldsFirstLine = firstLine.split(" ");
if (strFieldsFirstLine.length >= 2) {
beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime);
if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) {
prevWifiState = WifiState.WIFI_DISABLED;
} else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) {
prevWifiState = WifiState.WIFI_CONNECTED;
Matcher matcher = wifiPattern.matcher(firstLine);
if (matcher.lookingAt()) {
prevMacAddress = matcher.group(1);
prevRssi = matcher.group(2);
prevSsid = matcher.group(3);
} else {
LOGGER.warn("Unable to parse wifi connection params: " + firstLine);
}
} else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) {
prevWifiState = WifiState.WIFI_DISCONNECTED;
} else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) {
prevWifiState = WifiState.WIFI_CONNECTING;
} else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) {
prevWifiState = WifiState.WIFI_DISCONNECTING;
} else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) {
prevWifiState = WifiState.WIFI_SUSPENDED;
} else {
LOGGER.warn("Unknown wifi state: " + firstLine);
prevWifiState = WifiState.WIFI_UNKNOWN;
}
// FIXME Flawed logic lastWifiState is always null
// if (!prevWifiState.equals(lastWifiState)) {
// if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) {
// dActiveDuration += (beginTime - dLastTimeStamp);
// }
lastWifiState = prevWifiState;
dLastTimeStamp = beginTime;
// }
} else {
LOGGER.warn("Invalid WiFi trace entry: " + firstLine);
}
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e);
}
for (int i = 1; i < lines.length; i++) {
strLineBuf = lines[i];
String[] strFields = strLineBuf.split(" ");
try {
if (strFields.length >= 2) {
String macAddress = null;
String rssi = null;
String ssid = null;
WifiState wifiState = null;
endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime);
if (TraceDataConst.WIFI_OFF.equals(strFields[1])) {
wifiState = WifiState.WIFI_DISABLED;
} else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) {
wifiState = WifiState.WIFI_CONNECTED;
Matcher matcher = wifiPattern.matcher(strLineBuf);
if (matcher.lookingAt()) {
macAddress = matcher.group(1);
rssi = matcher.group(2);
ssid = matcher.group(3);
} else {
LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf);
}
} else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) {
wifiState = WifiState.WIFI_DISCONNECTED;
} else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) {
wifiState = WifiState.WIFI_CONNECTING;
} else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) {
wifiState = WifiState.WIFI_DISCONNECTING;
} else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) {
wifiState = WifiState.WIFI_SUSPENDED;
} else {
LOGGER.warn("Unknown wifi state: " + strLineBuf);
wifiState = WifiState.WIFI_UNKNOWN;
}
if (!wifiState.equals(lastWifiState)) {
wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid));
if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) {
dActiveDuration += (endTime - dLastTimeStamp);
}
lastWifiState = wifiState;
dLastTimeStamp = endTime;
beginTime = endTime;
prevWifiState = wifiState;
prevMacAddress = macAddress;
prevRssi = rssi;
prevSsid = ssid;
}
} else {
LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf);
}
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e);
}
}
wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid));
// Duration calculation should probably be done in analysis
if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) {
dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp);
}
this.wifiActiveDuration = dActiveDuration;
Collections.sort(wifiInfos);
}
return wifiInfos;
}
use of com.att.aro.core.peripheral.pojo.WifiInfo in project VideoOptimzer by attdevsupport.
the class WifiInfoReaderImplTest method readData_Exception_readAllLine.
@Test
public void readData_Exception_readAllLine() throws IOException {
Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenThrow(new IOException("Exception_readAllLine"));
List<WifiInfo> wifiInfos = traceDataReader.readData(traceFolder, 0, 0);
assertTrue(wifiInfos.size() == 0);
}
use of com.att.aro.core.peripheral.pojo.WifiInfo in project VideoOptimzer by attdevsupport.
the class PktAnazlyzerTimeRangeImpl method getWifiInfosForTheTimeRange.
private void getWifiInfosForTheTimeRange(TraceDirectoryResult result, double beginTime, double endTime) {
List<WifiInfo> orifilteredWifiInfos = result.getWifiInfos();
List<WifiInfo> filteredWifiInfos = new ArrayList<WifiInfo>();
for (WifiInfo wifiInfo : orifilteredWifiInfos) {
if (wifiInfo.getBeginTimeStamp() >= beginTime && wifiInfo.getEndTimeStamp() <= endTime) {
filteredWifiInfos.add(wifiInfo);
} else if (wifiInfo.getBeginTimeStamp() <= beginTime && wifiInfo.getEndTimeStamp() <= endTime && wifiInfo.getEndTimeStamp() > beginTime) {
filteredWifiInfos.add(new WifiInfo(beginTime, wifiInfo.getEndTimeStamp(), wifiInfo.getWifiState(), wifiInfo.getWifiMacAddress(), wifiInfo.getWifiRSSI(), wifiInfo.getWifiSSID()));
} else if (wifiInfo.getBeginTimeStamp() <= beginTime && wifiInfo.getEndTimeStamp() >= endTime) {
filteredWifiInfos.add(new WifiInfo(beginTime, endTime, wifiInfo.getWifiState(), wifiInfo.getWifiMacAddress(), wifiInfo.getWifiRSSI(), wifiInfo.getWifiSSID()));
} else if (wifiInfo.getBeginTimeStamp() >= beginTime && wifiInfo.getBeginTimeStamp() < endTime && wifiInfo.getEndTimeStamp() >= endTime) {
filteredWifiInfos.add(new WifiInfo(wifiInfo.getBeginTimeStamp(), endTime, wifiInfo.getWifiState(), wifiInfo.getWifiMacAddress(), wifiInfo.getWifiRSSI(), wifiInfo.getWifiSSID()));
}
}
result.setWifiInfos(filteredWifiInfos);
// return filteredWifiInfos;
}
use of com.att.aro.core.peripheral.pojo.WifiInfo in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImpl method readFileUtil.
/**
* some of the trace files read here
*
* Parses the user event trace
*
* @throws IOException
*
* Reads the screen rotations information contained in the
* "screen_rotations" file found inside the trace directory and adds
* them to the user events list.
* @throws IOException
* Reads the CPU trace information from the CPU file.
*
* @throws IOException
* Method to read the GPS data from the trace file and store it in
* the gpsInfos list. It also updates the active duration for GPS.
* Method to read the Bluetooth data from the trace file and store
* it in the bluetoothInfos list. It also updates the active
* duration for Bluetooth.
*
* @throws IOException
* Method to read the Camera data from the trace file and store it
* in the cameraInfos list. It also updates the active duration for
* Camera.
*
* Method to read the WIFI data from the trace file and store it in
* the wifiInfos list. It also updates the active duration for Wifi.
*
* Method to read the Screen State data from the trace file and
* store it in the ScreenStateInfos list.
*
* Method to read the Battery data from the trace file and store it
* in the batteryInfos list.
*
* Method to read the alarm event from the trace file and store it
* in the alarmInfos list.
*
* Reads the Radio data from the file and stores it in the
* RadioInfo.
* @param result
*/
public void readFileUtil(TraceDirectoryResult result) {
NetworkTypeObject obj = networktypereader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
if (obj != null) {
result.setNetworkTypeInfos(obj.getNetworkTypeInfos());
result.setNetworkTypesList(obj.getNetworkTypesList());
}
CollectOptions collectOptions = collectOptionsReader.readData(result.getTraceDirectory());
result.setCollectOptions(collectOptions);
List<UserEvent> userEvents = usereventreader.readData(result.getTraceDirectory(), result.getEventTime0(), result.getPcapTime0());
result.setUserEvents(userEvents);
List<UserEvent> list = this.screenrotationreader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setScreenRotationCounter(list.size());
result.getUserEvents().addAll(list);
List<TemperatureEvent> temperatureEvents = cputemperaturereader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setTemperatureInfos(temperatureEvents);
List<LocationEvent> locationEvents = locationreader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setLocationEventInfos(locationEvents);
CpuActivityList cpuActivityList = cpureader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setCpuActivityList(cpuActivityList);
List<GpsInfo> gpsInfos = gpsreader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setGpsInfos(gpsInfos);
result.setGpsActiveDuration(gpsreader.getGpsActiveDuration());
List<BluetoothInfo> bluetoothInfos = bluetoothreader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setBluetoothInfos(bluetoothInfos);
result.setBluetoothActiveDuration(bluetoothreader.getBluetoothActiveDuration());
List<WifiInfo> wifiInfos = wifireader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setWifiInfos(wifiInfos);
result.setWifiActiveDuration(wifireader.getWifiActiveDuration());
List<CameraInfo> cameraInfos = camerareader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setCameraInfos(cameraInfos);
result.setCameraActiveDuration(camerareader.getActiveDuration());
List<ThermalStatusInfo> thermalStatusInfos = new ThermalStatusReaderImpl(filereader).readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setThermalstatusInfos(thermalStatusInfos);
List<ScreenStateInfo> screenStateInfos = screenstatereader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setScreenStateInfos(screenStateInfos);
List<BatteryInfo> batteryInfos = batteryinforeader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setBatteryInfos(batteryInfos);
// alarm info from kernel log file
List<AlarmInfo> alarmInfos = alarminforeader.readData(result.getTraceDirectory(), result.getDumpsysEpochTimestamp(), result.getDumpsysElapsedTimestamp(), result.getTraceDateTime());
result.setAlarmInfos(alarmInfos);
List<RadioInfo> radioInfos = radioinforeader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setRadioInfos(radioInfos);
VideoStreamStartupData videoStreamStartupData = videoStartupReader.readData(result.getTraceDirectory());
result.setVideoStartupData(videoStreamStartupData);
result.setMetaData(metaDataReadWrite.readData(result.getTraceDirectory()));
}
use of com.att.aro.core.peripheral.pojo.WifiInfo in project VideoOptimzer by attdevsupport.
the class WifiPlot method populate.
@Override
public void populate(XYPlot plot, AROTraceData analysis) {
wifiData = new XYIntervalSeriesCollection();
if (analysis == null) {
LOGGER.info("didn't get analysis trace data! ");
} else {
TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
if (resultType.equals(TraceResultType.TRACE_FILE)) {
LOGGER.info("it is not contain the file ");
} else {
TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult().getTraceresult();
Map<WifiState, XYIntervalSeries> seriesMap = new EnumMap<WifiState, XYIntervalSeries>(WifiState.class);
for (WifiState eventType : WifiState.values()) {
XYIntervalSeries series = new XYIntervalSeries(eventType);
seriesMap.put(eventType, series);
switch(eventType) {
case WIFI_UNKNOWN:
case WIFI_DISABLED:
// Don't chart these
break;
default:
wifiData.addSeries(series);
break;
}
}
// Populate the data set
List<WifiInfo> wifiInfos = traceresult.getWifiInfos();
final Map<Double, WifiInfo> eventMap = new HashMap<Double, WifiInfo>(wifiInfos.size());
Iterator<WifiInfo> iter = wifiInfos.iterator();
if (iter.hasNext()) {
while (iter.hasNext()) {
WifiInfo wifiEvent = iter.next();
seriesMap.get(wifiEvent.getWifiState()).add(wifiEvent.getBeginTimeStamp(), wifiEvent.getBeginTimeStamp(), wifiEvent.getEndTimeStamp(), 0.5, 0, 1);
eventMap.put(wifiEvent.getBeginTimeStamp(), wifiEvent);
}
}
XYItemRenderer renderer = plot.getRenderer();
for (WifiState eventType : WifiState.values()) {
Color paint;
switch(eventType) {
case WIFI_CONNECTED:
case WIFI_CONNECTING:
case WIFI_DISCONNECTING:
paint = new Color(34, 177, 76);
break;
case WIFI_DISCONNECTED:
case WIFI_SUSPENDED:
paint = Color.YELLOW;
break;
default:
paint = Color.WHITE;
break;
}
int index = wifiData.indexOf(eventType);
if (index >= 0) {
renderer.setSeriesPaint(index, paint);
}
}
// Assign ToolTip to renderer
renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
WifiState eventType = (WifiState) wifiData.getSeries(series).getKey();
StringBuffer message = new StringBuffer(ResourceBundleHelper.getMessageString("wifi.tooltip.prefix"));
message.append(MessageFormat.format(ResourceBundleHelper.getMessageString("wifi.tooltip"), dataset.getX(series, item), ResourceBundleHelper.getEnumString(eventType)));
switch(eventType) {
case WIFI_CONNECTED:
WifiInfo info = eventMap.get(dataset.getX(series, item));
if (info != null && info.getWifiState() == WifiState.WIFI_CONNECTED) {
message.append(MessageFormat.format(ResourceBundleHelper.getMessageString("wifi.connTooltip"), info.getWifiMacAddress(), info.getWifiRSSI(), info.getWifiSSID()));
}
break;
default:
break;
}
message.append(ResourceBundleHelper.getMessageString("wifi.tooltip.suffix"));
return message.toString();
}
});
}
}
plot.setDataset(wifiData);
// return plot;
}
Aggregations