Source:
<code>private static SummaryReport calculateSummaryResult(long deviceId, Date from, Date to) throws SQLException { boolean ignoreOdometerConfig = Context.getConfig().getBoolean(ReportUtils.IGNORE_ODOMETER); SummaryReport result = new SummaryReport(); Device device = Context.getDeviceManager().getDeviceById(deviceId); result.setDeviceId(deviceId); result.setDeviceName(device.getName()); Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to); if (positions != null && !positions.isEmpty()) { Position firstPosition = null; Position previousPosition = null; double speedSum = 0; for (Position position : positions) { if (firstPosition == null) { firstPosition = position; } if (previousPosition != null && position.getAttributes().get(Position.KEY_IGNITION) != null && Boolean.parseBoolean(position.getAttributes().get(Position.KEY_IGNITION).toString()) && previousPosition.getAttributes().get(Position.KEY_IGNITION) != null && Boolean.parseBoolean(previousPosition.getAttributes() .get(Position.KEY_IGNITION).toString())) { result.addEngineHours(position.getFixTime().getTime() - previousPosition.getFixTime().getTime()); } previousPosition = position; speedSum += position.getSpeed(); result.setMaxSpeed(position.getSpeed()); } boolean ignoreOdometer = false; <START> if (device.getAttributes().containsKey(ReportUtils.IGNORE_ODOMETER)) { <END> ignoreOdometer = Boolean.parseBoolean(device.getAttributes() .get(ReportUtils.IGNORE_ODOMETER).toString()); } else { ignoreOdometer = ignoreOdometerConfig; } result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer)); result.setAverageSpeed(speedSum / positions.size()); } return result; }</code><technical_language>nice move this functionality in common place useful in multiple places. For example, similar for GT06 protocol encoder</technical_language>

Target:
private static SummaryReport calculateSummaryResult(long deviceId, Date from, Date to) throws SQLException { SummaryReport result = new SummaryReport(); result.setDeviceId(deviceId); result.setDeviceName(Context.getIdentityManager().getDeviceById(deviceId).getName()); Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to); if (positions != null && !positions.isEmpty()) { Position firstPosition = null; Position previousPosition = null; double speedSum = 0; for (Position position : positions) { if (firstPosition == null) { firstPosition = position; } if (previousPosition != null && position.getAttributes().get(Position.KEY_IGNITION) != null && Boolean.parseBoolean(position.getAttributes().get(Position.KEY_IGNITION).toString()) && previousPosition.getAttributes().get(Position.KEY_IGNITION) != null && Boolean.parseBoolean(previousPosition.getAttributes() .get(Position.KEY_IGNITION).toString())) { result.addEngineHours(position.getFixTime().getTime() - previousPosition.getFixTime().getTime()); } previousPosition = position; speedSum += position.getSpeed(); result.setMaxSpeed(position.getSpeed()); } boolean ignoreOdometer = Context.getDeviceManager() .lookupConfigBoolean(deviceId, "report.ignoreOdometer", false); result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer)); result.setAverageSpeed(speedSum / positions.size()); } return result; }