@Test public void readData1() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); String[] arr = new String[] { "1.414011237411E9 UNKNOWN", "1.414011237411E9 ACTIVE", "1.414011282953E9 ACTIVE", "1.414011295886E9 PhonyState", "1.414011300035E9 ACTIVE", "1.414011311924E9 STANDBY" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); gpsEventReader.setFileReader(filereader); List<GpsInfo> info = gpsEventReader.readData("/", 0, 0); assertTrue(info.size() > 0); }
@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)); if (prevGpsState == GpsState.GPS_ACTIVE) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.gpsActiveDuration = dActiveDuration; Collections.sort(gpsInfos); } return gpsInfos; }
GpsInfoReaderImpl extends PeripheralBase implements IGpsInfoReader { @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)); if (prevGpsState == GpsState.GPS_ACTIVE) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.gpsActiveDuration = dActiveDuration; Collections.sort(gpsInfos); } return gpsInfos; } }
GpsInfoReaderImpl extends PeripheralBase implements IGpsInfoReader { @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)); if (prevGpsState == GpsState.GPS_ACTIVE) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.gpsActiveDuration = dActiveDuration; Collections.sort(gpsInfos); } return gpsInfos; }  }
GpsInfoReaderImpl extends PeripheralBase implements IGpsInfoReader { @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)); if (prevGpsState == GpsState.GPS_ACTIVE) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.gpsActiveDuration = dActiveDuration; Collections.sort(gpsInfos); } return gpsInfos; }  @Override double getGpsActiveDuration(); @Override List<GpsInfo> readData(String directory, double startTime, double traceDuration); }
GpsInfoReaderImpl extends PeripheralBase implements IGpsInfoReader { @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)); if (prevGpsState == GpsState.GPS_ACTIVE) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.gpsActiveDuration = dActiveDuration; Collections.sort(gpsInfos); } return gpsInfos; }  @Override double getGpsActiveDuration(); @Override List<GpsInfo> readData(String directory, double startTime, double traceDuration);  }