Skip to content

Commit

Permalink
#68 Rounds the speed, altitude, and accuracy to 2 decimal places in t…
Browse files Browse the repository at this point in the history
…he CSV log file for all survey types
  • Loading branch information
christianrowlands committed Jan 2, 2025
1 parent 6fa5440 commit 8bb2da6
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -75,6 +79,8 @@ public abstract class CsvRecordLogger
this.logDirectoryName = logDirectoryName;
this.fileNamePrefix = fileNamePrefix;
this.lazyFileCreation = lazyFileCreation;

twoDecimalFormat.setRoundingMode(RoundingMode.CEILING);
}

public void onDestroy()
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 8bb2da6

Please sign in to comment.