Skip to content

Commit

Permalink
move chart tests to own place
Browse files Browse the repository at this point in the history
  • Loading branch information
time4tea committed Jun 11, 2022
1 parent a11acee commit bd32739
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 74 deletions.
14 changes: 10 additions & 4 deletions gopro_overlay/widgets_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def __init__(self, at, value, font=None, filled=False):
else:
self.font = None

self.fill = (91, 113, 146)
self.line = (255, 255, 255)
self.text = (255, 255, 255)

self.view = None
self.image = None

Expand Down Expand Up @@ -48,15 +52,17 @@ def y_pos(val):
for x, y in filtered:
# (0,0) is top left
points = ((x, size[1] - 1), (x, y_pos(y)))
draw.line(points, width=1, fill=(91, 113, 146))

draw.line(points, width=1, fill=self.fill)

points = [(x, y_pos(y)) for x, y in filtered]
draw.line(points, width=2, fill=(255, 255, 255))

draw.line(points, width=2, fill=self.line)

if self.font:
draw.text((10, 4), f"{max_val:.0f}", font=self.font, fill=(255, 255, 255), stroke_width=2,
draw.text((10, 4), f"{max_val:.0f}", font=self.font, fill=self.text, stroke_width=2,
stroke_fill=(0, 0, 0))
draw.text((10, 40), f"{min_val:.0f}", font=self.font, fill=(255, 255, 255), stroke_width=2,
draw.text((10, 40), f"{min_val:.0f}", font=self.font, fill=self.text, stroke_width=2,
stroke_fill=(0, 0, 0))

marker_val = data[int(size[0] / 2)]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 0 additions & 70 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import itertools
import random
from datetime import timedelta

from PIL import ImageFont

from gopro_overlay import fake
from gopro_overlay.dimensions import Dimension
from gopro_overlay.framemeta import View, Window
from gopro_overlay.layout import BigMetric, gps_info
from gopro_overlay.layout_components import text, metric
from gopro_overlay.point import Coordinate
from gopro_overlay.timeunits import timeunits
from gopro_overlay.timing import PoorTimer
from gopro_overlay.units import units
from gopro_overlay.widgets import simple_icon, Text, Scene, CachingText, Composite, Translate, Frame
from gopro_overlay.widgets_chart import SimpleChart
from gopro_overlay.widgets_info import ComparativeEnergy
from tests.approval import approve_image
from tests.testenvironment import is_make
Expand Down Expand Up @@ -85,72 +81,6 @@ def test_render_gps_info():
)


@approve_image
def test_render_simple_chart():
# Avg: 0.00018, Rate: 5,491.91
view = View(data=list(itertools.chain(
itertools.repeat(0, 128),
itertools.repeat(1, 128)
)), version=1)
return time_rendering("Simple Chart", [
SimpleChart(Coordinate(50, 50), lambda: view, filled=True, font=font)
])


@approve_image
def test_render_chart():
# Avg: 0.00019, Rate: 5,325.79
window = Window(
ts,
duration=timeunits(minutes=2),
samples=256,
key=lambda e: e.alt,
fmt=lambda v: v.magnitude
)

view = window.view(ts.min)

return time_rendering(name="Simple Chart with view", widgets=[
SimpleChart(Coordinate(50, 50), lambda: view, filled=True, font=font)
])


def test_render_chart_with_no_data():
window = Window(
ts,
duration=timeunits(minutes=2),
samples=256,
key=lambda e: e.bob, fmt=lambda v: v.magnitude
)

view = window.view(ts.min)

return time_rendering(name="Simple Chart with no valid data", widgets=[
SimpleChart(Coordinate(50, 50), lambda: view, filled=True, font=font)
])


# start = 0.04 / 24.52
def test_render_moving_chart():
window = Window(
ts,
duration=timeunits(minutes=2),
samples=256,
key=lambda e: e.alt,
fmt=lambda v: v.magnitude,
missing=0
)

stepper = iter(ts.stepper(timeunits(seconds=1)).steps())

def get_view():
return window.view(next(stepper))

return time_rendering(name="Moving Chart", repeat=50, widgets=[
SimpleChart(Coordinate(50, 50), get_view, filled=True, font=font)
])


@approve_image
def test_render_big_metric():
# Avg: 0.00026, Rate: 3,871.63
Expand Down
90 changes: 90 additions & 0 deletions tests/test_widgets_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import itertools
import random
from datetime import timedelta

from PIL import ImageFont

from gopro_overlay import fake
from gopro_overlay.framemeta import View, Window
from gopro_overlay.point import Coordinate
from gopro_overlay.timeunits import timeunits
from gopro_overlay.widgets_chart import SimpleChart
from tests.approval import approve_image
from tests.test_widgets import time_rendering

font = ImageFont.truetype(font='Roboto-Medium.ttf', size=18)
title_font = font.font_variant(size=16)

# Need reproducible results for approval tests
rng = random.Random()
rng.seed(12345)

ts = fake.fake_framemeta(timedelta(minutes=10), step=timedelta(seconds=1), rng=rng)


@approve_image
def test_render_simple_chart():
# Avg: 0.00018, Rate: 5,491.91
view = View(data=list(itertools.chain(
itertools.repeat(0, 128),
itertools.repeat(1, 128)
)), version=1)
return time_rendering("Simple Chart", [
SimpleChart(Coordinate(50, 50), lambda: view, filled=True, font=font)
])


@approve_image
def test_render_chart():
# Avg: 0.00019, Rate: 5,325.79
window = Window(
ts,
duration=timeunits(minutes=2),
samples=256,
key=lambda e: e.alt,
fmt=lambda v: v.magnitude
)

view = window.view(ts.min)

return time_rendering(name="Simple Chart with view", widgets=[
SimpleChart(Coordinate(50, 50), lambda: view, filled=True, font=font)
])


@approve_image
def test_render_chart_with_no_data():
window = Window(
ts,
duration=timeunits(minutes=2),
samples=256,
key=lambda e: e.bob, fmt=lambda v: v.magnitude
)

view = window.view(ts.min)

return time_rendering(name="Simple Chart with no valid data", widgets=[
SimpleChart(Coordinate(50, 50), lambda: view, filled=True, font=font)
])


# start = 0.04 / 24.52
@approve_image
def test_render_moving_chart():
window = Window(
ts,
duration=timeunits(minutes=2),
samples=256,
key=lambda e: e.alt,
fmt=lambda v: v.magnitude,
missing=0
)

stepper = iter(ts.stepper(timeunits(seconds=1)).steps())

def get_view():
return window.view(next(stepper))

return time_rendering(name="Moving Chart", repeat=50, widgets=[
SimpleChart(Coordinate(50, 50), get_view, filled=True, font=font)
])

0 comments on commit bd32739

Please sign in to comment.