From 8bb2da60c1d13ff6236b2876615889388c4adbda Mon Sep 17 00:00:00 2001 From: christianrowlands Date: Thu, 2 Jan 2025 09:04:40 -0500 Subject: [PATCH] #68 Rounds the speed, altitude, and accuracy to 2 decimal places in the CSV log file for all survey types --- .../logging/BluetoothCsvLogger.java | 6 +++--- .../networksurvey/logging/CdmaCsvLogger.java | 6 +++--- .../logging/CsvRecordLogger.java | 19 ++++++++++++++++++- .../logging/DeviceStatusCsvLogger.java | 14 +++++++------- .../networksurvey/logging/GnssCsvLogger.java | 6 +++--- .../networksurvey/logging/GsmCsvLogger.java | 6 +++--- .../networksurvey/logging/LteCsvLogger.java | 6 +++--- .../networksurvey/logging/NrCsvLogger.java | 6 +++--- .../logging/PhoneStateCsvLogger.java | 6 +++--- .../networksurvey/logging/UmtsCsvLogger.java | 6 +++--- .../networksurvey/logging/WifiCsvLogger.java | 6 +++--- 11 files changed, 52 insertions(+), 35 deletions(-) diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/BluetoothCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/BluetoothCsvLogger.java index 3f57272b..c0ec6830 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/BluetoothCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/BluetoothCsvLogger.java @@ -106,9 +106,9 @@ private String[] convertToObjectArray(BluetoothRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), data.getSourceAddress(), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CdmaCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CdmaCsvLogger.java index 58510cfe..a26b505c 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CdmaCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CdmaCsvLogger.java @@ -84,9 +84,9 @@ private String[] convertToObjectArray(CdmaRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), String.valueOf(data.getGroupNumber()), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CsvRecordLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CsvRecordLogger.java index c6831f2d..8e74447b 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CsvRecordLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/CsvRecordLogger.java @@ -18,8 +18,10 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.math.RoundingMode; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.DecimalFormat; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; @@ -46,6 +48,8 @@ public abstract class CsvRecordLogger */ protected final Object csvFileLock = new Object(); + private final DecimalFormat twoDecimalFormat = new DecimalFormat("#.##"); + private Context applicationContext; final Handler handler; private final String logDirectoryName; @@ -75,6 +79,8 @@ public abstract class CsvRecordLogger this.logDirectoryName = logDirectoryName; this.fileNamePrefix = fileNamePrefix; this.lazyFileCreation = lazyFileCreation; + + twoDecimalFormat.setRoundingMode(RoundingMode.CEILING); } public void onDestroy() @@ -428,7 +434,7 @@ public void reset() } /** - * Trims a double (location) to six decimal places. + * Trims a double (location) to six decimal places, not removing extra zeros. * * @param value The double to trim. * @return The trimmed double as a string. @@ -437,4 +443,15 @@ String trimToSixDecimalPlaces(double value) { return String.format(Locale.getDefault(), "%.6f", value); } + + /** + * Rounds a double to 2 decimal places, removing extra zeros. + * + * @param value The double to round. + * @return The rounded double as a string. + */ + String roundToTwoDecimalPlaces(double value) + { + return twoDecimalFormat.format(value); + } } diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/DeviceStatusCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/DeviceStatusCsvLogger.java index cde83a96..2617ae94 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/DeviceStatusCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/DeviceStatusCsvLogger.java @@ -88,20 +88,20 @@ private String[] convertToObjectArray(DeviceStatus record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.hasBatteryLevelPercent() ? String.valueOf(data.getBatteryLevelPercent().getValue()) : "", hasGnssLocation ? trimToSixDecimalPlaces(gnssLatitude) : "", hasGnssLocation ? trimToSixDecimalPlaces(gnssLongitude) : "", - hasGnssLocation ? String.valueOf(data.getGnssAltitude()) : "", - hasGnssLocation ? String.valueOf(data.getGnssAccuracy()) : "", + hasGnssLocation ? roundToTwoDecimalPlaces(data.getGnssAltitude()) : "", + hasGnssLocation ? roundToTwoDecimalPlaces(data.getGnssAccuracy()) : "", hasNetworkLocation ? trimToSixDecimalPlaces(networkLatitude) : "", hasNetworkLocation ? trimToSixDecimalPlaces(networkLongitude) : "", - hasNetworkLocation ? String.valueOf(data.getNetworkAltitude()) : "", - hasNetworkLocation ? String.valueOf(data.getNetworkAccuracy()) : "", + hasNetworkLocation ? roundToTwoDecimalPlaces(data.getNetworkAltitude()) : "", + hasNetworkLocation ? roundToTwoDecimalPlaces(data.getNetworkAccuracy()) : "", data.getDeviceSerialNumber() }; } diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GnssCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GnssCsvLogger.java index 23e92ca4..646ca2b3 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GnssCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GnssCsvLogger.java @@ -89,9 +89,9 @@ private String[] convertToObjectArray(GnssRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), String.valueOf(data.getGroupNumber()), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GsmCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GsmCsvLogger.java index 2b7d8a1f..c2b907d4 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GsmCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/GsmCsvLogger.java @@ -84,9 +84,9 @@ private String[] convertToObjectArray(GsmRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), String.valueOf(data.getGroupNumber()), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/LteCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/LteCsvLogger.java index 14ccfb78..f242fa2a 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/LteCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/LteCsvLogger.java @@ -92,9 +92,9 @@ private String[] convertToObjectArray(LteRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), String.valueOf(data.getGroupNumber()), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/NrCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/NrCsvLogger.java index a7ef0bbc..a06e1ddd 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/NrCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/NrCsvLogger.java @@ -89,9 +89,9 @@ private String[] convertToObjectArray(NrRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), String.valueOf(data.getGroupNumber()), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/PhoneStateCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/PhoneStateCsvLogger.java index 3af90e33..805f1aa7 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/PhoneStateCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/PhoneStateCsvLogger.java @@ -125,9 +125,9 @@ private String[] convertToObjectArray(PhoneState record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), simState, diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/UmtsCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/UmtsCsvLogger.java index b325a82d..359e3a4a 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/UmtsCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/UmtsCsvLogger.java @@ -85,9 +85,9 @@ private String[] convertToObjectArray(UmtsRecord record) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), String.valueOf(data.getGroupNumber()), diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/WifiCsvLogger.java b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/WifiCsvLogger.java index 9878b5f9..c141338b 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/logging/WifiCsvLogger.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/logging/WifiCsvLogger.java @@ -115,9 +115,9 @@ private String[] convertToObjectArray(WifiRecordWrapper wrapper) data.getDeviceTime(), trimToSixDecimalPlaces(data.getLatitude()), trimToSixDecimalPlaces(data.getLongitude()), - String.valueOf(data.getAltitude()), - String.valueOf(data.getSpeed()), - String.valueOf(data.getAccuracy()), + roundToTwoDecimalPlaces(data.getAltitude()), + roundToTwoDecimalPlaces(data.getSpeed()), + roundToTwoDecimalPlaces(data.getAccuracy()), data.getMissionId(), String.valueOf(data.getRecordNumber()), data.getSourceAddress(),