Skip to content

Commit

Permalink
Merge pull request #231 from SWM-KAWAI-MANS/feat/calculatePaceInMinPerKm
Browse files Browse the repository at this point in the history
feat : m/s로 계산된 평균 페이스를 분/킬로미터 단위로 변환
  • Loading branch information
nohjunh authored Oct 14, 2023
2 parents 49119e6 + 8a90a69 commit a191aea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
)

0 comments on commit a191aea

Please sign in to comment.