mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 19:06:53 +01:00
Bangle.js: actTrk WIP
This commit is contained in:
parent
bcd1fc8681
commit
e39e67100e
@ -522,7 +522,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
} else
|
||||
LOG.warn("UART RX JSON parsed but doesn't contain 't' - ignoring");
|
||||
} catch (JSONException e) {
|
||||
LOG.info("UART RX JSON parse failure: "+ e.getLocalizedMessage());
|
||||
LOG.error("UART RX JSON parse failure: "+ e.getLocalizedMessage());
|
||||
GB.toast(getContext(), "Malformed JSON from Bangle.js: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
|
||||
@ -851,7 +851,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (storedLogObject.has("Steps")) {
|
||||
for (int i = 0; i < logLength; i++) {
|
||||
if (i == 0) {
|
||||
calculationsArray.put("-");
|
||||
calculationsArray.put("0");
|
||||
} else {
|
||||
double steps = storedLogObject.getJSONArray("Steps").getDouble(i);
|
||||
if (steps==0) steps=0.001;
|
||||
@ -951,7 +951,6 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
calculationsArray = new JSONArray();
|
||||
}
|
||||
|
||||
LOG.info("AnalyticsObject:\n" + analyticsObject);
|
||||
|
||||
BaseActivitySummary summary = null;
|
||||
@ -967,7 +966,6 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
JSONObject summaryData = new JSONObject();
|
||||
summaryData = addSummaryData(summaryData,"test",3,"mm");
|
||||
|
||||
// private JSONObject createActivitySummaryGroups(){
|
||||
// final Map<String, List<String>> groupDefinitions = new HashMap<String, List<String>>() {{
|
||||
// put("Strokes", Arrays.asList(
|
||||
@ -1005,53 +1003,58 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// "averageSpeed", "maxSpeed", "minSpeed", "averageKMPaceSeconds", "minPace",
|
||||
// "maxPace", "averageSpeed2", "averageCadence", "maxCadence", "minCadence"
|
||||
// ));
|
||||
if (analyticsObject.has("Speed")) {
|
||||
//summaryData = addSummaryData(summaryData,"averageSpeed",averageOfJSONArray(analyticsObject.getJSONArray("Speed")),"mm"); // This seems to be calculated somewhere else automatically.
|
||||
summaryData = addSummaryData(summaryData, "maxSpeed", maxOfJSONArray(analyticsObject.getJSONArray("Speed")), "m/s");
|
||||
summaryData = addSummaryData(summaryData, "minSpeed", maxOfJSONArray(analyticsObject.getJSONArray("Speed")), "m/s");
|
||||
//summaryData = addSummaryData(summaryData, "averageKMPaceSeconds", averageOfJSONArray(analyticsObject.getJSONArray("Pace")), "s/km"); // Is this also calculated automatically then?
|
||||
//summaryData = addSummaryData(summaryData, "averageKMPaceSeconds",
|
||||
// (float) (1000.0 * analyticsObject.getJSONArray("Elapsed Time").getDouble(logLength-1) /
|
||||
// analyticsObject.getJSONArray("Total Distance").getDouble(logLength-1)),
|
||||
// "s/km"
|
||||
//);
|
||||
summaryData = addSummaryData(summaryData, "minPace", minOfJSONArray(analyticsObject.getJSONArray("Pace")), "s/km");
|
||||
summaryData = addSummaryData(summaryData, "maxPace", maxOfJSONArray(analyticsObject.getJSONArray("Pace")), "s/km");
|
||||
//summaryData = addSummaryData(summaryData,"averageSpeed2",3,"mm");
|
||||
}
|
||||
if (analyticsObject.has("Cadence")) {
|
||||
summaryData = addSummaryData(summaryData, "averageCadence",
|
||||
60 * sumOfJSONArray(storedLogObject.getJSONArray("Steps")) /
|
||||
(float) analyticsObject.getJSONArray("Elapsed Time").getDouble(logLength-1),
|
||||
"steps/min"
|
||||
);
|
||||
summaryData = addSummaryData(summaryData, "maxCadence", maxOfJSONArray(analyticsObject.getJSONArray("Cadence")), "steps/min");
|
||||
summaryData = addSummaryData(summaryData, "minCadence", minOfJSONArray(analyticsObject.getJSONArray("Cadence")), "steps/min");
|
||||
}
|
||||
// put("Activity", Arrays.asList(
|
||||
// "distanceMeters", "steps", "activeSeconds", "caloriesBurnt", "totalStride",
|
||||
// "averageHR", "maxHR", "minHR", "averageStride", "maxStride", "minStride"
|
||||
// ));
|
||||
if (analyticsObject.has("Intermediate Distance")) summaryData =
|
||||
addSummaryData(summaryData,"distanceMeters",
|
||||
(float) analyticsObject.getJSONArray("Total Distance").getDouble(logLength-1),
|
||||
"m");
|
||||
if (storedLogObject.has("Steps")) summaryData = addSummaryData(summaryData, "steps", sumOfJSONArray(storedLogObject.getJSONArray("Steps")),"steps");
|
||||
//summaryData = addSummaryData(summaryData,"activeSeconds",3,"mm"); // FIXME: Is this suppose to exclude the time of inactivity in a workout?
|
||||
//summaryData = addSummaryData(summaryData,"caloriesBurnt",3,"mm"); // TODO: Should this be calculated on Gadgetbridge side or be reported by Bangle.js?
|
||||
//summaryData = addSummaryData(summaryData,"totalStride",3,"mm"); // FIXME: What is this?
|
||||
if (storedLogObject.has("Heartrate")) {
|
||||
summaryData = addSummaryData(summaryData, "averageHR", averageOfJSONArray(storedLogObject.getJSONArray("Heartrate")), "bpm");
|
||||
summaryData = addSummaryData(summaryData, "maxHR", maxOfJSONArray(storedLogObject.getJSONArray("Heartrate")), "bpm");
|
||||
summaryData = addSummaryData(summaryData, "minHR", minOfJSONArray(storedLogObject.getJSONArray("Heartrate")), "bpm");
|
||||
}
|
||||
if (analyticsObject.has("Stride")) {
|
||||
summaryData = addSummaryData(summaryData, "averageStride",
|
||||
(float) (analyticsObject.getJSONArray("Total Distance").getDouble(logLength-1) /
|
||||
(0.5 * sumOfJSONArray(storedLogObject.getJSONArray("Steps")))),
|
||||
"m/stride"); // FIXME: Is this meant to be stride length as I've assumed?
|
||||
summaryData = addSummaryData(summaryData, "maxStride", maxOfJSONArray(analyticsObject.getJSONArray("Stride")), "m/stride");
|
||||
summaryData = addSummaryData(summaryData, "minStride", minOfJSONArray(analyticsObject.getJSONArray("Stride")), "m/stride");
|
||||
try {
|
||||
if (analyticsObject.has("Speed")) {
|
||||
//summaryData = addSummaryData(summaryData,"averageSpeed",averageOfJSONArray(analyticsObject.getJSONArray("Speed")),"mm"); // This seems to be calculated somewhere else automatically.
|
||||
summaryData = addSummaryData(summaryData, "maxSpeed", maxOfJSONArray(analyticsObject.getJSONArray("Speed")), "m/s");
|
||||
summaryData = addSummaryData(summaryData, "minSpeed", maxOfJSONArray(analyticsObject.getJSONArray("Speed")), "m/s");
|
||||
//summaryData = addSummaryData(summaryData, "averageKMPaceSeconds", averageOfJSONArray(analyticsObject.getJSONArray("Pace")), "s/km"); // Is this also calculated automatically then?
|
||||
//summaryData = addSummaryData(summaryData, "averageKMPaceSeconds",
|
||||
// (float) (1000.0 * analyticsObject.getJSONArray("Elapsed Time").getDouble(logLength-1) /
|
||||
// analyticsObject.getJSONArray("Total Distance").getDouble(logLength-1)),
|
||||
// "s/km"
|
||||
//);
|
||||
summaryData = addSummaryData(summaryData, "minPace", minOfJSONArray(analyticsObject.getJSONArray("Pace")), "s/km");
|
||||
summaryData = addSummaryData(summaryData, "maxPace", maxOfJSONArray(analyticsObject.getJSONArray("Pace")), "s/km");
|
||||
//summaryData = addSummaryData(summaryData,"averageSpeed2",3,"mm");
|
||||
}
|
||||
if (analyticsObject.has("Cadence")) {
|
||||
summaryData = addSummaryData(summaryData, "averageCadence",
|
||||
60 * sumOfJSONArray(storedLogObject.getJSONArray("Steps")) /
|
||||
(float) analyticsObject.getJSONArray("Elapsed Time").getDouble(logLength - 1),
|
||||
"steps/min"
|
||||
);
|
||||
summaryData = addSummaryData(summaryData, "maxCadence", maxOfJSONArray(analyticsObject.getJSONArray("Cadence")), "steps/min");
|
||||
summaryData = addSummaryData(summaryData, "minCadence", minOfJSONArray(analyticsObject.getJSONArray("Cadence")), "steps/min");
|
||||
}
|
||||
// put("Activity", Arrays.asList(
|
||||
// "distanceMeters", "steps", "activeSeconds", "caloriesBurnt", "totalStride",
|
||||
// "averageHR", "maxHR", "minHR", "averageStride", "maxStride", "minStride"
|
||||
// ));
|
||||
if (analyticsObject.has("Intermediate Distance")) summaryData =
|
||||
addSummaryData(summaryData, "distanceMeters",
|
||||
(float) analyticsObject.getJSONArray("Total Distance").getDouble(logLength - 1),
|
||||
"m");
|
||||
if (storedLogObject.has("Steps"))
|
||||
summaryData = addSummaryData(summaryData, "steps", sumOfJSONArray(storedLogObject.getJSONArray("Steps")), "steps");
|
||||
//summaryData = addSummaryData(summaryData,"activeSeconds",3,"mm"); // FIXME: Is this suppose to exclude the time of inactivity in a workout?
|
||||
//summaryData = addSummaryData(summaryData,"caloriesBurnt",3,"mm"); // TODO: Should this be calculated on Gadgetbridge side or be reported by Bangle.js?
|
||||
//summaryData = addSummaryData(summaryData,"totalStride",3,"mm"); // FIXME: What is this?
|
||||
if (storedLogObject.has("Heartrate")) {
|
||||
summaryData = addSummaryData(summaryData, "averageHR", averageOfJSONArray(storedLogObject.getJSONArray("Heartrate")), "bpm");
|
||||
summaryData = addSummaryData(summaryData, "maxHR", maxOfJSONArray(storedLogObject.getJSONArray("Heartrate")), "bpm");
|
||||
summaryData = addSummaryData(summaryData, "minHR", minOfJSONArray(storedLogObject.getJSONArray("Heartrate")), "bpm");
|
||||
}
|
||||
if (analyticsObject.has("Stride")) {
|
||||
summaryData = addSummaryData(summaryData, "averageStride",
|
||||
(float) (analyticsObject.getJSONArray("Total Distance").getDouble(logLength - 1) /
|
||||
(0.5 * sumOfJSONArray(storedLogObject.getJSONArray("Steps")))),
|
||||
"m/stride"); // FIXME: Is this meant to be stride length as I've assumed?
|
||||
summaryData = addSummaryData(summaryData, "maxStride", maxOfJSONArray(analyticsObject.getJSONArray("Stride")), "m/stride");
|
||||
summaryData = addSummaryData(summaryData, "minStride", minOfJSONArray(analyticsObject.getJSONArray("Stride")), "m/stride");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error(String.valueOf(e) + ". (thrown when trying to add summary data");
|
||||
}
|
||||
// put("HeartRateZones", Arrays.asList(
|
||||
// "hrZoneNa", "hrZoneWarmUp", "hrZoneFatBurn", "hrZoneAerobic", "hrZoneAnaerobic",
|
||||
|
Loading…
Reference in New Issue
Block a user