diff --git a/sport_activities_features/hill_identification.py b/sport_activities_features/hill_identification.py index aeedebd..acaa2a1 100644 --- a/sport_activities_features/hill_identification.py +++ b/sport_activities_features/hill_identification.py @@ -171,7 +171,8 @@ def identify_hills(self) -> None: if abs(current_descent) >= self.ascent_threshold: is_descent = True - if ((is_ascent and is_descent) and array_of_changes_indexes[i][2] < 0) or i == (len(array_of_changes_indexes) - 1): + if (((is_ascent and is_descent) and array_of_changes_indexes[i][2] < 0) + or i == (len(array_of_changes_indexes) - 1)): hill_segment_grade = None is_a_list = isinstance( @@ -181,8 +182,8 @@ def identify_hills(self) -> None: if is_a_list and len(self.distances) == len( self.altitudes ): - end_distance = self.distances[array_of_changes_indexes[0][1]] - start_distance = self.distances[array_of_changes_indexes[0][0]] + end_distance = self.distances[array_of_changes_indexes[i][1]] + start_distance = self.distances[start_x] hill_segment_distance = ( end_distance - start_distance ) @@ -192,22 +193,16 @@ def identify_hills(self) -> None: self.identified_hills.append(StoredSegments( [start_x, array_of_changes_indexes[i][1]], - array_of_changes_indexes[i][2], + current_ascent, hill_segment_grade, )) - print('hill_segment_grade', hill_segment_grade) start_x = array_of_changes_indexes[i][1] is_ascent = False is_descent = False current_ascent = 0 current_descent = 0 - for i in range (len(self.identified_hills)): - print(self.identified_hills[i].segment) - print(self.identified_hills[i].ascent) - print(self.identified_hills[i].average_slope) - def return_hills(self) -> list: """ Method for returning identified hills.\n diff --git a/sport_activities_features/topographic_features.py b/sport_activities_features/topographic_features.py index 8a8b530..b90f44f 100644 --- a/sport_activities_features/topographic_features.py +++ b/sport_activities_features/topographic_features.py @@ -59,11 +59,21 @@ def distance_of_hills(self, positions: list) -> float: total_distance = 0.0 for i in range(len(self.identified_hills)): current = self.identified_hills[i] + + index_range = [] + + start = current[0] + 1 + if current[0] == 0: + start = 0 + + for index in range(start, current[1]): + index_range.append(index) + distance = 0.0 if len(positions) < 5: total_distance = 0.0 else: - for _j in range(len(current) - 1): + for _j in range(len(index_range) - 1): distance = distance + self.calculate_distance( positions[i][0], positions[i + 1][0], diff --git a/tests/test_hill_identification.py b/tests/test_hill_identification.py index 4debb50..42570f6 100644 --- a/tests/test_hill_identification.py +++ b/tests/test_hill_identification.py @@ -38,27 +38,24 @@ def test_avg_ascent_correct(self): places=1, ) - @pytest.mark.skip(reason="need manual verification") def test_distance_of_hills_correct(self): self.assertAlmostEqual( self.top.distance_of_hills(self.activity["positions"]), - 20.0, + 40.1, places=1, ) - @pytest.mark.skip(reason="need manual verification") def test_share_of_hills_correct(self): distance_hills = self.top.distance_of_hills(self.activity["positions"]) self.assertAlmostEqual( self.top.share_of_hills( distance_hills, self.activity["total_distance"] ), - 0.17, + 0.34, places=2, ) - @pytest.mark.skip(reason="need manual verification") def test_avg_grade_of_hill(self): self.assertAlmostEqual( - self.hill.identified_hills[0].average_slope, 2.336246, 5 + self.hill.identified_hills[0].average_slope, 1.554688, 5 )