Add max power stats

This commit is contained in:
quaelnix
2023-09-11 15:35:38 +02:00
committed by Dennis Guse
parent e130039118
commit cf9b432224
7 changed files with 62 additions and 16 deletions
@@ -869,12 +869,14 @@ public class ContentProviderUtils {
final int AVG_HR_INDEX = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALIAS_AVG_HR);
final int MAX_CADENCE_INDEX = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALIAS_MAX_CADENCE);
final int AVG_CADENCE_INDEX = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALIAS_AVG_CADENCE);
final int MAX_POWER_INDEX = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALIAS_MAX_POWER);
final int AVG_POWER_INDEX = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALIAS_AVG_POWER);
sensorStatistics = new SensorStatistics(
!cursor.isNull(MAX_HR_INDEX) ? HeartRate.of(cursor.getFloat(MAX_HR_INDEX)) : null,
!cursor.isNull(AVG_HR_INDEX) ? HeartRate.of(cursor.getFloat(AVG_HR_INDEX)) : null,
!cursor.isNull(MAX_CADENCE_INDEX) ? Cadence.of(cursor.getFloat(MAX_CADENCE_INDEX)) : null,
!cursor.isNull(AVG_CADENCE_INDEX) ? Cadence.of(cursor.getFloat(AVG_CADENCE_INDEX)) : null,
!cursor.isNull(MAX_POWER_INDEX) ? Power.of(cursor.getFloat(MAX_POWER_INDEX)) : null,
!cursor.isNull(AVG_POWER_INDEX) ? Power.of(cursor.getFloat(AVG_POWER_INDEX)) : null
);
}
@@ -62,7 +62,7 @@ public class CustomContentProvider extends ContentProvider {
/**
* The string representing the query that compute sensor stats from trackpoints table.
* It computes the average for heart rate, cadence, and power (duration-based average) and the maximum for heart rate and cadence.
* It computes the average for heart rate, cadence and power (duration-based average) and the maximum for heart rate, cadence and power.
* Finally, it ignores manual pause (SEGMENT_START_MANUAL).
*/
private final String SENSOR_STATS_QUERY =
@@ -86,7 +86,9 @@ public class CustomContentProvider extends ContentProvider {
"SUM(t." + TrackPointsColumns.SENSOR_POWER + " * (COALESCE(MAX(t." + TrackPointsColumns.TIME + ", (SELECT time_value FROM time_select)), t." + TrackPointsColumns.TIME + ") - t." + TrackPointsColumns.TIME + ")) " +
"/ " +
"SUM(COALESCE(MAX(t." + TrackPointsColumns.TIME + ", (SELECT time_value FROM time_select)), t." + TrackPointsColumns.TIME + ") - t." + TrackPointsColumns.TIME + ") " + TrackPointsColumns.ALIAS_AVG_POWER + " " +
"SUM(COALESCE(MAX(t." + TrackPointsColumns.TIME + ", (SELECT time_value FROM time_select)), t." + TrackPointsColumns.TIME + ") - t." + TrackPointsColumns.TIME + ") " + TrackPointsColumns.ALIAS_AVG_POWER + ", " +
"MAX(t." + TrackPointsColumns.SENSOR_POWER + ") " + TrackPointsColumns.ALIAS_MAX_POWER + " " +
"FROM " + TrackPointsColumns.TABLE_NAME + " t " +
"WHERE t." + TrackPointsColumns.TRACKID + " = ? " +
@@ -62,6 +62,7 @@ public interface TrackPointsColumns extends BaseColumns {
String ALIAS_AVG_CADENCE = "avg_cadence";
String ALIAS_MAX_CADENCE = "max_cadence";
String ALIAS_AVG_POWER = "avg_power";
String ALIAS_MAX_POWER = "max_power";
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " ("
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
@@ -270,10 +270,12 @@ public class StatisticsRecordedFragment extends Fragment {
viewBinding.statsAvgCadenceValue.setText(avgRPM);
}
if (sensorStatistics.hasPower()) {
String W = String.valueOf(Math.round(sensorStatistics.getAvgPower().getW()));
String maxW = String.valueOf(Math.round(sensorStatistics.getMaxPower().getW()));
String avgW = String.valueOf(Math.round(sensorStatistics.getAvgPower().getW()));
viewBinding.statsPowerGroup.setVisibility(View.VISIBLE);
viewBinding.statsPowerValue.setText(W);
viewBinding.statsMaxPowerValue.setText(maxW);
viewBinding.statsAvgPowerValue.setText(avgW);
}
}
}
@@ -9,13 +9,15 @@ public class SensorStatistics {
private final HeartRate avgHr;
private final Cadence maxCadence;
private final Cadence avgCadence;
private final Power maxPower;
private final Power avgPower;
public SensorStatistics(HeartRate maxHr, HeartRate avgHr, Cadence maxCadence, Cadence avgCadence, Power avgPower) {
public SensorStatistics(HeartRate maxHr, HeartRate avgHr, Cadence maxCadence, Cadence avgCadence, Power maxPower, Power avgPower) {
this.maxHr = maxHr;
this.avgHr = avgHr;
this.maxCadence = maxCadence;
this.avgCadence = avgCadence;
this.maxPower = maxPower;
this.avgPower = avgPower;
}
@@ -47,6 +49,10 @@ public class SensorStatistics {
return avgPower != null;
}
public Power getMaxPower() {
return maxPower;
}
public Power getAvgPower() {
return avgPower;
}