mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Fix json format for GC
Change month format in ride headder Make sure numbers are formatted correctly ie not scientific notation Log all current values: Perviously it only logged values that were measured. However, if GC doesn't see the other values it assumes they are zero.
This commit is contained in:
@@ -30,6 +30,7 @@ public class StartActivity extends FragmentActivity
|
||||
public static final String PAIRED_ANTS = "PairedAnts";
|
||||
SharedPreferences settings;
|
||||
AlertDialog dialog;
|
||||
public MultiDeviceSearch mSearch;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
@@ -78,7 +79,6 @@ public class StartActivity extends FragmentActivity
|
||||
|
||||
protected void setupAnt() {
|
||||
|
||||
MultiDeviceSearch mSearch;
|
||||
MultiDeviceSearch.SearchCallbacks mCallback;
|
||||
MultiDeviceSearch.RssiCallback mRssiCallback;
|
||||
final ArrayList<MultiDeviceSearchResult> foundDevices = new ArrayList<MultiDeviceSearchResult>();
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.ridelogger.RideService;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -76,34 +77,112 @@ public class Base
|
||||
|
||||
public void writeData(Map<String, String> map)
|
||||
{
|
||||
String ts = String.valueOf((double) (System.currentTimeMillis() - start_time) / 1000.0);
|
||||
current_values.put("SECS", ts);
|
||||
String ts = String.valueOf((double) (System.currentTimeMillis() - start_time) / 1000.0);
|
||||
current_values.put("SECS", ts);
|
||||
|
||||
try {
|
||||
synchronized (buf) {
|
||||
buf.write(",{");
|
||||
try {
|
||||
synchronized (buf) {
|
||||
buf.write(",{");
|
||||
|
||||
buf.write("\"");
|
||||
buf.write("SECS");
|
||||
buf.write("\":");
|
||||
buf.write(ts);
|
||||
|
||||
for (Map.Entry<String, String> entry : map.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
|
||||
buf.write("\"");
|
||||
buf.write("SECS");
|
||||
buf.write(",\"");
|
||||
buf.write(key);
|
||||
buf.write("\":");
|
||||
buf.write(ts);
|
||||
buf.write(value);
|
||||
|
||||
for (Map.Entry<String, String> entry : map.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
|
||||
buf.write(",\"");
|
||||
buf.write(key);
|
||||
buf.write("\":");
|
||||
buf.write(value);
|
||||
|
||||
current_values.put(key, value);
|
||||
}
|
||||
|
||||
buf.write("}");
|
||||
current_values.put(key, value);
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
|
||||
buf.write("}");
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
|
||||
public void alterCurrentData(String key, String value)
|
||||
{
|
||||
synchronized (current_values) {
|
||||
current_values.put("SECS", getTs());
|
||||
current_values.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void alterCurrentData(Map<String, String> map)
|
||||
{
|
||||
synchronized (current_values) {
|
||||
current_values.put("SECS", getTs());
|
||||
|
||||
for (Map.Entry<String, String> entry : map.entrySet())
|
||||
{
|
||||
current_values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeCurrentData()
|
||||
{
|
||||
try {
|
||||
synchronized (buf) {
|
||||
buf.write(",{");
|
||||
|
||||
for (Map.Entry<String, String> entry : current_values.entrySet())
|
||||
{
|
||||
buf.write(",\"");
|
||||
buf.write(entry.getKey());
|
||||
buf.write("\":");
|
||||
buf.write(entry.getValue());
|
||||
}
|
||||
|
||||
buf.write("}");
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
|
||||
public String getTs() {
|
||||
return reduceNumberToString((double) (System.currentTimeMillis() - start_time) / 1000.0);
|
||||
}
|
||||
|
||||
|
||||
public static String reduceNumberToString(double d)
|
||||
{
|
||||
if(d == (long) d)
|
||||
return String.format("%d",(long)d);
|
||||
else
|
||||
return String.format("%f", d);
|
||||
}
|
||||
|
||||
|
||||
public static String reduceNumberToString(float d)
|
||||
{
|
||||
if(d == (long) d)
|
||||
return String.format("%d",(long)d);
|
||||
else
|
||||
return String.format("%f", d);
|
||||
}
|
||||
|
||||
|
||||
public static String reduceNumberToString(BigDecimal d)
|
||||
{
|
||||
try {
|
||||
long test = d.longValueExact();
|
||||
return String.format("%d", test);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
return String.format("%s", d.toPlainString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ public class Gps extends Base
|
||||
LocationListener locationListener = new LocationListener() {
|
||||
public void onLocationChanged(Location location) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("ALTITUDE", Double.toString(location.getAltitude()) );
|
||||
map.put("KPH", Float.toString( location.getSpeed()) );
|
||||
map.put("bearing", Float.toString( location.getBearing()) );
|
||||
map.put("gpsa", Float.toString( location.getAccuracy()) );
|
||||
map.put("LAT", Double.toString(location.getLatitude()) );
|
||||
map.put("LON", Double.toString(location.getLongitude()));
|
||||
writeData(map);
|
||||
map.put("ALTITUDE", reduceNumberToString(location.getAltitude()) );
|
||||
map.put("KPH", reduceNumberToString(location.getSpeed()) );
|
||||
map.put("bearing", reduceNumberToString(location.getBearing()) );
|
||||
map.put("gpsa", reduceNumberToString(location.getAccuracy()) );
|
||||
map.put("LAT", reduceNumberToString(location.getLatitude()) );
|
||||
map.put("LON", reduceNumberToString(location.getLongitude()));
|
||||
alterCurrentData(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ public class HeartRate extends Base
|
||||
new IHeartRateDataReceiver() {
|
||||
@Override
|
||||
public void onNewHeartRateData(final long estTimestamp, EnumSet<EventFlag> eventFlags, final int computedHeartRate, final long heartBeatCount, final BigDecimal heartBeatEventTime, final DataState dataState) {
|
||||
writeData("HR", String.valueOf(computedHeartRate));
|
||||
alterCurrentData("HR", reduceNumberToString(computedHeartRate));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Power extends Base
|
||||
result.subscribeCalculatedPowerEvent(new ICalculatedPowerReceiver() {
|
||||
@Override
|
||||
public void onNewCalculatedPower(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedPower) {
|
||||
writeData("WATTS", String.format("%.1f", calculatedPower));
|
||||
alterCurrentData("WATTS", reduceNumberToString(calculatedPower));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -66,7 +66,7 @@ public class Power extends Base
|
||||
new ICalculatedTorqueReceiver() {
|
||||
@Override
|
||||
public void onNewCalculatedTorque(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedTorque) {
|
||||
writeData("NM", String.format("%.1f", calculatedTorque));
|
||||
alterCurrentData("NM", reduceNumberToString(calculatedTorque));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -75,7 +75,7 @@ public class Power extends Base
|
||||
new ICalculatedCrankCadenceReceiver() {
|
||||
@Override
|
||||
public void onNewCalculatedCrankCadence(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedCrankCadence) {
|
||||
writeData("RPM", String.format("%.1f", calculatedCrankCadence));
|
||||
alterCurrentData("RPM", reduceNumberToString(calculatedCrankCadence));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -85,7 +85,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewCalculatedWheelSpeed(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedWheelSpeed)
|
||||
{
|
||||
writeData("KMH", String.format("%.1f", calculatedWheelSpeed));
|
||||
alterCurrentData("KMH", reduceNumberToString(calculatedWheelSpeed));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -95,7 +95,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewCalculatedWheelDistance(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedWheelDistance)
|
||||
{
|
||||
writeData("KM", String.format("%.1f", calculatedWheelDistance));
|
||||
alterCurrentData("KM", reduceNumberToString(calculatedWheelDistance));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -105,7 +105,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewInstantaneousCadence(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final int instantaneousCadence)
|
||||
{
|
||||
writeData("RPM", String.format("%d", instantaneousCadence));
|
||||
alterCurrentData("RPM", reduceNumberToString(instantaneousCadence));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -115,7 +115,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewRawPowerOnlyData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final int instantaneousPower, final long accumulatedPower)
|
||||
{
|
||||
writeData("WATTS", String.format("%d", instantaneousPower));
|
||||
alterCurrentData("WATTS", reduceNumberToString(instantaneousPower));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -125,7 +125,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewPedalPowerBalance(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final boolean rightPedalIndicator, final int pedalPowerPercentage)
|
||||
{
|
||||
writeData("LTE", String.format("%d", pedalPowerPercentage));
|
||||
alterCurrentData("LTE", reduceNumberToString(pedalPowerPercentage));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -135,7 +135,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewRawWheelTorqueData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long wheelTorqueUpdateEventCount, final long accumulatedWheelTicks, final BigDecimal accumulatedWheelPeriod, final BigDecimal accumulatedWheelTorque)
|
||||
{
|
||||
writeData("NM", String.format("%.1f", accumulatedWheelTorque));
|
||||
alterCurrentData("NM", reduceNumberToString(accumulatedWheelTorque));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -145,7 +145,7 @@ public class Power extends Base
|
||||
@Override
|
||||
public void onNewRawCrankTorqueData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long crankTorqueUpdateEventCount, final long accumulatedCrankTicks, final BigDecimal accumulatedCrankPeriod, final BigDecimal accumulatedCrankTorque)
|
||||
{
|
||||
writeData("NM", String.format("%.1f", accumulatedCrankTorque));
|
||||
alterCurrentData("NM", reduceNumberToString(accumulatedCrankTorque));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -156,9 +156,9 @@ public class Power extends Base
|
||||
public void onNewTorqueEffectiveness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final BigDecimal leftTorqueEffectiveness, final BigDecimal rightTorqueEffectiveness)
|
||||
{
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("LTE", String.format("%.1f", leftTorqueEffectiveness));
|
||||
map.put("RTE", String.format("%.1f", rightTorqueEffectiveness));
|
||||
writeData(map);
|
||||
map.put("LTE", reduceNumberToString(leftTorqueEffectiveness));
|
||||
map.put("RTE", reduceNumberToString(rightTorqueEffectiveness));
|
||||
alterCurrentData(map);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -169,9 +169,9 @@ public class Power extends Base
|
||||
public void onNewPedalSmoothness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final boolean separatePedalSmoothnessSupport, final BigDecimal leftOrCombinedPedalSmoothness, final BigDecimal rightPedalSmoothness)
|
||||
{
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("SNPLC", String.format("%.1f", leftOrCombinedPedalSmoothness));
|
||||
map.put("SNPR", String.format("%.1f", rightPedalSmoothness));
|
||||
writeData(map);
|
||||
map.put("SNPLC", reduceNumberToString(leftOrCombinedPedalSmoothness));
|
||||
map.put("SNPR", reduceNumberToString(rightPedalSmoothness));
|
||||
alterCurrentData(map);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Sensors extends Base
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
// The light sensor returns a single value.
|
||||
// Many sensors return 3 values, one for each axis.
|
||||
writeData("lux", Float.toString(event.values[0]));
|
||||
alterCurrentData("lux", reduceNumberToString(event.values[0]));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,10 +60,10 @@ public class Sensors extends Base
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("ms2x", Float.toString(event.values[0]));
|
||||
map.put("ms2y", Float.toString(event.values[1]));
|
||||
map.put("ms2z", Float.toString(event.values[2]));
|
||||
writeData(map);
|
||||
map.put("ms2x", reduceNumberToString(event.values[0]));
|
||||
map.put("ms2y", reduceNumberToString(event.values[1]));
|
||||
map.put("ms2z", reduceNumberToString(event.values[2]));
|
||||
alterCurrentData(map);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ public class Sensors extends Base
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
// The light sensor returns a single value.
|
||||
// Many sensors return 3 values, one for each axis.
|
||||
writeData("press", Float.toString(event.values[0]));
|
||||
alterCurrentData("press", reduceNumberToString(event.values[0]));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ public class Sensors extends Base
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
// The light sensor returns a single value.
|
||||
// Many sensors return 3 values, one for each axis.
|
||||
writeData("temp", Float.toString(event.values[0]));
|
||||
alterCurrentData("temp", reduceNumberToString(event.values[0]));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -107,10 +107,10 @@ public class Sensors extends Base
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("uTx", Float.toString(event.values[0]));
|
||||
map.put("uTy", Float.toString(event.values[1]));
|
||||
map.put("uTz", Float.toString(event.values[2]));
|
||||
writeData(map);
|
||||
map.put("uTx", reduceNumberToString(event.values[0]));
|
||||
map.put("uTy", reduceNumberToString(event.values[1]));
|
||||
map.put("uTz", reduceNumberToString(event.values[2]));
|
||||
alterCurrentData(map);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user