1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Device Cycling sensor: improved cycling data display

This commit is contained in:
Daniel Dakhno 2024-07-05 02:58:25 +02:00
parent 6017ff519c
commit fe96c75006

View File

@ -116,21 +116,28 @@ public class CyclingChartFragment extends AbstractChartFragment<CyclingChartFrag
} }
int nextIndex = 0; int nextIndex = 0;
CyclingSample oldSample = null;
for (CyclingSample sample : samples) { for (CyclingSample sample : samples) {
// add distance in Km // add distance in Km
distanceEntries.add(new Entry(sample.getTimestamp(), (sample.getDistance() / 1000f) - dayStart)); distanceEntries.add(new Entry(sample.getTimestamp(), (sample.getDistance() / 1000f) - dayStart));
Float speed = sample.getSpeed();
speedEntries.add(new Entry(sample.getTimestamp(), (speed != null) ? (sample.getSpeed() * 3.6f) : 0));
if(nextIndex < samples.size()){ if(oldSample != null) {
CyclingSample nextSample = samples.get(nextIndex); float deltaMeters = sample.getDistance() - oldSample.getDistance();
if(nextSample.getSpeed() == null){ float deltaMillis = sample.getTimestamp() - oldSample.getTimestamp();
// sensor is off, doesn't report zero speed. So let's inject it outselves
speedEntries.add(new Entry(sample.getTimestamp() + 30_000, 0)); float metersPerMillisecond = deltaMeters / deltaMillis;
float kmh = metersPerMillisecond * 3600;
// Float speed = sample.getSpeed();
if(kmh < 6.0) {
// speed to slow, cutting down to 0
speedEntries.add(new Entry(oldSample.getTimestamp() + 30_000, 0));
} }
speedEntries.add(new Entry(sample.getTimestamp(), kmh));
} }
nextIndex++; nextIndex++;
oldSample = sample;
} }
LineDataSet distanceSet = new LineDataSet(distanceEntries, "Cycling"); LineDataSet distanceSet = new LineDataSet(distanceEntries, "Cycling");