Skip to content

Commit

Permalink
fix average speed and max speed
Browse files Browse the repository at this point in the history
  • Loading branch information
HWJFish committed Apr 8, 2024
1 parent 6971406 commit 20cb8c0
Showing 1 changed file with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,18 @@ class VoiceAnnouncementUtils {

private VoiceAnnouncementUtils() {
}

static double calculateMaxSlope() {

// This method should return the calculated maximum slope.
return 0.0;
return 0.0;
}
static double CalculateAverageSlope(){

static double CalculateAverageSlope() {
// This is dummy methods to fetch or calculate the average slope.
return 10.0;
}

static double calculateAverageSpeed(){
// This is dummy methods to fetch or calculate the average slope.
return 5.0;
}

static Spannable createIdle(Context context) {
return new SpannableStringBuilder()
Expand All @@ -62,6 +59,7 @@ static Spannable createIdle(Context context) {
static Spannable createAfterRecording(Context context, TrackStatistics trackStatistics, UnitSystem unitSystem) {
SpannableStringBuilder builder = new SpannableStringBuilder();
Speed maxSpeed = trackStatistics.getMaxSpeed();
Speed avgSpeed = trackStatistics.getAverageSpeed();

int perUnitStringId;
int distanceId;
Expand Down Expand Up @@ -97,7 +95,7 @@ static Spannable createAfterRecording(Context context, TrackStatistics trackStat
if (shouldVoiceAnnounceMaxSpeedRecording()) {
double speedInUnit = maxSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.speed));
.append(context.getString(R.string.stats_max_speed));
String template = context.getResources().getString(speedId);
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
Expand All @@ -107,36 +105,34 @@ static Spannable createAfterRecording(Context context, TrackStatistics trackStat
double maxSlope = calculateMaxSlope(); // Calculate the maximum slope based on elevation data
if (!Double.isNaN(maxSlope)) {
builder.append(" ")
.append(context.getString(R.string.settings_announcements_max_slope))
.append(": ")
.append(String.format("%.2f%%", maxSlope)) // Format the slope value
.append(".");
.append(context.getString(R.string.settings_announcements_max_slope))
.append(": ")
.append(String.format("%.2f%%", maxSlope)) // Format the slope value
.append(".");
}
}

if (shouldVoiceAnnounceAverageSpeedRecording()) {
double avgSpeed = calculateMaxSlope();
if (!Double.isNaN(avgSpeed)) {

double speedInUnit = avgSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.speed));
String template = context.getResources().getString(speedId);
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
}


if (shouldVoiceAnnounceAveragesloperecording()) {
double avgSlope = CalculateAverageSlope();
if (!Double.isNaN(avgSlope)) {
builder.append(" ")
.append("Average speed")
.append(" ")
.append("Average slope")
.append(": ")
.append(String.format("%.2f%%", avgSpeed))
.append(String.format("%.2f%%", avgSlope))
.append(".");
}
}


if (shouldVoiceAnnounceAveragesloperecording()) {
double avgSlope = CalculateAverageSlope();
if (!Double.isNaN(avgSlope)) {
builder.append(" ")
.append("Average slope")
.append(": ")
.append(String.format("%.2f%%", avgSlope))
.append(".");
}
}
return builder;
}

Expand Down Expand Up @@ -166,21 +162,20 @@ static Spannable createRunStatistics(Context context, TrackStatistics trackStati
}



//Announce Average Speed
if (shouldVoiceAnnounceRunAverageSpeed()) {
double speedInUnit = averageMovingSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.speed));
String template = context.getResources().getString(speedId);
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
}
if (shouldVoiceAnnounceRunAverageSpeed()) {
double speedInUnit = averageMovingSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.speed));
String template = context.getResources().getString(speedId);
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
}

if (shouldVoiceAnnounceMaxSpeedRun()) {
double speedInUnit = maxSpeed.to(unitSystem);
builder.append(" ")
.append(context.getString(R.string.settings_announcements_max_speed_run));
.append(context.getString(R.string.stats_max_speed));
String template = context.getResources().getString(speedId);
appendDecimalUnit(builder, MessageFormat.format(template, Map.of("n", speedInUnit)), speedInUnit, 1, unitSpeedTTS);
builder.append(".");
Expand Down Expand Up @@ -306,7 +301,6 @@ static Spannable createStatistics(Context context, TrackStatistics trackStatisti
appendCardinal(builder, context.getString(R.string.sensor_state_heart_rate_value, currentHeartRate), currentHeartRate);
builder.append(".");
}



return builder;
Expand Down Expand Up @@ -334,7 +328,7 @@ private static void appendDuration(@NonNull Context context, @NonNull SpannableS
/**
* Speaks as: 98.14 [UNIT] - ninety eight point one four [UNIT with correct plural form]
*
* @param number The number to speak
* @param number The number to speak
* @param precision The number of decimal places to announce
*/
private static void appendDecimalUnit(@NonNull SpannableStringBuilder builder, @NonNull String localizedText, double number, int precision, @NonNull String unit) {
Expand All @@ -346,7 +340,7 @@ private static void appendDecimalUnit(@NonNull SpannableStringBuilder builder, @
long integerPart = (long) roundedNumber;

if (precision == 0 || (roundedNumber - integerPart) == 0) {
measureBuilder.setNumber((long)number);
measureBuilder.setNumber((long) number);
} else {
// Extract the decimal part
String fractionalPart = String.format("%." + precision + "f", (roundedNumber - integerPart)).substring(2);
Expand Down

0 comments on commit 20cb8c0

Please sign in to comment.