Skip to content

Commit

Permalink
Don't calculate difficulty twice
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Aug 31, 2023
1 parent 0c8f267 commit 2b3db40
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ class HikingService : IHikingService {

override fun getHikingDuration(
path: List<PathPoint>,
paceFactor: Float
paceFactor: Float,
difficulty: HikingDifficulty?
): Duration {
val difficulty = getHikingDifficulty(path)
return getHikingDuration(path, getAveragePace(difficulty, paceFactor))
val diff = difficulty ?: getHikingDifficulty(path)
return getHikingDuration(path, getAveragePace(diff, paceFactor))
}

override fun getElevationGain(path: List<PathPoint>): Distance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ interface IHikingService {

fun getHikingDuration(
path: List<PathPoint>,
paceFactor: Float = 2f
paceFactor: Float = 2f,
difficulty: HikingDifficulty? = null
): Duration

fun getElevationLossGain(path: List<PathPoint>): Pair<Distance, Distance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ class PathOverviewFragment : BoundFragment<FragmentPathOverviewBinding>() {

private suspend fun updateHikingStats() = onDefault {
val reversed = waypoints.reversed()
difficulty = hikingService.getHikingDifficulty(reversed)
calculatedDuration =
hikingService.getHikingDuration(reversed, paceFactor)
difficulty = hikingService.getHikingDifficulty(reversed)
}

private fun movePath() {
Expand Down

0 comments on commit 2b3db40

Please sign in to comment.