diff --git a/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/util/RunningRecordCalculation.kt b/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/util/RunningRecordCalculation.kt index af092c46..023da4d9 100644 --- a/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/util/RunningRecordCalculation.kt +++ b/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/util/RunningRecordCalculation.kt @@ -32,6 +32,19 @@ fun calculateAveragePace(runnerStatus: RunnerStatus): String { return formatPace(pace) } +fun calculatePaceInMinPerKm(speedInMetersPerSec: Double): String { + if (speedInMetersPerSec == 0.0) { + return "0'00''" + } + + val paceInMinPerKm = (1 / speedInMetersPerSec) * (1000 / 60) + val minutes = paceInMinPerKm.toInt() + val seconds = ((paceInMinPerKm - minutes) * 60).roundToInt() + + // %02d는 정수를 두 자리로 표현하는데, 만약 한 자리수면 앞에 0 추가 + return "${minutes}'${String.format("%02d", seconds)}''" +} + fun calculateAverageAltitude(runnerStatus: RunnerStatus): Double { return if (runnerStatus.records.isNotEmpty()) { (runnerStatus.records.sumOf { it.altitude } / runnerStatus.records.size) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/ComprehensiveRunRecordResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/ComprehensiveRunRecordResponse.kt index 678ccc19..25c19b8d 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/ComprehensiveRunRecordResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/ComprehensiveRunRecordResponse.kt @@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord import online.partyrun.partyrunapplication.core.model.my_page.TotalRunningTime import online.partyrun.partyrunapplication.core.model.my_page.toElapsedTimeString -import online.partyrun.partyrunapplication.core.model.util.formatPace +import online.partyrun.partyrunapplication.core.model.util.calculatePaceInMinPerKm import online.partyrun.partyrunapplication.core.network.model.util.formatDistanceInKm data class ComprehensiveRunRecordResponse( @@ -17,7 +17,7 @@ data class ComprehensiveRunRecordResponse( ) fun ComprehensiveRunRecordResponse.toDomainModel() = ComprehensiveRunRecord( - averagePace = formatPace(this.averagePace ?: 0.0), + averagePace = calculatePaceInMinPerKm(this.averagePace ?: 0.0), totalDistance = formatDistanceInKm(this.totalDistance?.toInt() ?: 0), totalRunningTime = this.totalRunningTime?.toElapsedTimeString() ?: "00:00" )