simplifying speed zones and re-enabling
parent
bde8e4c0e6
commit
a61cbddb5d
|
@ -21,25 +21,21 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||||
|
|
||||||
class ActivityAnalysis {
|
class ActivityAnalysis {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ActivityAnalysis.class);
|
||||||
|
|
||||||
// store raw steps and duration
|
// store raw steps and duration
|
||||||
protected HashMap<Integer, Long> stats = new HashMap<Integer, Long>();
|
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
|
// max speed determined from samples
|
||||||
private int maxSpeed = 0;
|
private int maxSpeed = 0;
|
||||||
// number of bars on stats chart
|
|
||||||
private int resolution = 5;
|
|
||||||
|
|
||||||
ActivityAmounts calculateActivityAmounts(List<? extends ActivitySample> samples) {
|
ActivityAmounts calculateActivityAmounts(List<? extends ActivitySample> samples) {
|
||||||
ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP);
|
ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP);
|
||||||
|
@ -89,11 +85,11 @@ class ActivityAnalysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stats.containsKey(steps)) {
|
if (!stats.containsKey(steps)) {
|
||||||
//System.out.println("Adding: " + steps);
|
LOG.info("Adding: " + steps);
|
||||||
stats.put(steps, timeDifference);
|
stats.put(steps, timeDifference);
|
||||||
} else {
|
} else {
|
||||||
long time = stats.get(steps);
|
long time = stats.get(steps);
|
||||||
//System.out.println("Updating: " + steps + " " + timeDifference + time);
|
LOG.info("Updating: " + steps + " " + timeDifference + time);
|
||||||
stats.put(steps, timeDifference + time);
|
stats.put(steps, timeDifference + time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,34 +99,6 @@ class ActivityAnalysis {
|
||||||
previousSample = sample;
|
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();
|
ActivityAmounts result = new ActivityAmounts();
|
||||||
if (deepSleep.getTotalSeconds() > 0) {
|
if (deepSleep.getTotalSeconds() > 0) {
|
||||||
result.addAmount(deepSleep);
|
result.addAmount(deepSleep);
|
||||||
|
|
|
@ -338,12 +338,12 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
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);
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
|
||||||
if (coordinator.supportsRealtimeData()) {
|
if (coordinator.supportsRealtimeData()) {
|
||||||
return 5;
|
return 6;
|
||||||
}
|
}
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,15 +19,19 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||||
import com.github.mikephil.charting.components.AxisBase;
|
import com.github.mikephil.charting.components.AxisBase;
|
||||||
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by nhu on 30/04/17.
|
* Created by Vebryn on 30/04/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class XAxisValueFormatter implements IAxisValueFormatter {
|
public class XAxisValueFormatter implements IAxisValueFormatter {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(XAxisValueFormatter.class);
|
||||||
private List<String> mValues = new ArrayList<>();
|
private List<String> mValues = new ArrayList<>();
|
||||||
|
|
||||||
public XAxisValueFormatter() {
|
public XAxisValueFormatter() {
|
||||||
|
@ -39,7 +43,7 @@ public class XAxisValueFormatter implements IAxisValueFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort() {
|
public void sort() {
|
||||||
//System.out.println("Sorting " + mValues);
|
LOG.info("Sorting " + mValues);
|
||||||
Collections.sort(mValues);
|
Collections.sort(mValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +53,9 @@ public class XAxisValueFormatter implements IAxisValueFormatter {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
returnString = mValues.get((int) value).toString();
|
returnString = mValues.get((int) value).toString();
|
||||||
//System.out.println("Asking " + value + ", returning " + returnString);
|
LOG.info("Asking " + value + ", returning " + returnString);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e.getMessage());
|
LOG.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return returnString;
|
return returnString;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue