Skip to content

Commit

Permalink
put in test for #31 and fix here
Browse files Browse the repository at this point in the history
other places (e.g. widgets) should accept missing gradient and render something sensible
  • Loading branch information
time4tea committed Jun 11, 2022
1 parent bd32739 commit 0bc244d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
11 changes: 6 additions & 5 deletions gopro_overlay/timeseries_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ def calculate_gradient():
# have to move a bit (0.10m) to calculate decent gradient
# this is called for frames ~2 sec apart.
def accept(a, b, c):
gain = b.alt - a.alt
if a.odo and b.odo:
dist = b.odo - a.odo
if dist and dist.magnitude > 0.10:
return {"grad": (gain / dist) * 100.0}
if a.alt and b.alt:
gain = b.alt - a.alt
if a.odo and b.odo:
dist = b.odo - a.odo
if dist and dist.magnitude > 0.10:
return {"grad": (gain / dist) * 100.0}

return accept
25 changes: 24 additions & 1 deletion tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from gopro_overlay.entry import Entry
from gopro_overlay.point import Point
from gopro_overlay.timeseries import Timeseries
from gopro_overlay.timeseries_process import process_ses, calculate_speeds
from gopro_overlay.timeseries_process import process_ses, calculate_speeds, calculate_gradient
from gopro_overlay.units import units


Expand Down Expand Up @@ -56,3 +56,26 @@ def test_process_delta_speeds():
assert "{0.magnitude:.2f} {0.units:~P}".format(entry.cspeed) == "16.11 m/s"
assert "{0.magnitude:.2f} {0.units:~P}".format(entry.azi) == "56.53 deg"
assert "{0.magnitude:.2f} {0.units:~P}".format(entry.cog) == "56.53 deg"


def metres(n):
return units.Quantity(n, units.m)


def test_process_gradient():
processor = calculate_gradient()
r = processor(
a=Entry(datetime_of(0), alt=metres(5), odo=metres(10)),
b=Entry(datetime_of(0), alt=metres(6), odo=metres(26)),
c=None
)
assert r["grad"].magnitude == 6.25


def test_process_gradient_missing_alt():
processor = calculate_gradient()
assert processor(
a=Entry(datetime_of(0), odo=metres(10)),
b=Entry(datetime_of(0), alt=metres(6), odo=metres(26)),
c=None
) is None

0 comments on commit 0bc244d

Please sign in to comment.