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

Huawei: Group pace values in activity summary pace group

This commit is contained in:
José Rebelo 2024-03-30 21:42:18 +00:00
parent 83d2aaf30e
commit 88a1e7bb59
4 changed files with 32 additions and 14 deletions

View File

@ -129,4 +129,6 @@ public class ActivitySummaryEntries {
public static final String UNIT_STROKES_PER_SECOND = "strokes_second"; public static final String UNIT_STROKES_PER_SECOND = "strokes_second";
public static final String UNIT_YARD = "yard"; public static final String UNIT_YARD = "yard";
public static final String UNIT_DEGREES = "degrees"; public static final String UNIT_DEGREES = "degrees";
public static final String GROUP_PACE = "Pace";
} }

View File

@ -123,7 +123,13 @@ public class ActivitySummaryJsonSummary {
if (summaryDatalist == null) return null; if (summaryDatalist == null) return null;
Iterator<String> keys = summaryDatalist.keys(); Iterator<String> keys = summaryDatalist.keys();
Map<String, JSONArray> activeGroups = new HashMap<>();
final Map<String, JSONArray> activeGroups = new LinkedHashMap<>();
// Initialize activeGroups with the initial expected order and empty arrays
final Iterator<String> names = this.groupData.keys();
while (names.hasNext()) {
activeGroups.put(names.next(), new JSONArray());
}
while (keys.hasNext()) { while (keys.hasNext()) {
String key = keys.next(); String key = keys.next();
@ -131,10 +137,12 @@ public class ActivitySummaryJsonSummary {
JSONObject innerData = (JSONObject) summaryDatalist.get(key); JSONObject innerData = (JSONObject) summaryDatalist.get(key);
Object value = innerData.get("value"); Object value = innerData.get("value");
String unit = innerData.getString("unit"); String unit = innerData.getString("unit");
String groupName = getGroup(key); // Use the group if specified in the entry, otherwise fallback to the array below
String groupName = innerData.optString("group", getGroup(key));
JSONArray group = activeGroups.get(groupName); JSONArray group = activeGroups.get(groupName);
if (group == null) { if (group == null) {
// This group is not defined in createActivitySummaryGroups - add it to the end
group = new JSONArray(); group = new JSONArray();
activeGroups.put(groupName, group); activeGroups.put(groupName, group);
} }
@ -149,20 +157,20 @@ public class ActivitySummaryJsonSummary {
} }
} }
// Reorder collected groups according to the order set by this.groupData. // Convert activeGroups to the expected JSONObject
JSONObject grouped = new JSONObject(); // activeGroups is already ordered
Iterator<String> names = this.groupData.keys(); final JSONObject grouped = new JSONObject();
while(names.hasNext()) { for (final Map.Entry<String, JSONArray> entry : activeGroups.entrySet()) {
String groupName = names.next(); if (entry.getValue().length() == 0) {
JSONArray group = activeGroups.get(groupName); // empty group
if (group != null) { continue;
}
try { try {
grouped.put(groupName, group); grouped.put(entry.getKey(), entry.getValue());
} catch (JSONException e) { } catch (JSONException e) {
LOG.error("SportsActivity internal error building grouped summary", e); LOG.error("SportsActivity internal error building grouped summary", e);
} }
} }
}
return grouped; return grouped;
} }
@ -223,6 +231,8 @@ public class ActivitySummaryJsonSummary {
put("laps", Arrays.asList( put("laps", Arrays.asList(
LAP_PACE_AVERAGE, LAPS, LANE_LENGTH LAP_PACE_AVERAGE, LAPS, LANE_LENGTH
)); ));
put("Pace", Arrays.asList(
));
put("RunningForm", Arrays.asList( put("RunningForm", Arrays.asList(
GROUND_CONTACT_TIME_AVG, IMPACT_AVG, IMPACT_MAX, SWING_ANGLE_AVG, GROUND_CONTACT_TIME_AVG, IMPACT_AVG, IMPACT_MAX, SWING_ANGLE_AVG,
FORE_FOOT_LANDINGS, MID_FOOT_LANDINGS, BACK_FOOT_LANDINGS, FORE_FOOT_LANDINGS, MID_FOOT_LANDINGS, BACK_FOOT_LANDINGS,

View File

@ -559,22 +559,26 @@ public class HuaweiWorkoutGbParser {
JSONObject paceDistance = new JSONObject(); JSONObject paceDistance = new JSONObject();
paceDistance.put("value", sample.getDistance()); paceDistance.put("value", sample.getDistance());
paceDistance.put("unit", ActivitySummaryEntries.UNIT_KILOMETERS); paceDistance.put("unit", ActivitySummaryEntries.UNIT_KILOMETERS);
paceDistance.put("group", ActivitySummaryEntries.GROUP_PACE);
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceDistance), index), paceDistance); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceDistance), index), paceDistance);
JSONObject paceType = new JSONObject(); JSONObject paceType = new JSONObject();
paceType.put("value", sample.getType()); paceType.put("value", sample.getType());
paceType.put("unit", ""); // TODO: find out types paceType.put("unit", ""); // TODO: find out types
paceType.put("group", ActivitySummaryEntries.GROUP_PACE);
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceType), index), paceType); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceType), index), paceType);
JSONObject pacePace = new JSONObject(); JSONObject pacePace = new JSONObject();
pacePace.put("value", sample.getPace()); pacePace.put("value", sample.getPace());
pacePace.put("unit", ActivitySummaryEntries.UNIT_SECONDS_PER_KM); pacePace.put("unit", ActivitySummaryEntries.UNIT_SECONDS_PER_KM);
pacePace.put("group", ActivitySummaryEntries.GROUP_PACE);
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPacePace), index), pacePace); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPacePace), index), pacePace);
if (sample.getCorrection() != 0) { if (sample.getCorrection() != 0) {
JSONObject paceCorrection = new JSONObject(); JSONObject paceCorrection = new JSONObject();
paceCorrection.put("value", sample.getCorrection() / 10); paceCorrection.put("value", sample.getCorrection() / 10);
paceCorrection.put("unit", ActivitySummaryEntries.UNIT_METERS); paceCorrection.put("unit", ActivitySummaryEntries.UNIT_METERS);
paceCorrection.put("group", ActivitySummaryEntries.GROUP_PACE);
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceCorrection), index), paceCorrection); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceCorrection), index), paceCorrection);
} }
} }
@ -587,6 +591,7 @@ public class HuaweiWorkoutGbParser {
JSONObject avgPace = new JSONObject(); JSONObject avgPace = new JSONObject();
avgPace.put("value", pace / count); avgPace.put("value", pace / count);
avgPace.put("unit", ActivitySummaryEntries.UNIT_SECONDS_PER_KM); avgPace.put("unit", ActivitySummaryEntries.UNIT_SECONDS_PER_KM);
avgPace.put("group", ActivitySummaryEntries.GROUP_PACE);
jsonObject.put(String.format(GBApplication.getContext().getString(R.string.fmtPaceTypeAverage), key), avgPace); jsonObject.put(String.format(GBApplication.getContext().getString(R.string.fmtPaceTypeAverage), key), avgPace);
} }
} }

View File

@ -1927,6 +1927,7 @@
<string name="km">km</string> <string name="km">km</string>
<string name="mi">mi</string> <string name="mi">mi</string>
<string name="degrees">degrees</string> <string name="degrees">degrees</string>
<string name="Pace">Pace</string>
<!-- activity summary groups--> <!-- activity summary groups-->
<string name="Strokes">Strokes</string> <string name="Strokes">Strokes</string>
<string name="Swimming">Swimming</string> <string name="Swimming">Swimming</string>