Skip to content

Commit

Permalink
Merge pull request #25 from luckyLukac/main
Browse files Browse the repository at this point in the history
Added test for area_identification
  • Loading branch information
firefly-cpp authored Jul 2, 2021
2 parents 0639702 + f3ee3f4 commit d769ad4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sport_activities_features/area_identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def extract_data_in_area(self) -> dict:
cur_time = (self.timestamps[i] - self.timestamps[i - 1]).seconds
distance += cur_distance
time += cur_time
heartrates = np.append(heartrates, self.heartrates[i])
if self.heartrates[i]:
heartrates = np.append(heartrates, self.heartrates[i])
if cur_distance / cur_time > max_speed:
max_speed = cur_distance / cur_time

Expand Down
37 changes: 37 additions & 0 deletions sport_activities_features/tests/test_area_identification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np
import os
from unittest import TestCase
from sport_activities_features.area_identification import AreaIdentification
from sport_activities_features.tcx_manipulation import TCXFile

class TestAreaIdentification(TestCase):
def setUp(self):
filename = os.path.join(os.path.dirname(__file__), "data", '15.tcx')
tcx_file = TCXFile()
self.activity = tcx_file.read_one_file(filename)
area_coordinates = np.array([[[10, 10], [10, 50], [50, 50], [50, 10]],
[[19, 19], [19, 21], [21, 21], [21, 19]]])
area = AreaIdentification(self.activity['positions'], self.activity['distances'], self.activity['timestamps'], self.activity['heartrates'], area_coordinates)
area.identify_points_in_area()
self.data = area.extract_data_in_area()

def test_distance_correct(self):
self.assertAlmostEqual(self.data['distance'], 116367.0, places=1)

def test_time_correct(self):
self.assertAlmostEqual(self.data['time'], 17250.0, places=1)

def test_max_speed_correct(self):
self.assertAlmostEqual(self.data['max_speed'], 21.4, places=1)

def test_avg_speed_correct(self):
self.assertAlmostEqual(self.data['avg_speed'], 6.7, places=1)

def test_min_heartrate_correct(self):
self.assertAlmostEqual(self.data['min_heartrate'], 95.0, places=1)

def test_max_heartrate_correct(self):
self.assertAlmostEqual(self.data['max_heartrate'], 200.0, places=1)

def test_avg_heartrate_correct(self):
self.assertAlmostEqual(self.data['avg_heartrate'], 140.6, places=1)

0 comments on commit d769ad4

Please sign in to comment.