-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are two errors for polylines that have popped up on Sentry lately. It seems that people have activities with either a single point, or multiple points directly on top of eachother, which results in div/0 errors. This fixes those, and adds tests for the polyline visualisations while I'm at it.
- Loading branch information
1 parent
58ec230
commit e34aac1
Showing
6 changed files
with
193 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import shutil | ||
|
||
import pytest | ||
from active_statistics.statistics.images.polyline_grid import create_images | ||
from stravalib.model import Activity, PolylineMap | ||
from tests.factories.activity_factories import ActivityFactory | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def temp_directory(request, tmp_path_factory): | ||
# Create a temporary directory | ||
temp_dir = tmp_path_factory.mktemp("temp_directory") | ||
|
||
# Define a finalizer to clean up the directory after the test | ||
def cleanup_temp_directory(): | ||
# Delete the directory and its contents | ||
shutil.rmtree(temp_dir) | ||
|
||
# Add the finalizer to the request to ensure cleanup | ||
request.addfinalizer(cleanup_temp_directory) | ||
|
||
return temp_dir | ||
|
||
|
||
class TestPolylineGrid: | ||
def test_no_activities(self, temp_directory) -> None: | ||
activities: list[Activity] = [] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_no_polylines(self, temp_directory) -> None: | ||
activities = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap(id="123", polyline=None, summary_polyline=None), | ||
), | ||
] | ||
create_images(activities, temp_directory) | ||
|
||
def test_activities_with_blank_polylines(self, temp_directory) -> None: | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap(id="123", polyline=None, summary_polyline=""), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_single_point_polylines(self, temp_directory) -> None: | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap(id="123", polyline=None, summary_polyline="??"), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_multi_point_identical_polylines( | ||
self, temp_directory | ||
) -> None: | ||
# Yes, this polyline is from real data. | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap( | ||
id="123", polyline=None, summary_polyline="fszfDwsbe\\??" | ||
), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_normal_polylines(self, temp_directory) -> None: | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap( | ||
id="123", | ||
polyline=None, | ||
summary_polyline="tdufD}|}d\C?e@Nm@\eAn@u@j@_Aj@i@b@q@\EN]HcAZyBdAWVcAt@g@Vs@n@{@j@c@r@mAnAW`@Mb@MVJR@Tw@jAGp@LtALl@RVTf@Vr@b@bBP`@FX?JCp@Jt@Vh@P^PTf@`@l@pABJ`@fA\t@~@hAd@`ARl@z@dBV^rA~AV\hBjDh@lA~BlC`@j@rCxERXdBbBbArAVf@jAjAXRb@LXPzA|ARJVD^TdAz@v@x@Rb@^l@x@`Az@t@dAl@vBvAjBtA`@^hBvAvA`Ap@j@dB`AlDlC~@n@hAh@hA\^Rd@\jAp@RFf@Df@Cf@BbB~@fAp@f@`@`@b@^Tf@Fr@Ah@OX[|@sBvAsDLc@d@eAHe@Hq@N_@FIFUAc@D{@DiEF}B?gBBsAD~CAfCErAEdEG~AJj@@h@GjAc@tD_@zAQf@Sd@{@rAIFa@RWDe@Ga@AWQM[[YWIkAk@s@g@{@g@k@[[Mi@[]IkAFSCWGiAi@{@c@eAs@cAa@mCgB}B}AeCoB{@g@mAcA_Am@uAkAeBgAiBoAc@_@a@c@e@_@}@_Aw@{A[a@u@o@a@WaA_@]Yy@}@w@_@]I_@Wk@i@eDeEWg@aBoB{@mAe@{@aBwBWg@y@gAqA{BqAgB{AeCi@u@sAmC[w@gAkBi@_BUe@w@mA{@iBKgA_@yAMq@Qi@q@_BKsAGc@Ak@Fe@JW`@m@Ie@Ng@PQZe@`@a@p@_AVi@bByAVYhCwAnAaAZO\Kb@Wd@O", | ||
), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) |
82 changes: 82 additions & 0 deletions
82
backend/tests/test_visualisations/test_polyline_overlay.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import shutil | ||
|
||
import pytest | ||
from active_statistics.statistics.images.polyline_overlay import create_images | ||
from stravalib.model import Activity, PolylineMap | ||
from tests.factories.activity_factories import ActivityFactory | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def temp_directory(request, tmp_path_factory): | ||
# Create a temporary directory | ||
temp_dir = tmp_path_factory.mktemp("temp_directory") | ||
|
||
# Define a finalizer to clean up the directory after the test | ||
def cleanup_temp_directory(): | ||
# Delete the directory and its contents | ||
shutil.rmtree(temp_dir) | ||
|
||
# Add the finalizer to the request to ensure cleanup | ||
request.addfinalizer(cleanup_temp_directory) | ||
|
||
return temp_dir | ||
|
||
|
||
class TestPolylineOverlay: | ||
def test_no_activities(self, temp_directory) -> None: | ||
activities: list[Activity] = [] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_no_polylines(self, temp_directory) -> None: | ||
activities = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap(id="123", polyline=None, summary_polyline=None), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_blank_polylines(self, temp_directory) -> None: | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap(id="123", polyline=None, summary_polyline=""), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_single_point_polylines(self, temp_directory) -> None: | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap(id="123", polyline=None, summary_polyline="??"), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_multi_point_identical_polylines( | ||
self, temp_directory | ||
) -> None: | ||
# Yes, this polyline is from real data. | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap( | ||
id="123", polyline=None, summary_polyline="fszfDwsbe\\??" | ||
), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) | ||
|
||
def test_activities_with_normal_polylines(self, temp_directory) -> None: | ||
activities: list[Activity] = [ | ||
ActivityFactory( | ||
type="Run", | ||
map=PolylineMap( | ||
id="123", | ||
polyline=None, | ||
summary_polyline="tdufD}|}d\C?e@Nm@\eAn@u@j@_Aj@i@b@q@\EN]HcAZyBdAWVcAt@g@Vs@n@{@j@c@r@mAnAW`@Mb@MVJR@Tw@jAGp@LtALl@RVTf@Vr@b@bBP`@FX?JCp@Jt@Vh@P^PTf@`@l@pABJ`@fA\t@~@hAd@`ARl@z@dBV^rA~AV\hBjDh@lA~BlC`@j@rCxERXdBbBbArAVf@jAjAXRb@LXPzA|ARJVD^TdAz@v@x@Rb@^l@x@`Az@t@dAl@vBvAjBtA`@^hBvAvA`Ap@j@dB`AlDlC~@n@hAh@hA\^Rd@\jAp@RFf@Df@Cf@BbB~@fAp@f@`@`@b@^Tf@Fr@Ah@OX[|@sBvAsDLc@d@eAHe@Hq@N_@FIFUAc@D{@DiEF}B?gBBsAD~CAfCErAEdEG~AJj@@h@GjAc@tD_@zAQf@Sd@{@rAIFa@RWDe@Ga@AWQM[[YWIkAk@s@g@{@g@k@[[Mi@[]IkAFSCWGiAi@{@c@eAs@cAa@mCgB}B}AeCoB{@g@mAcA_Am@uAkAeBgAiBoAc@_@a@c@e@_@}@_Aw@{A[a@u@o@a@WaA_@]Yy@}@w@_@]I_@Wk@i@eDeEWg@aBoB{@mAe@{@aBwBWg@y@gAqA{BqAgB{AeCi@u@sAmC[w@gAkBi@_BUe@w@mA{@iBKgA_@yAMq@Qi@q@_BKsAGc@Ak@Fe@JW`@m@Ie@Ng@PQZe@`@a@p@_AVi@bByAVYhCwAnAaAZO\Kb@Wd@O", | ||
), | ||
), | ||
] | ||
create_images((_ for _ in activities), temp_directory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Run.png": "All Run activities overlaid as if they have the same starting point.", "Run_animation.gif": "An animation of overlaid Run activities."} |