use of com.att.aro.core.peripheral.pojo.GpsInfo.GpsState in project VideoOptimzer by attdevsupport.
the class EnergyModelFactoryImpl method create.
@Override
public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) {
double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0;
double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy = 0;
double totalScreenEnergy = 0;
EnergyModel model = new EnergyModel();
model.setTotalRrcEnergy(totalRrcEnergy);
// GPS Energy
Iterator<GpsInfo> gpsIter = gpsinfos.iterator();
if (gpsIter.hasNext()) {
while (gpsIter.hasNext()) {
GpsInfo gps = gpsIter.next();
GpsState gpsState = gps.getGpsState();
switch(gpsState) {
case GPS_ACTIVE:
gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp());
break;
case GPS_STANDBY:
gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp());
break;
default:
break;
}
}
}
totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy;
// Camera Energy
Iterator<CameraInfo> cameraIter = camerainfos.iterator();
if (cameraIter.hasNext()) {
while (cameraIter.hasNext()) {
CameraInfo camera = cameraIter.next();
CameraInfo.CameraState cameraState = camera.getCameraState();
if (cameraState == CameraInfo.CameraState.CAMERA_ON) {
totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp());
}
}
}
// Bluetooth Energy
Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator();
if (bluetoothIter.hasNext()) {
while (bluetoothIter.hasNext()) {
BluetoothInfo btInfo = bluetoothIter.next();
if (btInfo == null || btInfo.getBluetoothState() == null) {
continue;
}
switch(btInfo.getBluetoothState()) {
case BLUETOOTH_CONNECTED:
bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp());
break;
case BLUETOOTH_DISCONNECTED:
bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp());
break;
default:
break;
}
}
}
totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy;
// Screen Energy
Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator();
if (screenIter.hasNext()) {
while (screenIter.hasNext()) {
ScreenStateInfo screenInfo = screenIter.next();
if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) {
totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp());
}
}
}
model.setBluetoothActiveEnergy(bluetoothActiveEnergy);
model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy);
model.setGpsActiveEnergy(gpsActiveEnergy);
model.setGpsStandbyEnergy(gpsStandbyEnergy);
model.setTotalBluetoothEnergy(totalBluetoothEnergy);
model.setTotalCameraEnergy(totalCameraEnergy);
model.setTotalGpsEnergy(totalGpsEnergy);
model.setTotalRrcEnergy(totalRrcEnergy);
model.setTotalScreenEnergy(totalScreenEnergy);
return model;
}
use of com.att.aro.core.peripheral.pojo.GpsInfo.GpsState in project VideoOptimzer by attdevsupport.
the class GpsPlot method populate.
@Override
public void populate(XYPlot plot, AROTraceData analysis) {
if (analysis == null) {
LOGGER.info("analysis data is null");
return;
}
gpsData.removeAllSeries();
locationData.removeAllSeries();
TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
if (resultType.equals(TraceResultType.TRACE_FILE)) {
LOGGER.info("didn't get analysis trace data!");
} else {
try {
image = ImageIO.read(GpsPlot.class.getResourceAsStream("/images/location.png"));
image = ImageHelper.resize(image, 12, 12);
} catch (IOException e) {
e.printStackTrace();
}
// create the GPS dataset...
Map<GpsState, XYIntervalSeries> seriesMap = new EnumMap<GpsState, XYIntervalSeries>(GpsState.class);
for (GpsState eventType : GpsState.values()) {
XYIntervalSeries series = new XYIntervalSeries(eventType);
seriesMap.put(eventType, series);
gpsData.addSeries(series);
}
series = new XYSeries("location");
TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult().getTraceresult();
listLocationEvent = (ArrayList<LocationEvent>) traceresult.getLocationEventInfos();
for (int idx = 0; idx < listLocationEvent.size(); idx++) {
series.add(listLocationEvent.get(idx).getTimeRecorded(), 0.5);
}
locationData.addSeries(series);
Iterator<GpsInfo> iter = analysis.getAnalyzerResult().getTraceresult().getGpsInfos().iterator();
if (iter.hasNext()) {
while (iter.hasNext()) {
GpsInfo gpsEvent = iter.next();
if (gpsEvent.getGpsState() != GpsState.GPS_DISABLED) {
seriesMap.get(gpsEvent.getGpsState()).add(gpsEvent.getBeginTimeStamp(), gpsEvent.getBeginTimeStamp(), gpsEvent.getEndTimeStamp(), 0.5, 0, 1);
}
}
}
XYItemRenderer renderer = plot.getRenderer(0);
// Looks like renderer is using the index descending order, so setting the index of the GPS background as 2 & location information index as 1.
if (renderer == null) {
renderer = plot.getRenderer(2);
}
renderer.setSeriesPaint(gpsData.indexOf(GpsState.GPS_STANDBY), Color.YELLOW);
renderer.setSeriesPaint(gpsData.indexOf(GpsState.GPS_ACTIVE), new Color(34, 177, 76));
// Assign ToolTip to renderer
renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
GpsState eventType = (GpsState) gpsData.getSeries(series).getKey();
return MessageFormat.format(ResourceBundleHelper.getMessageString("gps.tooltip"), dataset.getX(series, item), ResourceBundleHelper.getEnumString(eventType));
}
});
plot.setRenderer(2, renderer);
// Assign ToolTip to renderer
LocationImageRenderer renderer_loc = new LocationImageRenderer();
plot.setRenderer(1, renderer_loc);
renderer_loc.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
// Update tooltip of location data
LocationEvent event = listLocationEvent.get(item);
StringBuffer displayInfo = new StringBuffer(ResourceBundleHelper.getMessageString("location.tooltip.prefix"));
displayInfo.append(MessageFormat.format(ResourceBundleHelper.getMessageString("location.tooltip.content"), event.getTimeRecorded(), event.getLatitude(), event.getLongitude(), event.getProvider(), event.getLocality()));
displayInfo.append(ResourceBundleHelper.getMessageString("location.tooltip.suffix"));
return displayInfo.toString();
}
});
}
plot.setDataset(2, gpsData);
plot.setDataset(1, locationData);
}
use of com.att.aro.core.peripheral.pojo.GpsInfo.GpsState 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;
}
Aggregations