use of com.att.aro.core.peripheral.pojo.GpsInfo in project VideoOptimzer by attdevsupport.
the class GpsInfoReaderImpl method readData.
@Override
public List<GpsInfo> readData(String directory, double startTime, double traceDuration) {
this.gpsActiveDuration = 0;
List<GpsInfo> gpsInfos = new ArrayList<GpsInfo>();
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.GPS_FILE;
if (!filereader.fileExist(filepath)) {
return gpsInfos;
}
String[] lines = null;
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed to read GPS info: " + filepath);
}
if (lines == null || lines.length < 1) {
return gpsInfos;
}
double dLastActiveTimeStamp = 0.0;
double dActiveDuration = 0.0;
GpsState prevGpsState = null;
GpsState gpsState = null;
double beginTime = 0.0;
double endTime = 0.0;
String firstLine = lines[0];
if (firstLine != null) {
String[] strFieldsFirstLine = firstLine.split(" ");
if (strFieldsFirstLine.length == 2) {
try {
beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime);
if (TraceDataConst.GPS_STANDBY.equals(strFieldsFirstLine[1])) {
prevGpsState = GpsState.GPS_STANDBY;
} else if (TraceDataConst.GPS_DISABLED.equals(strFieldsFirstLine[1])) {
prevGpsState = GpsState.GPS_DISABLED;
} else if (TraceDataConst.GPS_ACTIVE.equals(strFieldsFirstLine[1])) {
prevGpsState = GpsState.GPS_ACTIVE;
if (0.0 == dLastActiveTimeStamp) {
dLastActiveTimeStamp = beginTime;
}
} else {
LOGGER.warn("Invalid GPS state: " + firstLine);
prevGpsState = GpsState.GPS_UNKNOWN;
}
if ((!TraceDataConst.GPS_ACTIVE.equals(strFieldsFirstLine[1])) && dLastActiveTimeStamp > 0.0) {
dActiveDuration += (beginTime - dLastActiveTimeStamp);
dLastActiveTimeStamp = 0.0;
}
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e);
}
}
String strLineBuf;
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.GPS_STANDBY.equals(strFields[1])) {
gpsState = GpsState.GPS_STANDBY;
} else if (TraceDataConst.GPS_DISABLED.equals(strFields[1])) {
gpsState = GpsState.GPS_DISABLED;
} else if (TraceDataConst.GPS_ACTIVE.equals(strFields[1])) {
gpsState = GpsState.GPS_ACTIVE;
if (0.0 == dLastActiveTimeStamp) {
dLastActiveTimeStamp = endTime;
}
} else {
LOGGER.warn("Invalid GPS state: " + strLineBuf);
gpsState = GpsState.GPS_UNKNOWN;
}
gpsInfos.add(new GpsInfo(beginTime, endTime, prevGpsState));
if ((!TraceDataConst.GPS_ACTIVE.equals(strFields[1])) && dLastActiveTimeStamp > 0.0) {
dActiveDuration += (endTime - dLastActiveTimeStamp);
dLastActiveTimeStamp = 0.0;
}
prevGpsState = gpsState;
beginTime = endTime;
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e);
}
} else {
LOGGER.warn("Invalid GPS trace entry: " + strLineBuf);
}
}
gpsInfos.add(new GpsInfo(beginTime, traceDuration, prevGpsState));
// Duration calculation should probably be done in analysis
if (prevGpsState == GpsState.GPS_ACTIVE) {
dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp);
}
this.gpsActiveDuration = dActiveDuration;
Collections.sort(gpsInfos);
}
return gpsInfos;
}
use of com.att.aro.core.peripheral.pojo.GpsInfo in project VideoOptimzer by attdevsupport.
the class PktAnazlyzerTimeRangeImpl method getGpsInfosForTheTimeRange.
/**
* Returns the list of gps events filtered based on the time range.
*/
private void getGpsInfosForTheTimeRange(TraceDirectoryResult result, double beginTime, double endTime) {
List<GpsInfo> orifilteredGpsInfos = result.getGpsInfos();
List<GpsInfo> filteredGpsInfos = new ArrayList<GpsInfo>();
GpsInfo filteredGpsInfo = null;
double gpsActiveDuration = 0.0;
for (GpsInfo gpsInfo : orifilteredGpsInfos) {
if (gpsInfo.getBeginTimeStamp() >= beginTime && gpsInfo.getEndTimeStamp() <= endTime) {
filteredGpsInfo = gpsInfo;
filteredGpsInfos.add(filteredGpsInfo);
if (filteredGpsInfo.getGpsState() == GpsState.GPS_ACTIVE) {
gpsActiveDuration += filteredGpsInfo.getEndTimeStamp() - filteredGpsInfo.getBeginTimeStamp();
}
} else if (gpsInfo.getBeginTimeStamp() <= beginTime && gpsInfo.getEndTimeStamp() <= endTime && gpsInfo.getEndTimeStamp() > beginTime) {
filteredGpsInfo = new GpsInfo(beginTime, gpsInfo.getEndTimeStamp(), gpsInfo.getGpsState());
filteredGpsInfos.add(filteredGpsInfo);
if (filteredGpsInfo.getGpsState() == GpsState.GPS_ACTIVE) {
gpsActiveDuration += filteredGpsInfo.getEndTimeStamp() - filteredGpsInfo.getBeginTimeStamp();
}
} else if (gpsInfo.getBeginTimeStamp() <= beginTime && gpsInfo.getEndTimeStamp() >= endTime) {
filteredGpsInfo = new GpsInfo(beginTime, endTime, gpsInfo.getGpsState());
filteredGpsInfos.add(filteredGpsInfo);
if (filteredGpsInfo.getGpsState() == GpsState.GPS_ACTIVE) {
gpsActiveDuration += filteredGpsInfo.getEndTimeStamp() - filteredGpsInfo.getBeginTimeStamp();
}
} else if (gpsInfo.getBeginTimeStamp() >= beginTime && gpsInfo.getBeginTimeStamp() < endTime && gpsInfo.getEndTimeStamp() >= endTime) {
filteredGpsInfo = new GpsInfo(gpsInfo.getBeginTimeStamp(), endTime, gpsInfo.getGpsState());
filteredGpsInfos.add(filteredGpsInfo);
if (filteredGpsInfo.getGpsState() == GpsState.GPS_ACTIVE) {
gpsActiveDuration += filteredGpsInfo.getEndTimeStamp() - filteredGpsInfo.getBeginTimeStamp();
}
}
}
result.setGpsInfos(filteredGpsInfos);
result.setGpsActiveDuration(gpsActiveDuration);
// return filteredGpsInfos;
}
use of com.att.aro.core.peripheral.pojo.GpsInfo in project VideoOptimzer by attdevsupport.
the class PktAnazlyzerTimeRangeImplTest method getTimeRangeResultTest.
@Test
public void getTimeRangeResultTest() {
TraceDirectoryResult result = new TraceDirectoryResult();
List<UserEvent> userEvents = new ArrayList<UserEvent>();
userEvents.add(new UserEvent(UserEventType.KEY_HOME, 4.0, 3.0));
result.setUserEvents(userEvents);
List<GpsInfo> gpsInfos = new ArrayList<GpsInfo>();
gpsInfos.add(new GpsInfo(0.0, 0.9, GpsState.GPS_ACTIVE));
gpsInfos.add(new GpsInfo(1.0, 4.0, GpsState.GPS_ACTIVE));
gpsInfos.add(new GpsInfo(1.4, 12.0, GpsState.GPS_ACTIVE));
gpsInfos.add(new GpsInfo(12.4, 14.0, GpsState.GPS_ACTIVE));
result.setGpsInfos(gpsInfos);
List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>();
bluetoothInfos.add(new BluetoothInfo(0.0, 3.0, BluetoothState.BLUETOOTH_CONNECTED));
bluetoothInfos.add(new BluetoothInfo(4.0, 10.0, BluetoothState.BLUETOOTH_CONNECTED));
bluetoothInfos.add(new BluetoothInfo(1.0, 13.0, BluetoothState.BLUETOOTH_DISCONNECTED));
bluetoothInfos.add(new BluetoothInfo(11.0, 16.0, BluetoothState.BLUETOOTH_CONNECTED));
result.setBluetoothInfos(bluetoothInfos);
List<CameraInfo> cameraInfos = new ArrayList<CameraInfo>();
cameraInfos.add(new CameraInfo(0.0, 1.0, CameraState.CAMERA_ON));
cameraInfos.add(new CameraInfo(3.0, 7.0, CameraState.CAMERA_ON));
cameraInfos.add(new CameraInfo(8.0, 14.0, CameraState.CAMERA_ON));
cameraInfos.add(new CameraInfo(1.0, 14.0, CameraState.CAMERA_ON));
cameraInfos.add(new CameraInfo(12.0, 15.0, CameraState.CAMERA_ON));
result.setCameraInfos(cameraInfos);
List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>();
ScreenStateInfo screenInfo01 = new ScreenStateInfo(0.0, 1.0, ScreenState.SCREEN_ON, " ", 5);
ScreenStateInfo screenInfo02 = new ScreenStateInfo(1.0, 12.0, ScreenState.SCREEN_ON, "", 3);
ScreenStateInfo screenInfo03 = new ScreenStateInfo(5.0, 9.0, ScreenState.SCREEN_ON, "", 2);
ScreenStateInfo screenInfo04 = new ScreenStateInfo(12.0, 15.0, ScreenState.SCREEN_ON, "", 4);
screenStateInfos.add(screenInfo01);
screenStateInfos.add(screenInfo02);
screenStateInfos.add(screenInfo03);
screenStateInfos.add(screenInfo04);
result.setScreenStateInfos(screenStateInfos);
List<RadioInfo> radioInfos = new ArrayList<RadioInfo>();
radioInfos.add(new RadioInfo(0.0, 3.0));
radioInfos.add(new RadioInfo(4.0, 8.0));
result.setRadioInfos(radioInfos);
List<BatteryInfo> batteryInfos = new ArrayList<BatteryInfo>();
batteryInfos.add(new BatteryInfo(3.0, true, 2, 3));
result.setBatteryInfos(batteryInfos);
List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>();
wifiInfos.add(new WifiInfo(1.0, 2.0, WifiState.WIFI_CONNECTED, "", "", ""));
wifiInfos.add(new WifiInfo(1.0, 5.0, WifiState.WIFI_CONNECTING, "", "", ""));
wifiInfos.add(new WifiInfo(1.4, 13.0, WifiState.WIFI_CONNECTING, "", "", ""));
wifiInfos.add(new WifiInfo(9.0, 13.0, WifiState.WIFI_CONNECTING, "", "", ""));
result.setWifiInfos(wifiInfos);
List<NetworkType> networkTypesList = new ArrayList<NetworkType>();
networkTypesList.add(NetworkType.LTE);
result.setNetworkTypesList(networkTypesList);
List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>();
networkTypeInfos.add(new NetworkBearerTypeInfo(1.0, 3.0, NetworkType.HSPA, NetworkType.OVERRIDE_NETWORK_TYPE_NONE));
networkTypeInfos.add(new NetworkBearerTypeInfo(8.0, 12.0, NetworkType.HSPA, NetworkType.OVERRIDE_NETWORK_TYPE_NONE));
result.setNetworkTypeInfos(networkTypeInfos);
TimeRange timeRange = new TimeRange(2.00, 11.00);
TraceDirectoryResult testResult = (TraceDirectoryResult) pktTimeUtil.getTimeRangeResult(result, timeRange);
assertEquals(1, testResult.getBatteryInfos().size());
assertEquals(2, testResult.getGpsInfos().size());
assertEquals(1, testResult.getBatteryInfos().size());
assertEquals(5, testResult.getCameraInfos().size());
assertEquals(2, testResult.getScreenStateInfos().size());
assertEquals(1, testResult.getRadioInfos().size());
assertEquals(3, testResult.getWifiInfos().size());
assertEquals(2, testResult.getNetworkTypeInfos().size());
}
Aggregations