1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

simplifying speed zones and re-enabling

This commit is contained in:
Vebryn 2017-08-23 23:38:30 +02:00 committed by Andreas Shimokawa
parent bde8e4c0e6
commit a61cbddb5d
3 changed files with 18 additions and 46 deletions

View File

@ -21,25 +21,21 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
class ActivityAnalysis {
private static final Logger LOG = LoggerFactory.getLogger(ActivityAnalysis.class);
// store raw steps and duration
protected HashMap<Integer, Long> stats = new HashMap<Integer, Long>();
// normalize steps
protected HashMap<Float, Float> statsQuantified = new HashMap<Float, Float>();
// store maxSpeed / resolution
protected float maxSpeedQuantifier;
// store an average of round precision
protected float roundPrecision = 0f;
// max speed determined from samples
private int maxSpeed = 0;
// number of bars on stats chart
private int resolution = 5;
ActivityAmounts calculateActivityAmounts(List<? extends ActivitySample> samples) {
ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP);
@ -89,11 +85,11 @@ class ActivityAnalysis {
}
if (!stats.containsKey(steps)) {
//System.out.println("Adding: " + steps);
LOG.info("Adding: " + steps);
stats.put(steps, timeDifference);
} else {
long time = stats.get(steps);
//System.out.println("Updating: " + steps + " " + timeDifference + time);
LOG.info("Updating: " + steps + " " + timeDifference + time);
stats.put(steps, timeDifference + time);
}
}
@ -103,34 +99,6 @@ class ActivityAnalysis {
previousSample = sample;
}
maxSpeedQuantifier = maxSpeed / resolution;
for (Map.Entry<Integer, Long> entry : stats.entrySet()) {
// 0.1 precision
//float keyQuantified = Math.round(entry.getKey() / maxSpeedQuantifier * 10f) / 10f;
// 1 precision
float keyQuantified = entry.getKey() / maxSpeedQuantifier;
float keyQuantifiedRounded = Math.round(entry.getKey() / maxSpeedQuantifier);
float keyQuantifiedPrecision = keyQuantifiedRounded - keyQuantified;
roundPrecision = (roundPrecision + Math.abs(keyQuantifiedPrecision)) / 2;
//System.out.println("Precision: " + roundPrecision);
// no scale
//keyQuantified = entry.getKey();
// scaling to minutes
float timeMinutes = entry.getValue() / 60;
if (!statsQuantified.containsKey(keyQuantifiedRounded)) {
//System.out.println("Adding: " + keyQuantified + "/" + timeMinutes);
statsQuantified.put(keyQuantifiedRounded, timeMinutes);
} else {
float previousTime = statsQuantified.get(keyQuantifiedRounded);
//System.out.println("Updating: " + keyQuantified + "/" + (timeMinutes + previousTime));
statsQuantified.put(keyQuantifiedRounded, (timeMinutes + previousTime));
}
}
ActivityAmounts result = new ActivityAmounts();
if (deepSleep.getTotalSeconds() > 0) {
result.addAmount(deepSleep);

View File

@ -338,12 +338,12 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
@Override
public int getCount() {
// Show 4 or 5 total pages. (always hide speed zones)
// Show 5 or 6 total pages.
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
if (coordinator.supportsRealtimeData()) {
return 5;
return 6;
}
return 4;
return 5;
}
@Override

View File

@ -19,15 +19,19 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by nhu on 30/04/17.
* Created by Vebryn on 30/04/17.
*/
public class XAxisValueFormatter implements IAxisValueFormatter {
private static final Logger LOG = LoggerFactory.getLogger(XAxisValueFormatter.class);
private List<String> mValues = new ArrayList<>();
public XAxisValueFormatter() {
@ -39,7 +43,7 @@ public class XAxisValueFormatter implements IAxisValueFormatter {
}
public void sort() {
//System.out.println("Sorting " + mValues);
LOG.info("Sorting " + mValues);
Collections.sort(mValues);
}
@ -49,9 +53,9 @@ public class XAxisValueFormatter implements IAxisValueFormatter {
try {
returnString = mValues.get((int) value).toString();
//System.out.println("Asking " + value + ", returning " + returnString);
LOG.info("Asking " + value + ", returning " + returnString);
} catch (Exception e) {
System.out.println(e.getMessage());
LOG.error(e.getMessage());
}
return returnString;
}